1
0
mirror of https://github.com/wolfpld/tracy synced 2025-05-03 06:03:51 +00:00
tracy/client/TracyProfiler.hpp
Bartosz Taudul 7424077d70 Store source location in a single object.
Source file, function name and line number are now stored in a const
static container object. This has the following benefits:
- Slightly lighter profiling workload (3 instructions less).
- Profiling queue event size is significantly reduced, by 12 bytes. This
  has an effect on all queue event types.
- Source location grouping has now no cost, as it's performed at the
  compilation stage. This allows simplification of server code.
The downside is that the full source location resolution is now
performed in two steps, as the server has to query both source location
container and strings contained within. This has almost no real impact
on profiler operation.
2017-09-26 02:39:08 +02:00

80 lines
1.5 KiB
C++
Executable File

#ifndef __TRACYPROFILER_HPP__
#define __TRACYPROFILER_HPP__
#include <atomic>
#include <chrono>
#include <stdint.h>
#include <thread>
#include "../common/tracy_lz4.hpp"
#include "../common/TracyQueue.hpp"
#if defined _MSC_VER || defined __CYGWIN__
# include <intrin.h>
#endif
namespace tracy
{
class Socket;
struct SourceLocation
{
const char* function;
const char* file;
uint32_t line;
};
class Profiler
{
public:
Profiler();
~Profiler();
static uint64_t GetNewId();
static int64_t GetTime()
{
#if defined _MSC_VER || defined __CYGWIN__
unsigned int ui;
return int64_t( __rdtscp( &ui ) );
#else
return std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
#endif
}
static uint64_t ZoneBegin( QueueZoneBegin&& data );
static void ZoneEnd( uint64_t id, QueueZoneEnd&& data );
static void FrameMark();
static bool ShouldExit();
private:
void Worker();
bool SendData( const char* data, size_t len );
bool SendString( uint64_t ptr, const char* str, QueueType type );
bool SendSourceLocation( uint64_t ptr );
bool HandleServerQuery();
void CalibrateTimer();
void CalibrateDelay();
double m_timerMul;
uint64_t m_delay;
int64_t m_timeBegin;
uint64_t m_mainThread;
std::thread m_thread;
std::atomic<bool> m_shutdown;
std::atomic<uint64_t> m_id;
std::unique_ptr<Socket> m_sock;
LZ4_stream_t* m_stream;
char* m_buffer;
int m_bufferOffset;
};
};
#endif