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

Merge remote-tracking branch 'origin/multibehavior' into multibehavior

# Conflicts:
#	meson.build
#	src/broker/user_replay.cpp
#	src/broker/user_replay.hpp
#	src/users/broker.cpp
#	src/users/broker.hpp
#	src/users/log_user_stat.cpp
#	src/users/log_user_stat.hpp
#	test/schedconf/dm_user_multi_behavior_yellow.json
#	test/test_dm_users.py
parents 45805942 f042ea21
No related branches found
No related tags found
1 merge request!12Merge Request multibehavior
Pipeline #5424 passed with warnings
#include "users/log_user_stat.hpp"
#include "../pempek_assert.hpp"
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]=='!'){
splitting.push_back("");
}
else
{
splitting.back() += job_id[i];
}
}
return splitting;
}
boost::basic_format<char> BehaviorStat::format()
{
std::vector<std::string> splitting = split_id();
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;
}
LoggerUserStat::LoggerUserStat(std::string log_folder)
{
this->log_folder = log_folder;
put_header = true;
write_threshold=4096;
begin_to_write=0;
}
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){
log_stat();
}
}
void LoggerUserStat::log_stat(){
std::ofstream file;
if (put_header){
file.open(log_folder + "/user_stats_behaviors.csv");
file << "user,job_id,submission_time, behavior_name,time_delayed\n";
put_header=false;
}
else{
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++){
BehaviorStat read_behavior = behaviors[i];
file << read_behavior.format();
}
behaviors.clear();
file.close();
}
\ No newline at end of file
#pragma once
#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;
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();
boost::basic_format<char> format();
};
class LoggerUserStat {
public :
LoggerUserStat(std::string log_folder);
void add_stat(shared_ptr<Job> job,std::string behavior_name, double time_delayed);
void log_stat();
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;
};
\ 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