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:
|
2017-10-03 13:10:25 +00:00
|
|
|
tracy_force_inline ScopedZone( const SourceLocation* srcloc )
|
2017-09-10 18:09:57 +00:00
|
|
|
{
|
2018-07-10 18:42:30 +00:00
|
|
|
#ifndef TRACY_ON_DEMAND
|
2017-10-03 14:41:32 +00:00
|
|
|
const auto thread = GetThreadHandle();
|
|
|
|
m_thread = thread;
|
2017-10-03 12:50:55 +00:00
|
|
|
Magic magic;
|
2017-10-10 23:44:35 +00:00
|
|
|
auto& token = s_token.ptr;
|
2017-10-10 23:27:22 +00:00
|
|
|
auto& tail = token->get_tail_index();
|
2017-10-10 23:04:21 +00:00
|
|
|
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
2018-03-31 12:03:55 +00:00
|
|
|
MemWrite( &item->hdr.type, QueueType::ZoneBegin );
|
2018-04-27 17:40:47 +00:00
|
|
|
#ifdef TRACY_RDTSCP_OPT
|
2018-03-31 12:03:55 +00:00
|
|
|
MemWrite( &item->zoneBegin.time, Profiler::GetTime( item->zoneBegin.cpu ) );
|
|
|
|
#else
|
|
|
|
uint32_t cpu;
|
|
|
|
MemWrite( &item->zoneBegin.time, Profiler::GetTime( cpu ) );
|
|
|
|
MemWrite( &item->zoneBegin.cpu, cpu );
|
|
|
|
#endif
|
|
|
|
MemWrite( &item->zoneBegin.thread, thread );
|
|
|
|
MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
|
2017-10-10 23:27:22 +00:00
|
|
|
tail.store( magic + 1, std::memory_order_release );
|
2018-07-10 18:42:30 +00:00
|
|
|
#endif
|
2017-09-10 18:09:57 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 22:56:01 +00:00
|
|
|
tracy_force_inline ScopedZone( const SourceLocation* srcloc, int depth )
|
|
|
|
{
|
2018-07-10 18:42:30 +00:00
|
|
|
#ifndef TRACY_ON_DEMAND
|
2018-06-21 22:56:01 +00:00
|
|
|
const auto thread = GetThreadHandle();
|
|
|
|
m_thread = thread;
|
|
|
|
Magic magic;
|
|
|
|
auto& token = s_token.ptr;
|
|
|
|
auto& tail = token->get_tail_index();
|
|
|
|
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
|
|
|
MemWrite( &item->hdr.type, QueueType::ZoneBeginCallstack );
|
|
|
|
#ifdef TRACY_RDTSCP_OPT
|
|
|
|
MemWrite( &item->zoneBegin.time, Profiler::GetTime( item->zoneBegin.cpu ) );
|
|
|
|
#else
|
|
|
|
uint32_t cpu;
|
|
|
|
MemWrite( &item->zoneBegin.time, Profiler::GetTime( cpu ) );
|
|
|
|
MemWrite( &item->zoneBegin.cpu, cpu );
|
|
|
|
#endif
|
|
|
|
MemWrite( &item->zoneBegin.thread, thread );
|
|
|
|
MemWrite( &item->zoneBegin.srcloc, (uint64_t)srcloc );
|
|
|
|
tail.store( magic + 1, std::memory_order_release );
|
|
|
|
|
|
|
|
s_profiler.SendCallstack( depth, thread );
|
2018-07-10 18:42:30 +00:00
|
|
|
#endif
|
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 18:42:30 +00:00
|
|
|
#ifndef TRACY_ON_DEMAND
|
2017-10-03 12:50:55 +00:00
|
|
|
Magic magic;
|
2017-10-10 23:44:35 +00:00
|
|
|
auto& token = s_token.ptr;
|
2017-10-10 23:27:22 +00:00
|
|
|
auto& tail = token->get_tail_index();
|
2017-10-10 23:04:21 +00:00
|
|
|
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
2018-03-31 12:03:55 +00:00
|
|
|
MemWrite( &item->hdr.type, QueueType::ZoneEnd );
|
2018-04-27 17:40:47 +00:00
|
|
|
#ifdef TRACY_RDTSCP_OPT
|
2018-03-31 12:03:55 +00:00
|
|
|
MemWrite( &item->zoneEnd.time, Profiler::GetTime( item->zoneEnd.cpu ) );
|
|
|
|
#else
|
|
|
|
uint32_t cpu;
|
|
|
|
MemWrite( &item->zoneEnd.time, Profiler::GetTime( cpu ) );
|
2018-06-20 20:27:46 +00:00
|
|
|
MemWrite( &item->zoneEnd.cpu, cpu );
|
2018-03-31 12:03:55 +00:00
|
|
|
#endif
|
|
|
|
MemWrite( &item->zoneEnd.thread, m_thread );
|
2017-10-10 23:27:22 +00:00
|
|
|
tail.store( magic + 1, std::memory_order_release );
|
2018-07-10 18:42:30 +00:00
|
|
|
#endif
|
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 18:42:30 +00:00
|
|
|
#ifndef TRACY_ON_DEMAND
|
2017-10-03 12:50:55 +00:00
|
|
|
Magic magic;
|
2017-10-20 16:28:25 +00:00
|
|
|
auto& token = s_token.ptr;
|
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';
|
2017-10-10 23:27:22 +00:00
|
|
|
auto& tail = token->get_tail_index();
|
2017-10-10 23:04:21 +00:00
|
|
|
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
2018-03-31 12:03:55 +00:00
|
|
|
MemWrite( &item->hdr.type, QueueType::ZoneText );
|
|
|
|
MemWrite( &item->zoneText.thread, m_thread );
|
|
|
|
MemWrite( &item->zoneText.text, (uint64_t)ptr );
|
2017-10-10 23:27:22 +00:00
|
|
|
tail.store( magic + 1, std::memory_order_release );
|
2018-07-10 18:42:30 +00:00
|
|
|
#endif
|
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 18:42:30 +00:00
|
|
|
#ifndef TRACY_ON_DEMAND
|
2018-06-29 14:01:31 +00:00
|
|
|
Magic magic;
|
|
|
|
auto& token = s_token.ptr;
|
|
|
|
auto ptr = (char*)tracy_malloc( size+1 );
|
|
|
|
memcpy( ptr, txt, size );
|
|
|
|
ptr[size] = '\0';
|
|
|
|
auto& tail = token->get_tail_index();
|
|
|
|
auto item = token->enqueue_begin<moodycamel::CanAlloc>( magic );
|
|
|
|
MemWrite( &item->hdr.type, QueueType::ZoneName );
|
|
|
|
MemWrite( &item->zoneText.thread, m_thread );
|
|
|
|
MemWrite( &item->zoneText.text, (uint64_t)ptr );
|
|
|
|
tail.store( magic + 1, std::memory_order_release );
|
2018-07-10 18:42:30 +00:00
|
|
|
#endif
|
2018-06-29 14:01:31 +00:00
|
|
|
}
|
|
|
|
|
2017-09-10 18:09:57 +00:00
|
|
|
private:
|
2017-10-03 14:41:32 +00:00
|
|
|
uint64_t m_thread;
|
2017-09-10 18:09:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|