WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
setup_profiler.hpp
Go to the documentation of this file.
1// Copyright (c) Sleipnir contributors
2
3#pragma once
4
5#include <chrono>
6#include <string>
7#include <string_view>
8
9namespace slp {
10
11/// Records the number of profiler measurements (start/stop pairs) and the
12/// average duration between each start and stop call.
14 public:
15 /// Constructs a SetupProfiler.
16 ///
17 /// @param name Name of measurement to show in diagnostics.
18 explicit SetupProfiler(std::string_view name) : m_name{name} {}
19
20 /// Tell the profiler to start measuring setup time.
21 void start() {
22#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
23 m_setup_start_time = std::chrono::steady_clock::now();
24#endif
25 }
26
27 /// Tell the profiler to stop measuring setup time.
28 void stop() {
29#ifndef SLEIPNIR_DISABLE_DIAGNOSTICS
30 m_setup_stop_time = std::chrono::steady_clock::now();
31 m_setup_duration = m_setup_stop_time - m_setup_start_time;
32#endif
33 }
34
35 /// Returns name of measurement to show in diagnostics.
36 ///
37 /// @return Name of measurement to show in diagnostics.
38 std::string_view name() const { return m_name; }
39
40 /// Returns the setup duration in milliseconds as a double.
41 ///
42 /// @return The setup duration in milliseconds as a double.
43 const std::chrono::duration<double>& duration() const {
44 return m_setup_duration;
45 }
46
47 private:
48 /// Name of measurement to show in diagnostics.
49 std::string m_name;
50
51 std::chrono::steady_clock::time_point m_setup_start_time;
52 std::chrono::steady_clock::time_point m_setup_stop_time;
53 std::chrono::duration<double> m_setup_duration{0.0};
54};
55
56} // namespace slp
const std::chrono::duration< double > & duration() const
Returns the setup duration in milliseconds as a double.
Definition setup_profiler.hpp:43
SetupProfiler(std::string_view name)
Constructs a SetupProfiler.
Definition setup_profiler.hpp:18
std::string_view name() const
Returns name of measurement to show in diagnostics.
Definition setup_profiler.hpp:38
void stop()
Tell the profiler to stop measuring setup time.
Definition setup_profiler.hpp:28
void start()
Tell the profiler to start measuring setup time.
Definition setup_profiler.hpp:21
Definition expression_graph.hpp:11