-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprofiler.hpp
More file actions
52 lines (41 loc) · 1.69 KB
/
profiler.hpp
File metadata and controls
52 lines (41 loc) · 1.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#ifndef PROFILER_H
#define PROFILER_H
// Use this flag to toggle profiling globally.
#define PROFILE
#include <Arduino.h>
#define PROF_MAX_SECTIONS 8 // max number of active profiling sections
#define PROF_MAX_NAME 16 // max length of section name
#define PROF_MAX_TIMES (5000) // max number of start/end times per section
/// @brief Object for profiling sections of code.
struct Profiler {
/// @brief Constructor for the profiler.
Profiler() { clear(); }
/// @brief Data structure for a profiling section
struct profiler_section_t {
/// @brief the time lengths of each profiling section
uint32_t time_lengths[PROF_MAX_TIMES] = {0};
/// @brief Start time for the current profiling section
uint32_t start_time = 0;
/// @brief Number of start/end times recorded
uint16_t count = 0;
/// @brief Label on if count has overflowed
uint8_t overflowed = 0;
/// @brief Label on if a begin() has been called and the corresponding end() hasn't yet
uint8_t started = 0;
/// @brief Name for each section
char name[PROF_MAX_NAME + 1] = {0};// +1 extra space for null terminator
};
/// @brief clear all profiling sections
void clear();
/// @brief Start a profiling section
/// @param name A unique name to identify the section
void begin(const char *name);
/// @brief End a profiling section
/// @param name The name of the section to end
void end(const char *name);
/// @brief Print stats for a profiling section
/// @param name The name of the section to print stats for
void print(const char *name);
};
extern Profiler prof; // Global profiler
#endif // PROFILER_H