WPILibC++ 2027.0.0-alpha-4
Loading...
Searching...
No Matches
Tracer.hpp
Go to the documentation of this file.
1// Copyright (c) FIRST and other WPILib contributors.
2// Open Source Software; you can modify and/or share it under the terms of
3// the WPILib BSD license file in the root directory of this project.
4
5#pragma once
6
7#include <chrono>
8#include <string_view>
9
12
13namespace wpi::util {
14class raw_ostream;
15} // namespace wpi::util
16
17namespace wpi {
18/**
19 * A class for keeping track of how much time it takes for different parts of
20 * code to execute. This is done with epochs, that are added to calls to
21 * AddEpoch() and can be printed with a call to PrintEpochs().
22 *
23 * Epochs are a way to partition the time elapsed so that when overruns occur,
24 * one can determine which parts of an operation consumed the most time.
25 */
26class Tracer {
27 public:
28 /**
29 * Constructs a Tracer instance.
30 */
32
33 /**
34 * Restarts the epoch timer.
35 */
36 void ResetTimer();
37
38 /**
39 * Clears all epochs.
40 */
42
43 /**
44 * Adds time since last epoch to the list printed by PrintEpochs().
45 *
46 * Epochs are a way to partition the time elapsed so that when overruns occur,
47 * one can determine which parts of an operation consumed the most time.
48 *
49 * @param epochName The name to associate with the epoch.
50 */
51 void AddEpoch(std::string_view epochName);
52
53 /**
54 * Prints list of epochs added so far and their times to the DriverStation.
55 */
57
58 /**
59 * Prints list of epochs added so far and their times to a stream.
60 *
61 * @param os output stream
62 */
63 void PrintEpochs(wpi::util::raw_ostream& os);
64
65 private:
66 static constexpr std::chrono::milliseconds kMinPrintPeriod{1000};
67
69 wpi::hal::fpga_clock::time_point m_lastEpochsPrintTime =
71
73};
74} // namespace wpi
void AddEpoch(std::string_view epochName)
Adds time since last epoch to the list printed by PrintEpochs().
Tracer()
Constructs a Tracer instance.
void ResetTimer()
Restarts the epoch timer.
void PrintEpochs(wpi::util::raw_ostream &os)
Prints list of epochs added so far and their times to a stream.
void ClearEpochs()
Clears all epochs.
void PrintEpochs()
Prints list of epochs added so far and their times to the DriverStation.
std::chrono::time_point< fpga_clock > time_point
Definition fpga_clock.hpp:20
static fpga_clock::time_point epoch() noexcept
Definition fpga_clock.hpp:25
StringMap is a sorted associative container that contains key-value pairs with unique string keys.
Definition StringMap.hpp:26
Definition raw_os_ostream.hpp:19
Definition CvSource.hpp:15