23#include "shineknightdev/runtime_analyzer.hpp"
31template <ChronoDuration Unit>
37 out <<
"Sample " << ++i <<
": "
38 <<
"| Time: " << duration.count() <<
" " << profile.
unit_symbol <<
" | Sample size: " << size <<
"\n";
42template <ChronoDuration Unit>
45 out <<
"sample_id,time_unit,time_value,sample_size\n";
49 out << ++i <<
"," << profile.
unit_symbol <<
"," << duration.count() <<
"," << size <<
"\n";
53template <ChronoDuration Unit>
62 if (!first) { out <<
",\n"; }
65 <<
" \"sample_id\": " << ++i <<
",\n"
66 <<
" \"time_unit\": \"" << profile.
unit_symbol <<
"\",\n"
67 <<
" \"time_value\": " << duration.count() <<
",\n"
68 <<
" \"sample_size\": " << size <<
"\n"
78template <ChronoDuration Unit>
84template <ChronoDuration Unit>
87 std::ofstream file(filename);
88 if (!file.is_open()) {
throw std::runtime_error(
"Error: Could not open file " + filename.string()); }
90 const auto ext = filename.extension();
95 else {
throw std::runtime_error(
"Error: Unsupported file extension " + ext.string()); }
98template <ChronoDuration Unit>
101 const auto filename = std::filesystem::path(base_filename).replace_extension(
".csv");
105template <ChronoDuration Unit>
108 std::filesystem::path base_path(base_filename);
110 save_report(runtime_profile, base_path.replace_extension(
".csv"));
111 save_report(runtime_profile, base_path.replace_extension(
".json"));
112 save_report(runtime_profile, base_path.replace_extension(
".txt"));
115template <ChronoDuration Unit,
typename Stream>
116requires std::derived_from<Stream, std::ostream>
122 else {
throw std::invalid_argument(
"Unsupported format: " + format); }
void write_text_report_impl(std::ostream &out, const RuntimeProfile< Unit > &profile)
Definition runtime_reporter.hpp:32
void write_json_report_impl(std::ostream &out, const RuntimeProfile< Unit > &profile)
Definition runtime_reporter.hpp:54
void write_csv_report_impl(std::ostream &out, const RuntimeProfile< Unit > &profile)
Definition runtime_reporter.hpp:43
Definition runtime_analyzer.hpp:28
void generate_report(Stream &stream, const RuntimeProfile< Unit > &runtime_profile, const std::string &format="text")
Definition runtime_reporter.hpp:117
void save_report(const RuntimeProfile< Unit > &runtime_profile, const std::filesystem::path &filename)
Definition runtime_reporter.hpp:85
void save_reports(const RuntimeProfile< Unit > &runtime_profile, const std::string &base_filename="runtime_report")
Definition runtime_reporter.hpp:106
void print_report(const RuntimeProfile< Unit > &runtime_profile)
Definition runtime_reporter.hpp:79
Definition runtime_analyzer.hpp:60
std::string unit_symbol
Definition runtime_analyzer.hpp:63
std::vector< Unit > raw_durations
Definition runtime_analyzer.hpp:61
std::vector< size_t > sample_sizes
Definition runtime_analyzer.hpp:62