tracy/client/TracyProfiler.hpp

51 lines
1019 B
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>
2017-09-10 18:09:14 +00:00
#include "concurrentqueue.h"
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
{
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-10 18:09:14 +00:00
2017-09-10 15:43:56 +00:00
private:
void Worker();
static Profiler* Instance();
static moodycamel::ProducerToken& GetToken()
{
static thread_local moodycamel::ProducerToken token( Instance()->m_queue );
return token;
}
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:09:14 +00:00
moodycamel::ConcurrentQueue<QueueItem> m_queue;
2017-09-10 18:08:42 +00:00
std::atomic<uint64_t> m_id;
2017-09-10 15:43:56 +00:00
};
};
#endif