2017-09-10 18:09:57 +00:00
|
|
|
#ifndef __TRACYSCOPED_HPP__
|
|
|
|
#define __TRACYSCOPED_HPP__
|
|
|
|
|
|
|
|
#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:
|
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() )
|
2019-06-09 15:15:47 +00:00
|
|
|
, m_connectionId( GetProfiler().ConnectionId() )
|
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-19 14:06:11 +00:00
|
|
|
TracyLfqPrepare( 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 );
|
2020-01-19 14:06:11 +00:00
|
|
|
TracyLfqCommit;
|
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() )
|
2019-06-09 15:15:47 +00:00
|
|
|
, m_connectionId( GetProfiler().ConnectionId() )
|
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-19 14:06:11 +00:00
|
|
|
TracyLfqPrepare( 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 );
|
2020-01-19 14:06:11 +00:00
|
|
|
TracyLfqCommit;
|
2018-06-21 22:56:01 +00:00
|
|
|
|
2019-07-29 22:42:31 +00:00
|
|
|
GetProfiler().SendCallstack( depth );
|
2018-06-21 22:56:01 +00:00
|
|
|
}
|
|
|
|
|
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
|
2020-01-19 14:06:11 +00:00
|
|
|
TracyLfqPrepare( QueueType::ZoneEnd );
|
2019-08-12 17:18:17 +00:00
|
|
|
MemWrite( &item->zoneEnd.time, Profiler::GetTime() );
|
2020-01-19 14:06:11 +00:00
|
|
|
TracyLfqCommit;
|
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
|
|
|
{
|
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
|
2017-10-14 15:15:18 +00:00
|
|
|
auto ptr = (char*)tracy_malloc( size+1 );
|
2017-09-27 00:18:17 +00:00
|
|
|
memcpy( ptr, txt, size );
|
|
|
|
ptr[size] = '\0';
|
2020-01-19 14:06:11 +00:00
|
|
|
TracyLfqPrepare( QueueType::ZoneText );
|
2018-03-31 12:03:55 +00:00
|
|
|
MemWrite( &item->zoneText.text, (uint64_t)ptr );
|
2020-01-19 14:06:11 +00:00
|
|
|
TracyLfqCommit;
|
2017-09-27 00:18:17 +00:00
|
|
|
}
|
|
|
|
|
2018-06-29 14:01:31 +00:00
|
|
|
tracy_force_inline void Name( const char* txt, size_t size )
|
|
|
|
{
|
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
|
2018-06-29 14:01:31 +00:00
|
|
|
auto ptr = (char*)tracy_malloc( size+1 );
|
|
|
|
memcpy( ptr, txt, size );
|
|
|
|
ptr[size] = '\0';
|
2020-01-19 14:06:11 +00:00
|
|
|
TracyLfqPrepare( QueueType::ZoneName );
|
2018-06-29 14:01:31 +00:00
|
|
|
MemWrite( &item->zoneText.text, (uint64_t)ptr );
|
2020-01-19 14:06:11 +00:00
|
|
|
TracyLfqCommit;
|
2018-06-29 14:01:31 +00:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
uint64_t m_connectionId;
|
|
|
|
#endif
|
2017-09-10 18:09:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|