11 #include <string_view>
12 #include <unordered_set>
16 #include "hebench/modules/args_parser/include/args_parser.h"
17 #include "hebench/modules/general/include/hebench_utilities.h"
28 using namespace std::literals;
42 static void showVersion(std::ostream &os);
43 static std::string getTimeUnitName(
char time_unit,
const std::string &default_name =
"(default)");
46 static const std::unordered_set<std::string> m_allowed_time_units;
49 const std::unordered_set<std::string> ReportCompilerConfig::m_allowed_time_units({
"s",
"ms",
"us",
"ns" });
57 retval =
"milliseconds";
60 retval =
"microseconds";
63 retval =
"nanoseconds";
66 retval = default_name;
79 std::vector<std::filesystem::path> retval;
85 fnum.open(filename, std::ios_base::in);
87 throw std::ios_base::failure(
"Could not open file \"" + filename +
"\"");
89 std::filesystem::path root_path = std::filesystem::canonical(filename).parent_path();
93 std::size_t line_num = 0;
94 while (!b_done && std::getline(fnum, s_line))
97 hebench::Utilities::trim(s_line);
100 std::filesystem::path next_filename = s_line;
101 if (next_filename.is_relative())
103 next_filename = root_path / next_filename;
105 if (std::filesystem::is_regular_file(next_filename))
107 retval.emplace_back(next_filename.string());
115 std::stringstream ss;
116 ss << filename <<
":" << line_num <<
": file specified in line not found: " << next_filename;
117 throw std::invalid_argument(ss.str());
128 retval.emplace_back(filename);
138 static const std::string ReportSuffix =
"report";
142 std::stringstream ss_err;
148 throw std::runtime_error(
"Invalid null compiler configuration values.");
160 std::cout <<
"Extracting input file names..." << std::endl
164 std::size_t max_w_params = 0;
165 std::stringstream ss_overview_header;
166 std::stringstream ss_overview;
167 std::filesystem::path overview_filename = config.
input_file;
168 overview_filename.replace_filename(overview_filename.stem().string() +
"_overview.csv");
173 std::cout <<
"Input files:" << std::endl;
174 for (std::size_t i = 0; i < csv_filenames.size(); ++i)
175 std::cout <<
" " << i <<
", " << csv_filenames[i] << std::endl;
176 std::cout << std::endl
177 <<
"Overview file (output):" << std::endl
178 <<
" " << overview_filename << std::endl
182 ss_overview_header <<
",,,,,,,,,,,,,,Wall Time,,,,,,,,,,,,,CPU Time" << std::endl
183 <<
"Workload,End State,Filename,Category,Data type,Cipher text,Scheme,Security,Extra,"
184 <<
"ID,Event,Total Wall Time,Samples per sec,Samples per sec trimmed,"
186 <<
"Average,Standard Deviation,Time Unit,Time Factor,Min,Max,Median,Trimmed Average,Trimmed Standard Deviation,1-th percentile,10-th percentile,90-th percentile,99-th percentile,"
188 <<
"Average,Standard Deviation,Time Unit,Time Factor,Min,Max,Median,Trimmed Average,Trimmed Standard Deviation,1-th percentile,10-th percentile,90-th percentile,99-th percentile,Input Samples";
190 for (std::size_t csv_file_i = 0; csv_file_i < csv_filenames.size(); ++csv_file_i)
194 std::cout <<
"=====================" << std::endl
195 <<
" Progress: " << csv_file_i <<
"/" << csv_filenames.size() << std::endl
196 <<
" " << hebench::Utilities::convertDoubleToStr(csv_file_i * 100.0 / csv_filenames.size(), 2) <<
"%" << std::endl
197 <<
"=====================" << std::endl
200 std::cout <<
"Report file:" << std::endl
203 std::cerr << csv_filenames[csv_file_i] << std::endl;
207 std::cout <<
"Loading report..." << std::endl;
210 std::shared_ptr<TimingReport> p_report;
226 std::cout <<
"Parsing report header..." << std::endl;
232 std::cerr <<
"WARNING: The loaded report belongs to a failed benchmark." << std::endl;
240 if (overview_header.
w_params.size() > max_w_params)
242 for (std::size_t i = max_w_params; i < overview_header.
w_params.size(); ++i)
243 ss_overview_header <<
",wp" << i;
244 max_w_params = overview_header.
w_params.size();
250 std::filesystem::path stem_filename = csv_filenames[csv_file_i];
251 std::filesystem::path summary_filename;
252 std::filesystem::path stats_filename;
255 std::string s_tmp = stem_filename.stem();
256 if (s_tmp.length() >= ReportSuffix.length() && s_tmp.substr(s_tmp.length() - ReportSuffix.length()) == ReportSuffix)
257 stem_filename.replace_filename(s_tmp.substr(0, s_tmp.length() - ReportSuffix.length()));
258 summary_filename = stem_filename;
259 summary_filename +=
"summary.csv";
260 stats_filename = stem_filename;
261 stats_filename +=
"stats.csv";
265 std::cout <<
"Computing statistics..." << std::endl;
272 std::cout <<
"Writing summary to:" << std::endl
273 <<
" " << summary_filename << std::endl;
277 hebench::Utilities::writeToFile(
279 [&report_stats, tmp_time_unit](std::ostream &os) ->
void {
286 std::cout <<
"Writing statistics to:" << std::endl
287 <<
" " << stats_filename << std::endl;
291 hebench::Utilities::writeToFile(
293 [&report_stats, tmp_time_unit](std::ostream &os) ->
void {
300 std::cout <<
"Adding to report overview..." << std::endl;
305 if (overview_header.
w_params.empty())
308 std::cerr <<
"WARNING: No workload parameters found while parsing." << std::endl;
310 for (std::size_t i = 0; i < overview_header.
w_params.size(); ++i)
312 if (overview_header.
w_params[i].find_first_of(
',') == std::string::npos)
313 ss_overview <<
"," << overview_header.
w_params[i];
315 ss_overview <<
",\"" << overview_header.
w_params[i] <<
"\"";
321 std::cerr <<
"WARNING: Failed to load report from file." << std::endl;
322 ss_overview <<
"Failed," << csv_filenames[csv_file_i] <<
",Load";
326 std::cout << std::endl;
328 ss_overview << std::endl;
331 ss_overview_header << std::endl
332 << ss_overview.str();
333 ss_overview = std::stringstream();
334 std::string s_overview = ss_overview_header.str();
335 ss_overview_header = std::stringstream();
336 hebench::Utilities::writeToFile(overview_filename, s_overview.c_str(), s_overview.size() *
sizeof(
char),
false);
340 std::cout <<
"=====================" << std::endl
341 <<
" Progress: " << csv_filenames.size() <<
"/" << csv_filenames.size() << std::endl
342 <<
" 100%" << std::endl
343 <<
"=====================" << std::endl
350 std::cout <<
"Overview:" << std::endl;
351 std::cout << std::endl
352 << s_overview << std::endl;
355 catch (std::exception &ex)
362 ss_err <<
"Unexpected error occurred.";
void generateCSV(std::ostream &os, char ch_prefix)
Generates complete CSV stats for this report.
void generateSummaryCSV(std::ostream &os, char ch_prefix)
Generates summary CSV for this report.
const ReportEventTypeStats & getMainEventTypeStats() const
static TimingReport loadReportFromCSVFile(const std::string &filename)
uint64_t getEventCount() const
std::string getHeader() const
std::vector< std::filesystem::path > extractInputFiles(const std::string &filename)
char time_unit_overview
Time unit for report overview. If 0, the fallback time_unit will be used.
int32_t b_silent
If non-zero, the run details will be omited. Any warning, error, or important messages are directed t...
const char * input_file
C-string containing the input file name.
char time_unit_stats
Time unit for report statistics. If 0, the fallback time_unit will be used.
int32_t compile(const ReportCompilerConfigC *p_config, char *s_error, size_t s_error_size)
Runs the compiler using the specified configuration.
char time_unit_summary
Time unit for report summaries. If 0, the fallback time_unit will be used.
int32_t b_show_overview
If non-zero, the compiled overview will be output to stdout.
char time_unit
Fallback time unit when no time unit is specified for a specific output.
Configuration for a compiler run.
std::uint64_t copyString(char *dst, std::uint64_t size, const std::string &src)
Copies a C++ string object into a C-style string.
static std::string getTimeUnitName(char time_unit, const std::string &default_name="(default)")
void showConfig(std::ostream &os) const
std::filesystem::path input_file
static void showVersion(std::ostream &os)