Skip to content

Commit 6752949

Browse files
committed
[Cleanup] Reduce bin size when using timing stats
Reduce macro code
1 parent 52b5394 commit 6752949

File tree

2 files changed

+31
-11
lines changed

2 files changed

+31
-11
lines changed

src/src/DataStructs/TimingStats.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,31 @@ const __FlashStringHelper * getMiscStatsName_F(int stat) {
258258

259259
String getMiscStatsName(int stat) {
260260
if (stat >= C001_DELAY_QUEUE && stat <= C025_DELAY_QUEUE) {
261-
String result;
262-
result.reserve(16);
263-
result = F("Delay queue ");
264-
result += get_formatted_Controller_number(static_cast<cpluginID_t>(stat - C001_DELAY_QUEUE + 1));
265-
return result;
261+
return concat(
262+
F("Delay queue "),
263+
get_formatted_Controller_number(static_cast<cpluginID_t>(stat - C001_DELAY_QUEUE + 1)));
266264
}
267265
return getMiscStatsName_F(stat);
268266
}
269267

268+
void stopTimerTask(int T, int F, uint64_t statisticsTimerStart)
269+
{
270+
if (mustLogFunction(F)) pluginStats[(T) * 256 + (F)].add(usecPassedSince(statisticsTimerStart));
271+
}
272+
273+
void stopTimerController(int T, CPlugin::Function F, uint64_t statisticsTimerStart)
274+
{
275+
if (mustLogCFunction(F)) controllerStats[(T) * 256 + static_cast<int>(F)].add(usecPassedSince(statisticsTimerStart));
276+
}
277+
278+
void stopTimer(int L, uint64_t statisticsTimerStart)
279+
{
280+
if (Settings.EnableTimingStats()) { miscStats[L].add(usecPassedSince(statisticsTimerStart)); }
281+
}
282+
283+
void addMiscTimerStat(int L, int64_t T)
284+
{
285+
if (Settings.EnableTimingStats()) { miscStats[L].add(T); }
286+
}
287+
270288
#endif // if FEATURE_TIMING_STATS

src/src/DataStructs/TimingStats.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,23 +129,25 @@ const __FlashStringHelper * getCPluginCFunctionName(CPlugin::Function function);
129129
bool mustLogCFunction(CPlugin::Function function);
130130
String getMiscStatsName(int stat);
131131

132+
void stopTimerTask(int T, int F, uint64_t statisticsTimerStart);
133+
void stopTimerController(int T, CPlugin::Function F, uint64_t statisticsTimerStart);
134+
void stopTimer(int L, uint64_t statisticsTimerStart);
135+
void addMiscTimerStat(int L, int64_t T);
132136

133137
extern std::map<int, TimingStats> pluginStats;
134138
extern std::map<int, TimingStats> controllerStats;
135139
extern std::map<int, TimingStats> miscStats;
136140
extern unsigned long timingstats_last_reset;
137141

138142
# define START_TIMER const uint64_t statisticsTimerStart(getMicros64());
139-
# define STOP_TIMER_TASK(T, F) \
140-
if (mustLogFunction(F)) pluginStats[(T) * 256 + (F)].add(usecPassedSince(statisticsTimerStart));
141-
# define STOP_TIMER_CONTROLLER(T, F) \
142-
if (mustLogCFunction(F)) controllerStats[(T) * 256 + static_cast<int>(F)].add(usecPassedSince(statisticsTimerStart));
143+
# define STOP_TIMER_TASK(T, F) stopTimerTask(T, F, statisticsTimerStart);
144+
# define STOP_TIMER_CONTROLLER(T, F) stopTimerController(T, F, statisticsTimerStart);
143145

144146
// #define STOP_TIMER_LOADFILE miscStats[LOADFILE_STATS].add(usecPassedSince(statisticsTimerStart));
145-
# define STOP_TIMER(L) if (Settings.EnableTimingStats()) { miscStats[L].add(usecPassedSince(statisticsTimerStart)); }
147+
# define STOP_TIMER(L) stopTimer(L, statisticsTimerStart);
146148

147149
// Add a timer statistic value in usec.
148-
# define ADD_TIMER_STAT(L, T) if (Settings.EnableTimingStats()) { miscStats[L].add(T); }
150+
# define ADD_TIMER_STAT(L, T) addMiscTimerStat(L, T);
149151

150152
#else // if FEATURE_TIMING_STATS
151153

0 commit comments

Comments
 (0)