yolobs-studio/libobs/util/profiler.hpp

48 lines
990 B
C++
Raw Permalink Normal View History

2016-02-23 23:16:51 +00:00
#pragma once
#include "profiler.h"
struct ScopeProfiler {
const char *name;
bool enabled = true;
2019-09-22 21:19:10 +00:00
ScopeProfiler(const char *name) : name(name) { profile_start(name); }
2016-02-23 23:16:51 +00:00
~ScopeProfiler() { Stop(); }
ScopeProfiler(const ScopeProfiler &) = delete;
ScopeProfiler(ScopeProfiler &&other)
2019-09-22 21:19:10 +00:00
: name(other.name), enabled(other.enabled)
2016-02-23 23:16:51 +00:00
{
other.enabled = false;
}
ScopeProfiler &operator=(const ScopeProfiler &) = delete;
ScopeProfiler &operator=(ScopeProfiler &&other) = delete;
void Stop()
{
if (!enabled)
return;
profile_end(name);
enabled = false;
}
};
#ifndef NO_PROFILER_MACROS
2019-09-22 21:19:10 +00:00
#define ScopeProfiler_NameConcatImpl(x, y) x##y
2016-02-23 23:16:51 +00:00
#define ScopeProfiler_NameConcat(x, y) ScopeProfiler_NameConcatImpl(x, y)
#ifdef __COUNTER__
#define ScopeProfiler_Name(x) ScopeProfiler_NameConcat(x, __COUNTER__)
#else
#define ScopeProfiler_Name(x) ScopeProfiler_NameConcat(x, __LINE__)
#endif
2019-09-22 21:19:10 +00:00
#define ProfileScope(x) \
ScopeProfiler ScopeProfiler_Name(SCOPE_PROFILE) { x }
2016-02-23 23:16:51 +00:00
#endif