8#ifndef PERFORMANCE_UTIL_HPP_
9#define PERFORMANCE_UTIL_HPP_
11#include <boost/lexical_cast.hpp>
12#include <boost/filesystem.hpp>
13#include <boost/property_tree/ptree.hpp>
14#include <boost/property_tree/xml_parser.hpp>
17static void addUpdateTime(
GoogleChart & cg,
int np,
const std::string & base,
const std::string & filename)
20 struct tm * now = localtime( & t );
22 std::stringstream str;
26 std::system(
"git rev-parse HEAD >test.txt");
27 std::ifstream(
"test.txt") >> commit;
29 std::string prev_commit;
31 std::system(std::string(
"cat commit_f_" + base +
" > test.txt").c_str());
32 std::ifstream(
"test.txt") >> prev_commit;
34 str <<
"<h3>Updated: " << now->tm_mday <<
"/" << now->tm_mon + 1 <<
"/" << now->tm_year+1900 <<
" " << now->tm_hour <<
":" << now->tm_min <<
":"
35 << now->tm_sec <<
" commit: " << commit <<
" run with: " << np <<
" processes<br>previous: <a href=\"" << filename <<
"_" << prev_commit <<
".html\">here</a>" <<
"</h3>" << std::endl;
40static void createCommitFile(
const std::string & tmp)
43 struct tm * now = localtime( & t );
45 std::stringstream str;
48 commit = exec(
"git rev-parse HEAD");
49 std::cout << tmp <<
" " << commit << std::endl;
51 std::ofstream f(
"commit_f_" + tmp);
52 f << commit << std::endl;
57static inline void warning_set(
int & warning_level,
double mean,
double mean_ref,
double sigma)
59 int warning_level_candidate;
61 if (mean - mean_ref < -2.0*sigma )
62 warning_level_candidate = -1;
63 else if (mean - mean_ref < 2.0*sigma)
64 warning_level_candidate = 0;
65 else if (mean - mean_ref < 3.0*sigma)
66 warning_level_candidate = 1;
68 warning_level_candidate = 2;
70 if (warning_level_candidate > warning_level)
71 warning_level = warning_level_candidate;
74static inline void addchartarea(std::string & chart_area,
int lvl)
80 chart_area = std::string(
",chartArea: {\
93 chart_area = std::string(
",chartArea: {\
102 chart_area = std::string(
",chartArea: {\
117static bool isFloat(
const std::string &someString)
119 using boost::lexical_cast;
120 using boost::bad_lexical_cast;
123 {boost::lexical_cast<float>(someString);}
124 catch (bad_lexical_cast &)
130static void StandardXMLPerformanceGraph(std::string file_xml,
131 std::string file_xml_ref,
133 const double deviationMultiplier = 3.0)
136 boost::property_tree::ptree tree_measure;
139 boost::property_tree::read_xml(file_xml, tree_measure);
142 boost::property_tree::ptree tree_reference;
145 if (boost::filesystem::exists(file_xml_ref) ==
false )
147 boost::filesystem::copy_file(file_xml,file_xml_ref);
151 boost::property_tree::read_xml(file_xml_ref, tree_reference);
157 boost::property_tree::ptree childs = tree_measure.get_child(
"graphs");
159 for (
auto & c: childs)
161 std::string type = c.second.template get<std::string>(
"type",
"");
168 if (c.second.template get<std::string>(
"y.data(" + std::to_string(number) +
").title",
"") ==
"")
170 yn.add(c.second.template get<std::string>(
"y.data(" + std::to_string(number) +
").title",
171 "line" + std::to_string(number)));
177 bool is_log_x = c.second.template get<bool>(
"options.log_x",
false);
178 bool is_log_y = c.second.template get<bool>(
"options.log_y",
false);
181 std::string title = c.second.template get<std::string>(
"title",
"");
182 std::string x_title = c.second.template get<std::string>(
"x.title",
"");
183 std::string y_title = c.second.template get<std::string>(
"y.title",
"");
187 std::string preHTML = c.second.template get<std::string>(
"preHTML",
"");
188 std::string postHTML = c.second.template get<std::string>(
"postHTML",
"");
198 int warning_level = -1;
199 bool is_literal_x =
false;
201 for (
size_t i = 0 ; i < number ; i++)
211 std::string xv = c.second.template get<std::string>(
"x.data(" + std::to_string(i) +
").source",
"");
212 std::string yv = c.second.template get<std::string>(
"y.data(" + std::to_string(i) +
").source",
"");
219 std::string xv_ = xv;
220 std::string yv_ = yv;
222 int xpos = xv_.find(
"#");
223 int ypos = yv_.find(
"#");
225 xv_.replace(xpos,1,std::to_string(j));
226 yv_.replace(ypos,1,std::to_string(j));
228 if (tree_measure.template get<std::string>(xv_,
"") ==
"")
232 std::cout <<
"WARNING: Not found " << xv_ <<
" in file: " << file_xml << std::endl;
237 std::string tmp = tree_measure.template get<std::string>(xv_,
"");
240 std::string x_val_str;
241 if (isFloat(tmp) ==
true)
242 {x_val = tree_measure.template get<double>(xv_,0.0);}
249 double y_val = tree_measure.template get<double>(yv_,0.0);
251 double x_val_ref = tree_reference.template get<double>(xv_,0.0);
252 double y_val_ref = tree_reference.template get<double>(yv_,0.0);
254 if (y_val_ref == 0.0)
256 std::cout <<
"WARNING: " << yv_ <<
" does not exist on the reference file: " << file_xml_ref << std::endl;
259 ypos = yv_.find(
".mean");
260 std::string yv_dev = yv_.replace(ypos,5,
".dev");
261 double y_val_dev_ref = tree_reference.template get<double>(yv_,0.0);
263 if (y_val_dev_ref == 0.0)
265 std::cout <<
"WARNING: " << yv_ <<
" does not exist on the reference file: " << file_xml_ref << std::endl;
271 x_ref.last().add(x_val_ref);
272 y_ref_dw.last().add(y_val_ref - deviationMultiplier * y_val_dev_ref);
273 y_ref_up.last().add(y_val_ref + deviationMultiplier * y_val_dev_ref);
275 warning_set(warning_level,y_val,y_val_ref,y_val_dev_ref);
285 std::string chart_area;
286 addchartarea(chart_area,warning_level);
287 opt.
curveType = c.second.template get<std::string>(
"interpolation",
"function");
290 if (is_log_x ==
true)
292 opt.
more = GC_X_LOG +
"," + GC_ZOOM + chart_area;
296 opt.
more = GC_ZOOM + chart_area;
299 if (is_log_y ==
true)
301 opt.
more = GC_Y_LOG +
"," + GC_ZOOM + chart_area;
305 opt.
more = GC_ZOOM + chart_area;
312 if (is_literal_x ==
false)
316 cg.
AddLines(yn,opt,x.get(0),y.get(0),
317 x_ref.get(0),y_ref_dw.get(0),
318 x_ref.get(0),y_ref_up.get(0));
322 cg.
AddLines(yn,opt,x.get(0),y.get(0),
323 x_ref.get(0),y_ref_dw.get(0),x_ref.get(0),y_ref_up.get(0),
325 x_ref.get(1),y_ref_dw.get(1),x_ref.get(1),y_ref_up.get(1));
329 cg.
AddLines(yn,opt,x.get(0),y.get(0),
330 x_ref.get(0),y_ref_dw.get(0),x_ref.get(0),y_ref_up.get(0),
332 x_ref.get(1),y_ref_dw.get(1),x_ref.get(1),y_ref_up.get(1),
334 x_ref.get(2),y_ref_dw.get(2),x_ref.get(2),y_ref_up.get(2));
338 cg.
AddLines(yn,opt,x.get(0),y.get(0),
339 x_ref.get(0),y_ref_dw.get(0),x_ref.get(0),y_ref_up.get(0),
341 x_ref.get(1),y_ref_dw.get(1),x_ref.get(1),y_ref_up.get(1),
343 x_ref.get(2),y_ref_dw.get(2),x_ref.get(2),y_ref_up.get(2),
345 x_ref.get(3),y_ref_dw.get(3),x_ref.get(3),y_ref_up.get(3));
349 cg.
AddLines(yn,opt,x.get(0),y.get(0),
350 x_ref.get(0),y_ref_dw.get(0),x_ref.get(0),y_ref_up.get(0),
352 x_ref.get(1),y_ref_dw.get(1),x_ref.get(1),y_ref_up.get(1),
354 x_ref.get(2),y_ref_dw.get(2),x_ref.get(2),y_ref_up.get(2),
356 x_ref.get(3),y_ref_dw.get(3),x_ref.get(3),y_ref_up.get(3),
358 x_ref.get(4),y_ref_dw.get(4),x_ref.get(4),y_ref_up.get(4));
362 cg.
AddLines(yn,opt,x.get(0),y.get(0),
363 x_ref.get(0),y_ref_dw.get(0),x_ref.get(0),y_ref_up.get(0),
365 x_ref.get(1),y_ref_dw.get(1),x_ref.get(1),y_ref_up.get(1),
367 x_ref.get(2),y_ref_dw.get(2),x_ref.get(2),y_ref_up.get(2),
369 x_ref.get(3),y_ref_dw.get(3),x_ref.get(3),y_ref_up.get(3),
371 x_ref.get(4),y_ref_dw.get(4),x_ref.get(4),y_ref_up.get(4),
373 x_ref.get(5),y_ref_dw.get(5),x_ref.get(5),y_ref_up.get(5));
380 y_tmp.resize(x.get(0).size());
382 for (
size_t i = 0 ; i < x.size() ; i++)
384 for (
size_t j = 0 ; j < x.get(i).size() ; j++)
386 y_tmp.get(j).add(y.get(i).get(j));
387 y_tmp.get(j).add(y_ref_dw.get(i).get(j));
388 y_tmp.get(j).add(y_ref_up.get(i).get(j));
Small class to produce graph with Google chart in HTML.
void AddLines(const openfpm::vector< std::string > &yn, const GCoptions &opt, X ... xy)
Add lines graph.
void AddLinesGraph(openfpm::vector< X > &x, openfpm::vector< Y > &y, const GCoptions &opt)
Add a simple lines graph.
void addHTML(const std::string &html)
Add HTML text.
Implementation of 1-D std::vector like structure.
std::string xAxis
X axis name.
std::string curveType
curve type
std::string title
Title of the chart.
std::string yAxis
Y axis name.