2017-09-10 15:43:56 +00:00
|
|
|
#ifndef __TRACYPROFILER_HPP__
|
|
|
|
#define __TRACYPROFILER_HPP__
|
|
|
|
|
|
|
|
#include <atomic>
|
2017-09-13 23:07:14 +00:00
|
|
|
#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
|
|
|
|
{
|
|
|
|
|
2017-09-13 23:07:14 +00:00
|
|
|
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();
|
|
|
|
|
2017-09-13 23:07:14 +00:00
|
|
|
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();
|
|
|
|
|
2017-09-10 18:52:10 +00:00
|
|
|
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
|