Counters
Counters are a very simple yet powerful addition to profiling just showing activities. Counter can be used to show values that are changing over time. Depending on which values you want to report to the profiler these counters can be a clear indication of why something takes longer than expected. Or maybe something isn’t slow at all but you just like to see how values behave over time, for example response times, average io latency, memory usage, framerate, etc.
Counters first need to be created before you can set them to some value. Often times counters are long-lived, being present during the entire run of an application or at the very least during the lifetime of some object. For that reason counters are often retained as members and then later those members are update. Below is a snippet showing both how to create a counter, specify it’s name and optionally a color and then later set the counter to some value. This automatically synchronizes the time at which activities are reported and thus you can see the value a counter had while activities are being executed.
#include <quApi.hpp>
class Application
{
public:
void Update()
{
QU_SET_COUNTER_VALUE( framerateCounter, 60.0f );
QU_SET_COUNTER_VALUE( memoryCounter, 36.5f );
}
private:
QU_SCOPED_COUNTER( framerateCounter, "Framerate" );
QU_SCOPED_COUNTER_COLOR( memoryCounter, "Memory Usage (MB)", QU_RGB( 200, 0, 0 ) );
};