WPILibC++ 2024.3.2
Tracer.h
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
10#include <hal/cpp/fpga_clock.h>
11#include <wpi/StringMap.h>
12
13namespace wpi {
14class raw_ostream;
15} // namespace wpi
16
17namespace frc {
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 */
64
65 private:
66 static constexpr std::chrono::milliseconds kMinPrintPeriod{1000};
67
70
72};
73} // namespace frc
This file defines the StringMap class.
A class for keeping track of how much time it takes for different parts of code to execute.
Definition: Tracer.h:26
void AddEpoch(std::string_view epochName)
Adds time since last epoch to the list printed by PrintEpochs().
void ClearEpochs()
Clears all epochs.
void ResetTimer()
Restarts the epoch timer.
Tracer()
Constructs a Tracer instance.
void PrintEpochs(wpi::raw_ostream &os)
Prints list of epochs added so far and their times to a stream.
void PrintEpochs()
Prints list of epochs added so far and their times to the DriverStation.
static fpga_clock::time_point epoch() noexcept
Definition: fpga_clock.h:25
std::chrono::time_point< fpga_clock > time_point
Definition: fpga_clock.h:20
This class implements an extremely fast bulk output stream that can only output to a stream.
Definition: raw_ostream.h:43
basic_string_view< char > string_view
Definition: core.h:501
Definition: AprilTagPoseEstimator.h:15
Definition: ntcore_cpp.h:26