Add possibility to explicitly avoid logging

This commit is contained in:
Arvid Gerstmann 2018-08-13 14:47:52 +02:00
parent c4ea13dab5
commit 076e83635b
2 changed files with 49 additions and 43 deletions

View File

@ -6,10 +6,10 @@
#ifndef TRACY_ENABLE
#define ZoneNamed(x)
#define ZoneNamedN(x,y)
#define ZoneNamedC(x,y)
#define ZoneNamedNC(x,y,z)
#define ZoneNamed(x,y)
#define ZoneNamedN(x,y,z)
#define ZoneNamedC(x,y,z)
#define ZoneNamedNC(x,y,z,w)
#define ZoneScoped
#define ZoneScopedN(x)
@ -59,15 +59,20 @@
#include "client/TracyProfiler.hpp"
#include "client/TracyScoped.hpp"
#define ZoneNamed( varname ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__) );
#define ZoneNamedN( varname, name ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__) );
#define ZoneNamedC( varname, color ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__) );
#define ZoneNamedNC( varname, name, color ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__) );
#define ZoneNamed( varname, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active );
#define ZoneNamedN( varname, name, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active );
#define ZoneNamedC( varname, color, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active );
#define ZoneNamedNC( varname, name, color, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), active );
#define ZoneScoped ZoneNamed( ___tracy_scoped_zone )
#define ZoneScopedN( name ) ZoneNamedN( ___tracy_scoped_zone, name )
#define ZoneScopedC( color ) ZoneNamedC( ___tracy_scoped_zone, color )
#define ZoneScopedNC( name, color ) ZoneNamedNC( ___tracy_scoped_zone, name, color )
#define ZoneScoped ZoneNamed( ___tracy_scoped_zone, true )
#define ZoneScopedN( name ) ZoneNamedN( ___tracy_scoped_zone, name, true )
#define ZoneScopedC( color ) ZoneNamedC( ___tracy_scoped_zone, color, true )
#define ZoneScopedNC( name, color ) ZoneNamedNC( ___tracy_scoped_zone, name, color, true )
#define ZoneScopedA( active ) ZoneNamed( ___tracy_scoped_zone, active )
#define ZoneScopedNA( name, active ) ZoneNamedN( ___tracy_scoped_zone, name, active )
#define ZoneScopedCA( color, active ) ZoneNamedC( ___tracy_scoped_zone, color, active )
#define ZoneScopedNCA( name, color, active ) ZoneNamedNC( ___tracy_scoped_zone, name, color, active )
#define ZoneText( txt, size ) ___tracy_scoped_zone.Text( txt, size );
#define ZoneName( txt, size ) ___tracy_scoped_zone.Name( txt, size );
@ -94,28 +99,38 @@
#define TracyFree( ptr ) tracy::Profiler::MemFree( ptr );
#ifdef TRACY_HAS_CALLSTACK
# define ZoneNamedS( varname, depth ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth );
# define ZoneNamedNS( varname, name, depth ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth );
# define ZoneNamedCS( varname, color, depth ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth );
# define ZoneNamedNCS( varname, name, color, depth ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth );
# define ZoneNamedS( varname, depth, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active );
# define ZoneNamedNS( varname, name, depth, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, 0 }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active );
# define ZoneNamedCS( varname, color, depth, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { nullptr, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active );
# define ZoneNamedNCS( varname, name, color, depth, active ) static const tracy::SourceLocationData TracyConcat(__tracy_source_location,__LINE__) { name, __FUNCTION__, __FILE__, (uint32_t)__LINE__, color }; tracy::ScopedZone varname( &TracyConcat(__tracy_source_location,__LINE__), depth, active );
# define ZoneScopedS( depth ) ZoneNamedS( ___tracy_scoped_zone, depth )
# define ZoneScopedNS( name, depth ) ZoneNamedNS( ___tracy_scoped_zone, name, depth )
# define ZoneScopedCS( color, depth ) ZoneNamedCS( ___tracy_scoped_zone, color, depth )
# define ZoneScopedNCS( name, color, depth ) ZoneNamedNCS( ___tracy_scoped_zone, name, color depth )
# define ZoneScopedS( depth ) ZoneNamedS( ___tracy_scoped_zone, depth, true )
# define ZoneScopedNS( name, depth ) ZoneNamedNS( ___tracy_scoped_zone, name, depth, true )
# define ZoneScopedCS( color, depth ) ZoneNamedCS( ___tracy_scoped_zone, color, depth, true )
# define ZoneScopedNCS( name, color, depth ) ZoneNamedNCS( ___tracy_scoped_zone, name, color depth, true )
# define ZoneScopedSA( depth, active ) ZoneNamedS( ___tracy_scoped_zone, depth, active )
# define ZoneScopedNSA( name, depth, active ) ZoneNamedNS( ___tracy_scoped_zone, name, depth, active )
# define ZoneScopedCSA( color, depth, active ) ZoneNamedCS( ___tracy_scoped_zone, color, depth, active )
# define ZoneScopedNCSA( name, color, depth, active ) ZoneNamedNCS( ___tracy_scoped_zone, name, color depth, active )
# define TracyAllocS( ptr, size, depth ) tracy::Profiler::MemAllocCallstack( ptr, size, depth );
# define TracyFreeS( ptr, depth ) tracy::Profiler::MemFreeCallstack( ptr, depth );
#else
# define ZoneNamedS( varname, depth ) ZoneNamed( varname )
# define ZoneNamedNS( varname, name, depth ) ZoneNamedN( varname, name )
# define ZoneNamedCS( varname, color, depth ) ZoneNamedC( varname, color )
# define ZoneNamedNCS( varname, name, color, depth ) ZoneNamedNC( varname, name, color )
# define ZoneNamedS( varname, depth, active ) ZoneNamed( varname, active )
# define ZoneNamedNS( varname, name, depth, active ) ZoneNamedN( varname, name, active )
# define ZoneNamedCS( varname, color, depth, active ) ZoneNamedC( varname, color, active )
# define ZoneNamedNCS( varname, name, color, depth, active ) ZoneNamedNC( varname, name, color, active )
# define ZoneScopedS( depth ) ZoneScoped
# define ZoneScopedNS( name, depth ) ZoneScopedN( name )
# define ZoneScopedCS( color, depth ) ZoneScopedC( color )
# define ZoneScopedNCS( name, color, depth ) ZoneScopedNC( name, color )
# define ZoneScopedS( depth ) ZoneScoped( depth, true )
# define ZoneScopedNS( name, depth ) ZoneScopedN( name, true )
# define ZoneScopedCS( color, depth ) ZoneScopedC( color, true )
# define ZoneScopedNCS( name, color, depth ) ZoneScopedNC( name, color, true )
# define ZoneScopedSA( depth, active ) ZoneScoped( depth, active )
# define ZoneScopedNSA( name, depth, active ) ZoneScopedN( name, active )
# define ZoneScopedCSA( color, depth, active ) ZoneScopedC( color, active )
# define ZoneScopedNCSA( name, color, depth, active ) ZoneScopedNC( name, color, active )
# define TracyAllocS( ptr, size, depth ) TracyAlloc( ptr, size )
# define TracyFreeS( ptr, depth ) TracyFree( ptr )

View File

@ -15,14 +15,14 @@ namespace tracy
class ScopedZone
{
public:
tracy_force_inline ScopedZone( const SourceLocationData* srcloc )
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, bool is_active = true )
#ifdef TRACY_ON_DEMAND
: m_active( s_profiler.IsConnected() )
#else
: m_active( is_active )
#endif
{
#ifdef TRACY_ON_DEMAND
if( !m_active ) return;
#endif
const auto thread = GetThreadHandle();
m_thread = thread;
Magic magic;
@ -42,14 +42,14 @@ public:
tail.store( magic + 1, std::memory_order_release );
}
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth )
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth, bool is_active = true )
#ifdef TRACY_ON_DEMAND
: m_active( s_profiler.IsConnected() )
#else
: m_active( is_active )
#endif
{
#ifdef TRACY_ON_DEMAND
if( !m_active ) return;
#endif
const auto thread = GetThreadHandle();
m_thread = thread;
Magic magic;
@ -73,9 +73,7 @@ public:
tracy_force_inline ~ScopedZone()
{
#ifdef TRACY_ON_DEMAND
if( !m_active ) return;
#endif
Magic magic;
auto& token = s_token.ptr;
auto& tail = token->get_tail_index();
@ -94,9 +92,7 @@ public:
tracy_force_inline void Text( const char* txt, size_t size )
{
#ifdef TRACY_ON_DEMAND
if( !m_active ) return;
#endif
Magic magic;
auto& token = s_token.ptr;
auto ptr = (char*)tracy_malloc( size+1 );
@ -112,9 +108,7 @@ public:
tracy_force_inline void Name( const char* txt, size_t size )
{
#ifdef TRACY_ON_DEMAND
if( !m_active ) return;
#endif
Magic magic;
auto& token = s_token.ptr;
auto ptr = (char*)tracy_malloc( size+1 );
@ -130,10 +124,7 @@ public:
private:
uint64_t m_thread;
#ifdef TRACY_ON_DEMAND
const bool m_active;
#endif
};
}