27 #include <unordered_map>
31 using time_point = std::chrono::time_point<std::chrono::high_resolution_clock>;
56 return event_timer.nested_event_timer;
74 const size_t nest_level,
75 const bool make_nested)
76 : event_label(event_label)
77 ,
start_time(std::chrono::high_resolution_clock::now()) {
79 const std::string nested_event_label{event_label +
" sub-steps"};
81 std::make_shared<CpuTimer>(nested_event_label, nest_level + 1);
90 end_time = std::chrono::high_resolution_clock::now();
98 const bool make_nested) {
109 timers_end_ = std::chrono::high_resolution_clock::now();
120 const std::string header_underline{std::string(
header.size(),
'=')};
121 const std::string nest_spaces{std::string(
nest_level_ * 2,
' ')};
122 std::cout << std::endl
123 << nest_spaces <<
header << std::endl
124 << nest_spaces << header_underline << std::endl;
126 const size_t timings_left_margin{50};
129 const int64_t ms_elapsed = std::chrono::duration_cast<std::chrono::milliseconds>(
130 event_timer.end_time - event_timer.start_time)
132 const int64_t total_ms_elapsed =
133 std::chrono::duration_cast<std::chrono::milliseconds>(event_timer.end_time -
136 const size_t label_width{event_timer.event_label.size()};
137 const size_t margin_calc{
138 label_width < timings_left_margin ? timings_left_margin - label_width : 0};
140 std::cout << nest_spaces << event_timer.event_label <<
": "
141 << std::setw(margin_calc) << std::fixed << std::setprecision(4)
142 << ms_elapsed <<
" ms elapsed, " << total_ms_elapsed <<
" ms total"
145 if (event_timer.nested_event_timer !=
nullptr) {
146 event_timer.nested_event_timer->print_timings();
147 std::cout << std::endl;
150 const int64_t total_ms_elapsed =
153 std::cout << nest_spaces <<
timer_label_ <<
" total elapsed: " << std::fixed
154 << std::setprecision(4) << total_ms_elapsed <<
" ms" << std::endl;
164 #endif // #ifndef __CUDACC__
const std::string timer_label_
std::shared_ptr< CpuTimer > start_nested_event_timer(const std::string &event_label)
EventTimer & start_event_timer_impl(const std::string &event_label, const bool make_nested)
std::shared_ptr< CpuTimer > nested_event_timer
void start_event_timer(const std::string &event_label)
EventTimer(const std::string &event_label, const size_t nest_level, const bool make_nested)
CpuTimer(const std::string &label)
std::vector< EventTimer > event_timers_
CpuTimer(const std::string &label, const int64_t nest_level)
std::chrono::time_point< std::chrono::high_resolution_clock > time_point