Fang-Robotics-MCB
Fang Robotics Team Codebase
Loading...
Searching...
No Matches
profiler.hpp
Go to the documentation of this file.
1/*****************************************************************************/
2/********** !!! WARNING: CODE GENERATED BY TAPROOT. DO NOT EDIT !!! **********/
3/*****************************************************************************/
4
5/*
6 * Copyright (c) 2020-2022 Advanced Robotics at the University of Washington <robomstr@uw.edu>
7 *
8 * This file is part of Taproot.
9 *
10 * Taproot is free software: you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation, either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * Taproot is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with Taproot. If not, see <https://www.gnu.org/licenses/>.
22 */
23
24#ifndef TAPROOT_PROFILER_HPP_
25#define TAPROOT_PROFILER_HPP_
26
27#include <unordered_map>
28
29#include "modm/container.hpp"
30
31#ifdef RUN_WITH_PROFILING
32#define PROFILE(profiler, func, params) \
33 do \
34 { \
35 int key = profiler.push(#func); \
36 func params; \
37 profiler.pop(key); \
38 } while (0);
39#else
40#define PROFILE(profiler, func, params) func params
41#endif
42
43namespace tap
44{
45class Drivers;
46}
47
48namespace tap::arch
49{
99{
100public:
102 static constexpr std::size_t MAX_PROFILED_ELEMENTS = 128;
104 static constexpr float AVG_LOW_PASS_ALPHA = 0.01f;
105
110 {
112 const char* name = nullptr;
114 uint32_t min = UINT32_MAX;
116 uint32_t max = 0;
118 float avg = 0;
122 uint32_t prevPushedTime = 0;
123
125 explicit ProfilerData(const char* name) : name(name) {}
126
128 void reset()
129 {
130 min = UINT32_MAX;
131 max = 0;
132 avg = 0;
133 }
134 };
135
136 Profiler(tap::Drivers* drivers);
137
148 std::size_t push(const char* profile);
149
156 void pop(std::size_t key);
157
159 inline ProfilerData getData(std::size_t key)
160 {
161 if (key >= profiledElements.getSize())
162 {
163 return ProfilerData();
164 }
165 else
166 {
167 return profiledElements.get(key);
168 }
169 }
170
172 inline void reset(std::size_t key)
173 {
174 if (key < profiledElements.getSize())
175 {
176 profiledElements[key].reset();
177 }
178 }
179
180private:
181 tap::Drivers* drivers;
182
189 std::unordered_map<const char*, std::size_t> elementNameToIndexMap;
190
194 modm::BoundedDeque<ProfilerData, MAX_PROFILED_ELEMENTS> profiledElements;
195};
196
197} // namespace tap::arch
198
199#endif // TAPROOT_PROFILER_HPP_
Definition drivers.hpp:70
Definition profiler.hpp:99
static constexpr std::size_t MAX_PROFILED_ELEMENTS
Max number of profiles that the profiler can store information about.
Definition profiler.hpp:102
void pop(std::size_t key)
Definition profiler.cpp:61
std::size_t push(const char *profile)
Definition profiler.cpp:37
void reset(std::size_t key)
Reset the ProfilerData associated with some particular key.
Definition profiler.hpp:172
ProfilerData getData(std::size_t key)
Definition profiler.hpp:159
static constexpr float AVG_LOW_PASS_ALPHA
Low pass alpha to be used when averaging time it takes for some code to run.
Definition profiler.hpp:104
Definition clock.hpp:36
Definition ballistics.cpp:29
Definition profiler.hpp:110
uint32_t max
Max value, in microseconds, ever recorded by the profiler.
Definition profiler.hpp:116
uint32_t prevPushedTime
Definition profiler.hpp:122
void reset()
Resets the long term profile storage information.
Definition profiler.hpp:128
ProfilerData()
Definition profiler.hpp:124
ProfilerData(const char *name)
Definition profiler.hpp:125
float avg
Average value, in microseconds, averaged using a low pass filter.
Definition profiler.hpp:118
uint32_t min
Min value, in microseconds, ever recorded by the profiler.
Definition profiler.hpp:114
const char * name
Name of the profile.
Definition profiler.hpp:112