9#define JNG_PROFILING_ENABLED 0
10#if JNG_PROFILING_ENABLED
26 void beginSession(
const std::string& filepath);
28 void addProfile(
const Result& result);
30 static Profiler& get() {
return s_instance; }
37 std::ofstream m_output;
40 static Profiler s_instance;
46 ProfilingTimer(
const char* name) :
48 m_startTS(std::chrono::steady_clock::now())
53 auto endTS = std::chrono::steady_clock::now();
55 Profiler::get().addProfile({
57 std::chrono::time_point_cast<std::chrono::microseconds>(m_startTS).time_since_epoch().count(),
58 std::chrono::time_point_cast<std::chrono::microseconds>(endTS).time_since_epoch().count()
63 std::chrono::time_point<std::chrono::steady_clock> m_startTS;
67 constexpr auto cleanupStringForProfiler(
const char(&str)[SIZE])
69 constexpr size_t arrSize = 3;
70 constexpr const char* remove[arrSize] = {
75 constexpr size_t removeSize[3] = { 9, 7, 8 };
79 for (
size_t srcIndex = 0; srcIndex < SIZE; ++srcIndex)
81 for (
size_t i = 0; i < arrSize; ++i)
83 size_t matchIndex = 0;
84 while (matchIndex < removeSize[i] - 1 && srcIndex + matchIndex < SIZE - 1 && str[srcIndex + matchIndex] == remove[i][matchIndex])
86 if (matchIndex == removeSize[i] - 1)
87 srcIndex += matchIndex;
90 result[dstIndex++] = str[srcIndex] ==
'"' ?
'\'' : str[srcIndex];
92 return std::string(result);
97#if defined(__FUNCSIG__)
98#define __JNG_FUNCSIG __FUNCSIG__
100#define __JNG_FUNCSIG __PRETTY_FUNCTION__
103#define JNG_PROFILE_BEGIN_SESSION(filepath) jng::Profiler::get().beginSession(filepath)
104#define JNG_PROFILE_END_SESSION() jng::Profiler::get().endSession()
105#define __JNG_CONCAT(x, y) x##y
106#define __JNG_PROFILE_SCOPE(name, line) jng::ProfilingTimer __JNG_CONCAT(timer, line)(jng::cleanupStringForProfiler(name).c_str())
107#define JNG_PROFILE_SCOPE(name) __JNG_PROFILE_SCOPE(name, __LINE__)
108#define JNG_PROFILE_FUNCTION() JNG_PROFILE_SCOPE(__JNG_FUNCSIG)
112#define JNG_PROFILE_BEGIN_SESSION(filepath)
113#define JNG_PROFILE_END_SESSION()
114#define JNG_PROFILE_SCOPE(name)
115#define JNG_PROFILE_FUNCTION()