WARPXM v1.10.0
Loading...
Searching...
No Matches
wmtimer.h
Go to the documentation of this file.
1#ifndef WMTIMER_H
2#define WMTIMER_H
3
4#include "lib/wxlogstream.h"
5#include <chrono>
6#include <map>
7#include <ratio>
8#include <string>
9#include <vector>
10
11namespace wxm
12{
13namespace timer
14{
15
22{
23public:
25 void start(const std::string& scope);
26
28 void stop();
29
34 void stop(const std::string& scope);
35
36 void add_scope(const std::string& scope)
37 {
38 scopes.push_back(scope);
39 }
40
41 void add_started_at(std::chrono::time_point<std::chrono::steady_clock,
42 std::chrono::nanoseconds> started_at)
43 {
44 started_ats.push_back(started_at);
45 }
46
47 void pop_scope()
48 {
49 scopes.pop_back();
50 }
51
53 {
54 started_ats.pop_back();
55 }
56
57 const std::chrono::time_point<std::chrono::steady_clock, std::chrono::nanoseconds>
59 {
60 return started_ats.back();
61 }
62
63 std::map<std::vector<std::string>, long> get_scoped_timings()
64 {
65 return scoped_timings_nanos;
66 }
67
72
73private:
74 // Startup times of the timers
75 std::vector<
76 std::chrono::time_point<std::chrono::steady_clock, std::chrono::nanoseconds>>
77 started_ats;
78
79 // The scopes we want to set the timer for (e.g. ndg/solve, ex_kernal, ...).
80 std::vector<std::string> scopes;
81
82 // The keys of the map are the scopes. The elements of the map are the elapsed times.
83 std::map<std::vector<std::string>, long> scoped_timings_nanos;
84};
85
87
88inline std::string ROOT_TIMING_SCOPE = "ROOT";
89
90} // namespace timer
91} // namespace wxm
92
93#endif
Provides interface to streaming iostreams to logs.
Definition: wxlogstream.h:19
Parameters for the walltime report.
Definition: wmtimer.h:22
void start(const std::string &scope)
Start a nested timing scope.
void pop_scope()
Definition: wmtimer.h:47
void add_started_at(std::chrono::time_point< std::chrono::steady_clock, std::chrono::nanoseconds > started_at)
Definition: wmtimer.h:41
void print_timings(WxLogStream &stream)
Print the timings in a readable table format to the given log stream.
void add_scope(const std::string &scope)
Definition: wmtimer.h:36
void pop_started_at()
Definition: wmtimer.h:52
void stop(const std::string &scope)
Stop the currently running scope, which must be the same as scope.
std::map< std::vector< std::string >, long > get_scoped_timings()
Definition: wmtimer.h:63
const std::chrono::time_point< std::chrono::steady_clock, std::chrono::nanoseconds > current_started_at()
Definition: wmtimer.h:58
void stop()
Stop the currently running scope.
std::string ROOT_TIMING_SCOPE
Definition: wmtimer.h:88
wxm::timer::WmTimer TIMER
Definition: wmtimer.h:86
Base namespace for everything not included in the global namespace.
Definition: field_source.h:8