P4C
The P4 Compiler
Loading...
Searching...
No Matches
timer.h
1#ifndef LIB_TIMER_H_
2#define LIB_TIMER_H_
3
4#include <cstddef>
5#include <cstdint>
6#include <functional>
7#include <memory>
8#include <string>
9#include <vector>
10
11namespace P4::Util {
12
26void withTimer(const char *timerName, const std::function<void()> &fn);
27
28struct TimerEntry {
30 std::string timerName;
36 uint64_t invocations;
37};
38
40std::vector<TimerEntry> getTimers();
41
42// Internal implementation.
43struct ScopedTimerCtx;
44
48 public:
49 explicit ScopedTimer(const char *name);
50 ScopedTimer(const ScopedTimer &) = delete;
52
53 private:
54 std::unique_ptr<ScopedTimerCtx> ctx;
55};
56
57} // namespace P4::Util
58
59#endif /* LIB_TIMER_H_ */
Definition timer.h:47
Definition timer.cpp:84
Definition timer.h:28
size_t milliseconds
Total duration in milliseconds.
Definition timer.h:32
float relativeToParent
Portion of this timer's name relative to the parent timer.
Definition timer.h:34
std::string timerName
Counter name. If a timer "Y" was invoked inside timer "X", its timer name is "X.Y".
Definition timer.h:30
uint64_t invocations
Number of invocations.
Definition timer.h:36