2017-09-10 18:09:57 +00:00
|
|
|
#ifndef __TRACYSCOPED_HPP__
|
|
|
|
#define __TRACYSCOPED_HPP__
|
|
|
|
|
2020-07-21 18:09:25 +00:00
|
|
|
#include <limits>
|
2024-02-11 15:24:37 +00:00
|
|
|
#include <stdarg.h>
|
2017-09-10 18:09:57 +00:00
|
|
|
#include <stdint.h>
|
2017-09-28 19:10:02 +00:00
|
|
|
#include <string.h>
|
2017-09-10 18:09:57 +00:00
|
|
|
|
2017-09-25 19:13:59 +00:00
|
|
|
#include "../common/TracySystem.hpp"
|
2018-03-31 12:03:55 +00:00
|
|
|
#include "../common/TracyAlign.hpp"
|
2017-10-18 17:08:19 +00:00
|
|
|
#include "../common/TracyAlloc.hpp"
|
2017-09-10 18:09:57 +00:00
|
|
|
#include "TracyProfiler.hpp"
|
|
|
|
|
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
|
|
|
|
class ScopedZone
|
|
|
|
{
|
|
|
|
public:
|
2020-09-23 15:39:53 +00:00
|
|
|
ScopedZone( const ScopedZone& ) = delete;
|
|
|
|
ScopedZone( ScopedZone&& ) = delete;
|
|
|
|
ScopedZone& operator=( const ScopedZone& ) = delete;
|
|
|
|
ScopedZone& operator=( ScopedZone&& ) = delete;
|
|
|
|
|
2018-08-13 12:47:52 +00:00
|
|
|
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, bool is_active = true )
|
2018-07-11 10:16:55 +00:00
|
|
|
#ifdef TRACY_ON_DEMAND
|
2019-02-19 17:38:08 +00:00
|
|
|
: m_active( is_active && GetProfiler().IsConnected() )
|
2018-08-13 12:47:52 +00:00
|
|
|
#else
|
|
|
|
: m_active( is_active )
|
2018-07-11 10:16:55 +00:00
|
|
|
#endif
|
2017-09-10 18:09:57 +00:00
|
|
|
{
|
2018-07-10 19:55:52 +00:00
|
|
|
if( !m_active ) return;
|
2020-01-25 16:21:30 +00:00
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
m_connectionId = GetProfiler().ConnectionId();
|
|
|
|
#endif
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueuePrepare( QueueType::ZoneBegin );
|
2019-08-12 17:18:17 +00:00
|
|
|
MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
|
2018-03-31 12:03:55 +00:00
|
|
|
MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueueCommit( zoneBeginThread );
|
2017-09-10 18:09:57 +00:00
|
|
|
}
|
|
|
|
|
2018-08-13 12:47:52 +00:00
|
|
|
tracy_force_inline ScopedZone( const SourceLocationData* srcloc, int depth, bool is_active = true )
|
2018-07-11 10:16:55 +00:00
|
|
|
#ifdef TRACY_ON_DEMAND
|
2019-02-19 17:38:08 +00:00
|
|
|
: m_active( is_active && GetProfiler().IsConnected() )
|
2018-08-13 12:47:52 +00:00
|
|
|
#else
|
|
|
|
: m_active( is_active )
|
2018-07-11 10:16:55 +00:00
|
|
|
#endif
|
2018-06-21 22:56:01 +00:00
|
|
|
{
|
2018-07-10 19:55:52 +00:00
|
|
|
if( !m_active ) return;
|
2020-01-25 16:21:30 +00:00
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
m_connectionId = GetProfiler().ConnectionId();
|
|
|
|
#endif
|
2020-09-29 14:39:56 +00:00
|
|
|
GetProfiler().SendCallstack( depth );
|
|
|
|
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueuePrepare( QueueType::ZoneBeginCallstack );
|
2019-08-12 17:18:17 +00:00
|
|
|
MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
|
2018-06-21 22:56:01 +00:00
|
|
|
MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueueCommit( zoneBeginThread );
|
2018-06-21 22:56:01 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 14:13:23 +00:00
|
|
|
tracy_force_inline ScopedZone( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, uint32_t color, bool is_active = true )
|
2020-08-16 12:50:27 +00:00
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
: m_active( is_active && GetProfiler().IsConnected() )
|
|
|
|
#else
|
|
|
|
: m_active( is_active )
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if( !m_active ) return;
|
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
m_connectionId = GetProfiler().ConnectionId();
|
|
|
|
#endif
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueuePrepare( QueueType::ZoneBeginAllocSrcLoc );
|
2024-03-17 14:13:23 +00:00
|
|
|
const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz, color );
|
2020-08-16 12:50:27 +00:00
|
|
|
MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
|
|
|
|
MemWrite( &item->zoneBegin.srcloc, srcloc );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueueCommit( zoneBeginThread );
|
2020-08-16 12:50:27 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 14:13:23 +00:00
|
|
|
tracy_force_inline ScopedZone( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, bool is_active = true ) : ScopedZone( line, source, sourceSz, function, functionSz, name, nameSz, static_cast<uint32_t>(0), is_active ) {}
|
|
|
|
|
|
|
|
tracy_force_inline ScopedZone( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, uint32_t color, int depth, bool is_active = true )
|
2020-08-16 12:50:27 +00:00
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
: m_active( is_active && GetProfiler().IsConnected() )
|
|
|
|
#else
|
|
|
|
: m_active( is_active )
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
if( !m_active ) return;
|
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
m_connectionId = GetProfiler().ConnectionId();
|
|
|
|
#endif
|
2020-09-29 14:39:56 +00:00
|
|
|
GetProfiler().SendCallstack( depth );
|
|
|
|
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueuePrepare( QueueType::ZoneBeginAllocSrcLocCallstack );
|
2024-03-17 14:13:23 +00:00
|
|
|
const auto srcloc = Profiler::AllocSourceLocation( line, source, sourceSz, function, functionSz, name, nameSz, color );
|
2020-08-16 12:50:27 +00:00
|
|
|
MemWrite( &item->zoneBegin.time, Profiler::GetTime() );
|
|
|
|
MemWrite( &item->zoneBegin.srcloc, srcloc );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueueCommit( zoneBeginThread );
|
2020-08-16 12:50:27 +00:00
|
|
|
}
|
|
|
|
|
2024-03-17 14:13:23 +00:00
|
|
|
tracy_force_inline ScopedZone( uint32_t line, const char* source, size_t sourceSz, const char* function, size_t functionSz, const char* name, size_t nameSz, int depth, bool is_active = true ) : ScopedZone( line, source, sourceSz, function, functionSz, name, nameSz, 0, depth, is_active ) {}
|
|
|
|
|
2017-10-03 13:10:25 +00:00
|
|
|
tracy_force_inline ~ScopedZone()
|
2017-09-10 18:09:57 +00:00
|
|
|
{
|
2018-07-10 19:55:52 +00:00
|
|
|
if( !m_active ) return;
|
2019-06-09 15:15:47 +00:00
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
|
|
|
#endif
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueuePrepare( QueueType::ZoneEnd );
|
2019-08-12 17:18:17 +00:00
|
|
|
MemWrite( &item->zoneEnd.time, Profiler::GetTime() );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueueCommit( zoneEndThread );
|
2017-09-10 18:09:57 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 13:10:25 +00:00
|
|
|
tracy_force_inline void Text( const char* txt, size_t size )
|
2017-09-27 00:18:17 +00:00
|
|
|
{
|
2023-08-17 08:03:52 +00:00
|
|
|
assert( size < (std::numeric_limits<uint16_t>::max)() );
|
2018-07-10 19:55:52 +00:00
|
|
|
if( !m_active ) return;
|
2019-06-09 15:15:47 +00:00
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
|
|
|
#endif
|
2020-07-21 18:09:25 +00:00
|
|
|
auto ptr = (char*)tracy_malloc( size );
|
2017-09-27 00:18:17 +00:00
|
|
|
memcpy( ptr, txt, size );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueuePrepare( QueueType::ZoneText );
|
2020-07-21 18:09:25 +00:00
|
|
|
MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
|
|
|
|
MemWrite( &item->zoneTextFat.size, (uint16_t)size );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueueCommit( zoneTextFatThread );
|
2017-09-27 00:18:17 +00:00
|
|
|
}
|
|
|
|
|
2024-08-08 17:55:32 +00:00
|
|
|
void TextFmt( const char* fmt, ... )
|
2024-02-11 15:24:37 +00:00
|
|
|
{
|
|
|
|
if( !m_active ) return;
|
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
|
|
|
#endif
|
|
|
|
va_list args;
|
|
|
|
va_start( args, fmt );
|
|
|
|
auto size = vsnprintf( nullptr, 0, fmt, args );
|
|
|
|
va_end( args );
|
|
|
|
if( size < 0 ) return;
|
|
|
|
assert( size < (std::numeric_limits<uint16_t>::max)() );
|
|
|
|
|
|
|
|
char* ptr = (char*)tracy_malloc( size_t( size ) + 1 );
|
|
|
|
va_start( args, fmt );
|
|
|
|
vsnprintf( ptr, size_t( size ) + 1, fmt, args );
|
|
|
|
va_end( args );
|
|
|
|
|
|
|
|
TracyQueuePrepare( QueueType::ZoneText );
|
|
|
|
MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
|
|
|
|
MemWrite( &item->zoneTextFat.size, (uint16_t)size );
|
|
|
|
TracyQueueCommit( zoneTextFatThread );
|
|
|
|
}
|
|
|
|
|
2018-06-29 14:01:31 +00:00
|
|
|
tracy_force_inline void Name( const char* txt, size_t size )
|
|
|
|
{
|
2023-08-17 08:03:52 +00:00
|
|
|
assert( size < (std::numeric_limits<uint16_t>::max)() );
|
2018-07-10 19:55:52 +00:00
|
|
|
if( !m_active ) return;
|
2019-06-09 15:15:47 +00:00
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
|
|
|
#endif
|
2020-07-21 18:09:25 +00:00
|
|
|
auto ptr = (char*)tracy_malloc( size );
|
2018-06-29 14:01:31 +00:00
|
|
|
memcpy( ptr, txt, size );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueuePrepare( QueueType::ZoneName );
|
2020-07-21 18:09:25 +00:00
|
|
|
MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
|
|
|
|
MemWrite( &item->zoneTextFat.size, (uint16_t)size );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueueCommit( zoneTextFatThread );
|
2018-06-29 14:01:31 +00:00
|
|
|
}
|
|
|
|
|
2024-08-08 17:55:32 +00:00
|
|
|
void NameFmt( const char* fmt, ... )
|
2024-02-11 15:24:37 +00:00
|
|
|
{
|
|
|
|
if( !m_active ) return;
|
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
|
|
|
#endif
|
|
|
|
va_list args;
|
|
|
|
va_start( args, fmt );
|
|
|
|
auto size = vsnprintf( nullptr, 0, fmt, args );
|
|
|
|
va_end( args );
|
|
|
|
if( size < 0 ) return;
|
|
|
|
assert( size < (std::numeric_limits<uint16_t>::max)() );
|
|
|
|
|
|
|
|
char* ptr = (char*)tracy_malloc( size_t( size ) + 1 );
|
|
|
|
va_start( args, fmt );
|
|
|
|
vsnprintf( ptr, size_t( size ) + 1, fmt, args );
|
|
|
|
va_end( args );
|
|
|
|
|
|
|
|
TracyQueuePrepare( QueueType::ZoneName );
|
|
|
|
MemWrite( &item->zoneTextFat.text, (uint64_t)ptr );
|
|
|
|
MemWrite( &item->zoneTextFat.size, (uint16_t)size );
|
|
|
|
TracyQueueCommit( zoneTextFatThread );
|
|
|
|
}
|
|
|
|
|
2020-11-27 11:37:35 +00:00
|
|
|
tracy_force_inline void Color( uint32_t color )
|
|
|
|
{
|
|
|
|
if( !m_active ) return;
|
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
|
|
|
#endif
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueuePrepare( QueueType::ZoneColor );
|
2023-01-23 00:18:23 +00:00
|
|
|
MemWrite( &item->zoneColor.b, uint8_t( ( color ) & 0xFF ) );
|
2020-11-27 11:37:35 +00:00
|
|
|
MemWrite( &item->zoneColor.g, uint8_t( ( color >> 8 ) & 0xFF ) );
|
2023-01-23 00:18:23 +00:00
|
|
|
MemWrite( &item->zoneColor.r, uint8_t( ( color >> 16 ) & 0xFF ) );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueueCommit( zoneColorThread );
|
2020-11-27 11:37:35 +00:00
|
|
|
}
|
|
|
|
|
2020-05-24 14:13:09 +00:00
|
|
|
tracy_force_inline void Value( uint64_t value )
|
|
|
|
{
|
|
|
|
if( !m_active ) return;
|
|
|
|
#ifdef TRACY_ON_DEMAND
|
|
|
|
if( GetProfiler().ConnectionId() != m_connectionId ) return;
|
|
|
|
#endif
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueuePrepare( QueueType::ZoneValue );
|
2020-05-24 14:13:09 +00:00
|
|
|
MemWrite( &item->zoneValue.value, value );
|
2021-10-09 12:58:33 +00:00
|
|
|
TracyQueueCommit( zoneValueThread );
|
2020-05-24 14:13:09 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 02:30:43 +00:00
|
|
|
tracy_force_inline bool IsActive() const { return m_active; }
|
|
|
|
|
2017-09-10 18:09:57 +00:00
|
|
|
private:
|
2018-07-11 10:16:55 +00:00
|
|
|
const bool m_active;
|
2019-06-09 15:15:47 +00:00
|
|
|
|
|
|
|
#ifdef TRACY_ON_DEMAND
|
2023-01-25 14:11:49 +00:00
|
|
|
uint64_t m_connectionId = 0;
|
2019-06-09 15:15:47 +00:00
|
|
|
#endif
|
2017-09-10 18:09:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|