tracy/client/TracyScoped.hpp

65 lines
1.5 KiB
C++
Raw Normal View History

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
#include "../common/TracySystem.hpp"
2017-09-10 18:09:57 +00:00
#include "TracyProfiler.hpp"
namespace tracy
{
class ScopedZone
{
public:
ScopedZone( const SourceLocation* srcloc )
: m_id( Profiler::GetNewId() )
2017-09-10 18:09:57 +00:00
{
auto item = Profiler::StartItem();
item->hdr.type = QueueType::ZoneBegin;
item->hdr.id = m_id;
2017-10-01 17:11:01 +00:00
item->zoneBegin.time = Profiler::GetTime( item->zoneBegin.cpu );
item->zoneBegin.srcloc = (uint64_t)srcloc;
item->zoneBegin.thread = GetThreadHandle();
Profiler::FinishItem();
2017-09-10 18:09:57 +00:00
}
~ScopedZone()
{
auto item = Profiler::StartItem();
item->hdr.type = QueueType::ZoneEnd;
item->hdr.id = m_id;
2017-10-01 17:11:01 +00:00
item->zoneEnd.time = Profiler::GetTime( item->zoneEnd.cpu );
Profiler::FinishItem();
2017-09-10 18:09:57 +00:00
}
2017-09-27 00:18:17 +00:00
void Text( const char* txt, size_t size )
{
auto ptr = new char[size+1];
memcpy( ptr, txt, size );
ptr[size] = '\0';
auto item = Profiler::StartItem();
item->hdr.type = QueueType::ZoneText;
item->hdr.id = m_id;
item->zoneText.text = (uint64_t)ptr;
Profiler::FinishItem();
2017-09-27 00:18:17 +00:00
}
2017-09-28 17:28:24 +00:00
void Name( const char* name )
{
auto item = Profiler::StartItem();
item->hdr.type = QueueType::ZoneName;
item->hdr.id = m_id;
item->zoneName.name = (uint64_t)name;
Profiler::FinishItem();
2017-09-28 17:28:24 +00:00
}
2017-09-10 18:09:57 +00:00
private:
uint64_t m_id;
};
}
#endif