17 EasyProfiler(
const std::string& prof_label,
bool enabled =
true,
bool debug =
false, std::ostream& ost = std::cout)
20 prof_label(prof_label),
26 labels.push_back(
"begin");
27 times.push_back(std::chrono::high_resolution_clock::now());
30 ost <<
"--- " << prof_label <<
" (debug) ---" << std::endl;
39 labels.push_back(
"end");
40 times.push_back(std::chrono::high_resolution_clock::now());
42 ost <<
"--- " << prof_label <<
" ---" <<
'\n';
45 for (
const auto& label : labels) {
46 longest = std::max<int>(label.size(), longest);
49 for (
int i = 1; i < labels.size(); i++) {
50 std::vector<char> pad(longest - labels[i - 1].size(),
' ');
51 std::string label = labels[i - 1] + std::string(pad.begin(), pad.end());
53 ost << label <<
":" << std::chrono::duration_cast<std::chrono::nanoseconds>(times[i] - times[i - 1]).count() / 1e6 <<
"[msec]" <<
'\n';
56 ost <<
"total:" << std::chrono::duration_cast<std::chrono::nanoseconds>(times.back() - times.front()).count() / 1e6 <<
"[msec]" <<
'\n';
60 void push(
const std::string& label) {
65 labels.push_back(label);
66 times.push_back(std::chrono::high_resolution_clock::now());
69 ost <<
">> " << label <<
" (" << std::chrono::duration_cast<std::chrono::nanoseconds>(times.back() - times.front()).count() / 1e6 <<
"[msec])"
77 const std::string prof_label;
79 std::vector<std::string> labels;
80 std::vector<std::chrono::high_resolution_clock::time_point> times;