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"
|
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
|
|
|
{
|
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-03 14:55:04 +00:00
|
|
|
auto& token = s_token;
|
|
|
|
auto item = s_queue.enqueue_begin( token, magic );
|
2017-10-01 15:49:45 +00:00
|
|
|
item->hdr.type = QueueType::ZoneBegin;
|
2017-10-01 17:11:01 +00:00
|
|
|
item->zoneBegin.time = Profiler::GetTime( item->zoneBegin.cpu );
|
2017-10-03 14:41:32 +00:00
|
|
|
item->zoneBegin.thread = thread;
|
2017-10-01 15:49:45 +00:00
|
|
|
item->zoneBegin.srcloc = (uint64_t)srcloc;
|
2017-10-03 14:55:04 +00:00
|
|
|
s_queue.enqueue_finish( token, magic );
|
2017-09-10 18:09:57 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 13:10:25 +00:00
|
|
|
tracy_force_inline ~ScopedZone()
|
2017-09-10 18:09:57 +00:00
|
|
|
{
|
2017-10-03 12:50:55 +00:00
|
|
|
Magic magic;
|
2017-10-03 14:55:04 +00:00
|
|
|
auto& token = s_token;
|
|
|
|
auto item = s_queue.enqueue_begin( token, magic );
|
2017-10-01 15:49:45 +00:00
|
|
|
item->hdr.type = QueueType::ZoneEnd;
|
2017-10-01 17:11:01 +00:00
|
|
|
item->zoneEnd.time = Profiler::GetTime( item->zoneEnd.cpu );
|
2017-10-03 14:41:32 +00:00
|
|
|
item->zoneEnd.thread = m_thread;
|
2017-10-03 14:55:04 +00:00
|
|
|
s_queue.enqueue_finish( token, magic );
|
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
|
|
|
{
|
2017-10-03 12:50:55 +00:00
|
|
|
Magic magic;
|
2017-09-27 00:18:17 +00:00
|
|
|
auto ptr = new char[size+1];
|
|
|
|
memcpy( ptr, txt, size );
|
|
|
|
ptr[size] = '\0';
|
2017-10-03 14:55:04 +00:00
|
|
|
auto& token = s_token;
|
|
|
|
auto item = s_queue.enqueue_begin( token, magic );
|
2017-10-01 15:49:45 +00:00
|
|
|
item->hdr.type = QueueType::ZoneText;
|
2017-10-03 14:41:32 +00:00
|
|
|
item->zoneText.thread = m_thread;
|
2017-10-01 15:49:45 +00:00
|
|
|
item->zoneText.text = (uint64_t)ptr;
|
2017-10-03 14:55:04 +00:00
|
|
|
s_queue.enqueue_finish( token, magic );
|
2017-09-27 00:18:17 +00:00
|
|
|
}
|
|
|
|
|
2017-10-03 13:10:25 +00:00
|
|
|
tracy_force_inline void Name( const char* name )
|
2017-09-28 17:28:24 +00:00
|
|
|
{
|
2017-10-03 12:50:55 +00:00
|
|
|
Magic magic;
|
2017-10-03 14:55:04 +00:00
|
|
|
auto& token = s_token;
|
|
|
|
auto item = s_queue.enqueue_begin( token, magic );
|
2017-10-01 15:49:45 +00:00
|
|
|
item->hdr.type = QueueType::ZoneName;
|
2017-10-03 14:41:32 +00:00
|
|
|
item->zoneName.thread = m_thread;
|
2017-10-01 15:49:45 +00:00
|
|
|
item->zoneName.name = (uint64_t)name;
|
2017-10-03 14:55:04 +00:00
|
|
|
s_queue.enqueue_finish( token, magic );
|
2017-09-28 17:28:24 +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
|