Files
Lioncache 7f20a5ef97 General: Add AXIO_ prefix to header guards
Makes any future potential of a class unlikely.
2026-01-16 22:45:09 -05:00

42 lines
809 B
C++

#ifndef AXIO_CSCOPEDTIMER_H
#define AXIO_CSCOPEDTIMER_H
#include "Common/CTimer.h"
#include "Common/Log.h"
#include <string_view>
// Runs a timer and automatically stops + prints the time to the log when it goes out of scope.
class CScopedTimer
{
CTimer mTimer;
std::string_view mTimerName;
bool mStopped = false;
public:
explicit CScopedTimer(std::string_view timerName)
: mTimerName(timerName)
{
mTimer.Start();
}
~CScopedTimer()
{
Stop();
}
void Stop()
{
if (!mStopped)
{
NLog::Debug("{} finished in {}s", mTimerName, mTimer.Stop());
mStopped = true;
}
}
};
#define SCOPED_TIMER(TimerName) \
[[maybe_unused]] CScopedTimer TimerName(#TimerName)
#endif // AXIO_CSCOPEDTIMER_H