Skip to content
Snippets Groups Projects
Commit a3daf604 authored by jgatt's avatar jgatt
Browse files

small reformat of log user file + comment

parent 0cdfef48
No related branches found
No related tags found
1 merge request!12Merge Request multibehavior
#include "users/log_user_stat.hpp"
#include "../pempek_assert.hpp"
BehaviorStat::BehaviorStat(shared_ptr<Job> job,
std::string behavior_name,double time_delayed){
BehaviorStat::BehaviorStat(
shared_ptr<Job> job, std::string behavior_name, double time_delayed){
this->job = job;
this->behavior_name = behavior_name;
this->time_delayed = time_delayed;
}
std::vector<std::string> BehaviorStat::split_id(){
std::string job_id = job->id;
std::vector<std::string> splitting;
splitting.push_back("");
for( std::string::size_type i =0 ; i < job_id.length();i++){
if(job_id[i]=='!'){
for (std::string::size_type i = 0; i < job_id.length(); i++){
if (job_id[i] == '!'){
splitting.push_back("");
}
else
{
else{
splitting.back() += job_id[i];
}
}
return splitting;
}
boost::basic_format<char> BehaviorStat::format()
{
boost::basic_format<char> BehaviorStat::format(){
std::vector<std::string> splitting = split_id();
PPK_ASSERT_ERROR(splitting.size()>=2,
PPK_ASSERT_ERROR(splitting.size() >= 2,
"Error logging the job behavior the job_id should be of the format"
" user_id!job_id");
return boost::format("%1%,%2%,%3%,%4%,%5%\n") % splitting[0] %
splitting[1] % job->submission_time % behavior_name % time_delayed;
return boost::format("%1%,%2%,%3%,%4%,%5%\n") % splitting[0] % splitting[1]
% job->submission_time % behavior_name % time_delayed;
}
LoggerUserStat::LoggerUserStat(std::string log_folder)
{
LoggerUserStat::LoggerUserStat(std::string log_folder){
this->log_folder = log_folder;
put_header = true;
write_threshold=4096;
begin_to_write=0;
write_threshold = 4096;
}
void LoggerUserStat::add_stat(shared_ptr<Job> job,std::string behavior_name, double time_delayed){
BehaviorStat to_add = BehaviorStat(job,behavior_name,time_delayed);
void LoggerUserStat::add_stat(
shared_ptr<Job> job, std::string behavior_name, double time_delayed){
BehaviorStat to_add = BehaviorStat(job, behavior_name, time_delayed);
behaviors.push_back(to_add);
if(behaviors.size()-begin_to_write >= write_threshold){
if (behaviors.size() >= write_threshold){
log_stat();
}
}
void LoggerUserStat::log_stat(){
/**
* This functions write log in the csv format the behaviors recorded in
* the vector behaviors
*/
std::ofstream file;
if (put_header){
/* first time we log we add the header and erase previous log */
file.open(log_folder + "/user_stats_behaviors.csv");
file << "user,job_id,submission_time, behavior_name,time_delayed\n";
put_header=false;
put_header = false;
}
else{
file.open(log_folder+"/user_stats_behaviors.csv",
/* after the first time we log we append the data to the file */
file.open(log_folder + "/user_stats_behaviors.csv",
std::ofstream::out | std::ofstream::app);
}
for (std::vector<BehaviorStat>::size_type i =0 ;
i < behaviors.size(); i++){
/* We write the content in the vector to the disk and then free the vector */
for (std::vector<BehaviorStat>::size_type i = 0; i < behaviors.size(); i++){
BehaviorStat read_behavior = behaviors[i];
file << read_behavior.format();
}
......
#pragma once
#include "json_workload.hpp"
#include <boost/format.hpp>
#include <fstream>
#include "json_workload.hpp"
/**
* library dedicated to logging user_behavior
*/
using namespace std;
struct BehaviorStat {
shared_ptr<Job> job;
shared_ptr <Job> job;
std::string behavior_name;
double time_delayed;
double submission_time;
BehaviorStat( shared_ptr<Job> job,
std::string behavior_name,double time_delayed);
std::vector<std::string> split_id();
BehaviorStat(shared_ptr <Job> job,
std::string behavior_name, double time_delayed);
std::vector <std::string> split_id();
boost::basic_format<char> format();
};
class LoggerUserStat {
public :
public:
LoggerUserStat(std::string log_folder);
void add_stat(shared_ptr<Job> job,std::string behavior_name, double time_delayed);
void add_stat(shared_ptr <Job> job,
std::string behavior_name, double time_delayed);
void log_stat();
protected :
protected:
bool put_header;
std::vector<BehaviorStat>::size_type begin_to_write;
std::vector<BehaviorStat>::size_type write_threshold;
std::string log_folder;
std::vector<BehaviorStat> behaviors;
std::vector <BehaviorStat> behaviors;
};
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment