Skip to content

Commit 0bd58ff

Browse files
committed
Improve function name in trace report
__func__ is portable but doesn't report the class name
1 parent dbe868b commit 0bd58ff

1 file changed

Lines changed: 11 additions & 7 deletions

File tree

Profiler.hpp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ namespace {
6060
inline void killPool()
6161
{
6262
}
63+
64+
#define FUNC_NAME __FUNCSIG__
6365
}
6466

6567
#else // defined(WIN32)
@@ -106,6 +108,8 @@ namespace {
106108
#endif
107109
}
108110

111+
#define FUNC_NAME __PRETTY_FUNCTION__
112+
109113
}
110114

111115
#endif // defined(WIN32)
@@ -899,7 +903,7 @@ inline void operator delete(void* ptr, size_t sz) noexcept
899903
nested inside functions to generate independent events. */
900904
#define INSTRUMENT_SCOPE(EVENT, VALUE, ...) \
901905
profiler::Global<>::traceMemory = false; \
902-
static uint16_t CAT(__profiler_id_,EVENT) = \
906+
static const uint16_t CAT(__profiler_id_,EVENT) = \
903907
profiler::registerName(std::string(__VA_ARGS__), __FILE__, __LINE__, EVENT, 0); \
904908
profiler::ProfilerGuard<> guard(CAT(__profiler_id_,EVENT), VALUE); \
905909
profiler::Global<>::traceMemory = true;
@@ -912,12 +916,12 @@ inline void operator delete(void* ptr, size_t sz) noexcept
912916
This is intended to be called immediately after a function starts. */
913917
#define INSTRUMENT_FUNCTION(...) \
914918
profiler::Global<>::traceMemory = false; \
915-
static std::string __profiler_function_name = \
916-
std::string_view(__VA_ARGS__).empty() ? __func__ : std::string(__VA_ARGS__); \
917-
static uint16_t __profiler_function_id = \
919+
static const std::string __profiler_function_name = \
920+
std::string_view(__VA_ARGS__).empty() ? FUNC_NAME : std::string(__VA_ARGS__); \
921+
static const uint16_t __profiler_function_id = \
918922
profiler::registerName(__profiler_function_name, __FILE__, __LINE__, 0, 0); \
919923
static uint16_t CAT(__profiler_function_,__LINE__) = \
920-
profiler::registerName(__profiler_function_name, __FILE__, __LINE__, __profiler_function_id, 1); \
924+
profiler::registerName(__func__, __FILE__, __LINE__, __profiler_function_id, 1); \
921925
profiler::ProfilerGuard<> __guard(__profiler_function_id, CAT(__profiler_function_,__LINE__)); \
922926
profiler::Global<>::traceMemory = true;
923927

@@ -926,11 +930,11 @@ inline void operator delete(void* ptr, size_t sz) noexcept
926930
927931
This macro creates a new event value for the __profiler_function_id event.
928932
An extra second string argument can be passed to the macro in order to set a
929-
custom name to the event value. Otherwise the __funct__:__LINE__ will be used.
933+
custom name to the event value. Otherwise the __func__:__LINE__ will be used.
930934
@param VALUE the numeric value for the event. */
931935
#define INSTRUMENT_FUNCTION_UPDATE(VALUE, ...) \
932936
profiler::Global<>::traceMemory = false; \
933-
static uint16_t CAT(__profiler_function_,__LINE__) = \
937+
static const uint16_t CAT(__profiler_function_,__LINE__) = \
934938
profiler::registerName(std::string(__VA_ARGS__), __FILE__, __LINE__, __profiler_function_id, VALUE); \
935939
profiler::Global<>::getInfoThread().eventsBuffer.emplaceEvent( \
936940
__profiler_function_id, CAT(__profiler_function_,__LINE__) \

0 commit comments

Comments
 (0)