26 for (
auto& block : *
this)
66 if (find(name) == end())
70 (*this)[name] = block;
77 (*this)[name]->isStarted =
true;
86 if (find(name) != end())
88 if (!(*
this)[name]->isStarted)
89 Utils::log(
"AverageTiming: Block with name %s stopped without being started!", name.c_str());
90 (*this)[name]->timer.stop();
91 (*this)[name]->val.set((*
this)[name]->timer.elapsedTimeInMilliSec());
92 (*this)[name]->nCalls++;
93 (*this)[name]->isStarted =
false;
97 Utils::log(
"AverageTiming: A block with name %s does not exist!", name.c_str());
104 if (find(name) != end())
106 return (*
this)[name]->val.average();
109 Utils::log(
"AverageTiming: A block with name %s does not exist!", name.c_str());
119 for (
const std::string& n : names)
131 std::vector<AverageTimingBlock*> blocks;
134 blocks.push_back(block.second);
136 std::sort(blocks.begin(),
139 { return lhs->posV < rhs->posV; });
142 float refTime = 1.0f;
145 refTime = (*blocks.begin())->val.average();
147 volatile int sizeofm =
sizeof(m);
148 snprintf(m + strlen(m), sizeofm,
"Num. calls: %i\n", (
int)(*blocks.begin())->nCalls);
153 for (
auto* block : blocks)
154 if (block->name.length() > maxLen)
155 maxLen = block->name.length();
158 for (
auto* block : blocks)
160 float val = block->val.average();
161 float valPC =
Utils::clamp(val / refTime * 100.0f, 0.0f, 100.0f);
162 string name = block->name;
164 name.append(maxLen - name.length(),
' ');
169 ss <<
"%s: %4.1f ms (%3d%%)\n";
170 snprintf(m + strlen(m),
sizeof(m), ss.str().c_str(), name.c_str(), val, (
int)valPC);
static float getTime(const std::string &name)
get time for block with name
void doStart(const std::string &name)
do start timer for a new or existing block
static void stop(const std::string &name)
stop timer for a running block with name
void doGetTimingMessage(char *m)
do get timings formatted via string
static AverageTiming & instance()
singleton
float doGetTime(const std::string &name)
do get time for block with name
void doStop(const std::string &name)
do stop timer for a running block with name
static void getTimingMessage(char *m)
get timings formatted via string
static void start(const std::string &name)
start timer for a new or existing block
void set(T value)
Sets the current value in the value array and builds the average.
Utils provides utilities for string & file handling, logging and math functions.
T clamp(T a, T min, T max)
void log(const char *tag, const char *format,...)
logs a formatted string platform independently
concatenation of average value and timer