wolfpld / tracy

Frame profiler
https://tracy.nereid.pl/
Other
9.95k stars 657 forks source link

feature request: LockMark doesn't like arrow or dot operators #575

Open tycho opened 1 year ago

tycho commented 1 year ago

The compiler doesn't like usage of LockMark when you have arrow or dot operators, because of how it expands the macro:

image

I think maybe it needs a couple of changes:

  1. Unrelated, but it would be nice if the various Lock macros were prefixed with "Tracy" (i.e. TracyLockableBase TracySharedLockableBase, TracyLockMark and so forth).
  2. LockMark should probably accept an additional argument like the various ZoneNamed/ZoneTransient macros do. That way, doing LockMark(TakingSomeLock, someStructure->m_mutex) would work.

Maybe something like this?

diff --git a/public/tracy/Tracy.hpp b/public/tracy/Tracy.hpp
index 94b7d0f2..0e1d662f 100644
--- a/public/tracy/Tracy.hpp
+++ b/public/tracy/Tracy.hpp
@@ -56,6 +56,7 @@
 #define LockableBase( type ) type
 #define SharedLockableBase( type ) type
 #define LockMark(x) (void)x
+#define LockMarkNamed(x,y) (void)y
 #define LockableName(x,y,z)

 #define TracyPlot(x,y)
@@ -170,6 +171,7 @@
 #define LockableBase( type ) tracy::Lockable<type>
 #define SharedLockableBase( type ) tracy::SharedLockable<type>
 #define LockMark( varname ) static constexpr tracy::SourceLocationData __tracy_lock_location_##varname { nullptr, TracyFunction,  TracyFile, (uint32_t)TracyLine, 0 }; varname.Mark( &__tracy_lock_location_##varname )
+#define LockMarkNamed( varname, lockname ) static constexpr tracy::SourceLocationData __tracy_lock_location_##varname { nullptr, TracyFunction,  TracyFile, (uint32_t)TracyLine, 0 }; lockname.Mark( &__tracy_lock_location_##varname )
 #define LockableName( varname, txt, size ) varname.CustomName( txt, size )

 #define TracyPlot( name, val ) tracy::Profiler::PlotData( name, val )
wolfpld commented 1 year ago

As a workaround you may create a local reference to the mutex.