P4C
The P4 Compiler
Loading...
Searching...
No Matches
timer.h
1/*
2 * SPDX-FileCopyrightText: 2023 The P4 Language Consortium
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef LIB_TIMER_H_
8#define LIB_TIMER_H_
9
10#include <cstddef>
11#include <cstdint>
12#include <functional>
13#include <memory>
14#include <string>
15#include <vector>
16
17namespace P4::Util {
18
32void withTimer(const char *timerName, const std::function<void()> &fn);
33
34struct TimerEntry {
36 std::string timerName;
42 uint64_t invocations;
43};
44
46std::vector<TimerEntry> getTimers();
47
48// Internal implementation.
49struct ScopedTimerCtx;
50
53class ScopedTimer {
54 public:
55 explicit ScopedTimer(const char *name);
56 ScopedTimer(const ScopedTimer &) = delete;
57 ~ScopedTimer();
58
59 private:
60 std::unique_ptr<ScopedTimerCtx> ctx;
61};
62
63} // namespace P4::Util
64
65#endif /* LIB_TIMER_H_ */
Definition timer.cpp:88
Definition timer.h:34
size_t milliseconds
Total duration in milliseconds.
Definition timer.h:38
float relativeToParent
Portion of this timer's name relative to the parent timer.
Definition timer.h:40
std::string timerName
Counter name. If a timer "Y" was invoked inside timer "X", its timer name is "X.Y".
Definition timer.h:36
uint64_t invocations
Number of invocations.
Definition timer.h:42