tracy/client/TracyProfiler.hpp

58 lines
1.1 KiB
C++
Raw Normal View History

2017-09-10 15:43:56 +00:00
#ifndef __TRACYPROFILER_HPP__
#define __TRACYPROFILER_HPP__
#include <atomic>
#include <chrono>
2017-09-10 18:08:42 +00:00
#include <stdint.h>
2017-09-10 15:43:56 +00:00
#include <thread>
#include "../common/tracy_lz4.hpp"
2017-09-13 20:56:08 +00:00
#include "../common/TracyQueue.hpp"
2017-09-10 18:09:14 +00:00
2017-09-10 15:43:56 +00:00
namespace tracy
{
class Socket;
static inline int64_t GetTime()
{
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
}
2017-09-10 15:43:56 +00:00
class Profiler
{
public:
Profiler();
~Profiler();
2017-09-10 18:08:42 +00:00
static uint64_t GetNewId();
static uint64_t ZoneBegin( QueueZoneBegin&& data );
static void ZoneEnd( uint64_t id, QueueZoneEnd&& data );
2017-09-15 22:30:27 +00:00
static void FrameMark();
2017-09-10 18:09:14 +00:00
static bool ShouldExit();
2017-09-10 15:43:56 +00:00
private:
void Worker();
bool SendData( const char* data, size_t len );
bool SendString( uint64_t ptr, const char* str, QueueType type );
bool HandleServerQuery();
2017-09-10 18:14:16 +00:00
int64_t m_timeBegin;
2017-09-10 15:43:56 +00:00
std::thread m_thread;
std::atomic<bool> m_shutdown;
2017-09-10 18:08:42 +00:00
std::atomic<uint64_t> m_id;
std::unique_ptr<Socket> m_sock;
LZ4_stream_t* m_stream;
char* m_buffer;
int m_bufferOffset;
2017-09-10 15:43:56 +00:00
};
};
#endif