11#include "shineknightdev/runtime_analyzer.hpp"
19template <ChronoDuration Unit>
25 out <<
"Sample " << ++i <<
": "
26 <<
"| Time: " << duration.count() <<
" " << profile.
unit_symbol <<
" | Sample size: " << size <<
"\n";
30template <ChronoDuration Unit>
33 out <<
"sample_id,time_unit,time_value,sample_size\n";
37 out << ++i <<
"," << profile.
unit_symbol <<
"," << duration.count() <<
"," << size <<
"\n";
41template <ChronoDuration Unit>
50 if (!first) { out <<
",\n"; }
53 <<
" \"sample_id\": " << ++i <<
",\n"
54 <<
" \"time_unit\": \"" << profile.
unit_symbol <<
"\",\n"
55 <<
" \"time_value\": " << duration.count() <<
",\n"
56 <<
" \"sample_size\": " << size <<
"\n"
66template <ChronoDuration Unit>
72template <ChronoDuration Unit>
75 std::ofstream file(filename);
76 if (!file.is_open()) {
throw std::runtime_error(
"Error: Could not open file " + filename.string()); }
78 const auto ext = filename.extension();
83 else {
throw std::runtime_error(
"Error: Unsupported file extension " + ext.string()); }
86template <ChronoDuration Unit>
89 const auto filename = std::filesystem::path(base_filename).replace_extension(
".csv");
93template <ChronoDuration Unit>
96 std::filesystem::path base_path(base_filename);
98 save_report(runtime_profile, base_path.replace_extension(
".csv"));
99 save_report(runtime_profile, base_path.replace_extension(
".json"));
100 save_report(runtime_profile, base_path.replace_extension(
".txt"));
103template <ChronoDuration Unit,
typename Stream>
104requires std::derived_from<Stream, std::ostream>
110 else {
throw std::invalid_argument(
"Unsupported format: " + format); }
void write_text_report_impl(std::ostream &out, const RuntimeProfile< Unit > &profile)
Definition runtime_reporter.hpp:20
void write_json_report_impl(std::ostream &out, const RuntimeProfile< Unit > &profile)
Definition runtime_reporter.hpp:42
void write_csv_report_impl(std::ostream &out, const RuntimeProfile< Unit > &profile)
Definition runtime_reporter.hpp:31
Definition runtime_analyzer.hpp:16
void generate_report(Stream &stream, const RuntimeProfile< Unit > &runtime_profile, const std::string &format="text")
Definition runtime_reporter.hpp:105
void save_report(const RuntimeProfile< Unit > &runtime_profile, const std::filesystem::path &filename)
Definition runtime_reporter.hpp:73
void save_reports(const RuntimeProfile< Unit > &runtime_profile, const std::string &base_filename="runtime_report")
Definition runtime_reporter.hpp:94
void print_report(const RuntimeProfile< Unit > &runtime_profile)
Definition runtime_reporter.hpp:67
Definition runtime_analyzer.hpp:48
std::string unit_symbol
Definition runtime_analyzer.hpp:51
std::vector< Unit > raw_durations
Definition runtime_analyzer.hpp:49
std::vector< size_t > sample_sizes
Definition runtime_analyzer.hpp:50