2017-09-12 23:33:50 +00:00
|
|
|
#ifndef __TRACYVIEW_HPP__
|
|
|
|
#define __TRACYVIEW_HPP__
|
|
|
|
|
|
|
|
#include <atomic>
|
2017-09-14 00:00:13 +00:00
|
|
|
#include <mutex>
|
2017-09-12 23:33:50 +00:00
|
|
|
#include <string>
|
|
|
|
#include <thread>
|
2017-09-14 00:00:13 +00:00
|
|
|
#include <unordered_map>
|
2017-09-14 00:16:51 +00:00
|
|
|
#include <unordered_set>
|
2017-09-14 00:00:13 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2017-09-17 11:10:42 +00:00
|
|
|
#include "../common/tracy_lz4.hpp"
|
2017-09-14 00:15:04 +00:00
|
|
|
#include "../common/TracySocket.hpp"
|
2017-09-14 00:00:13 +00:00
|
|
|
#include "../common/TracyQueue.hpp"
|
2017-09-27 00:36:14 +00:00
|
|
|
#include "TracyCharUtil.hpp"
|
2017-09-14 00:00:13 +00:00
|
|
|
#include "TracyEvent.hpp"
|
2017-09-15 17:56:55 +00:00
|
|
|
#include "TracySlab.hpp"
|
2017-09-15 18:17:39 +00:00
|
|
|
#include "TracyVector.hpp"
|
2017-09-12 23:33:50 +00:00
|
|
|
|
2017-09-23 22:07:06 +00:00
|
|
|
struct ImVec2;
|
|
|
|
|
2017-09-12 23:33:50 +00:00
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
|
2017-09-13 21:40:28 +00:00
|
|
|
struct QueueItem;
|
2017-09-30 14:58:02 +00:00
|
|
|
class FileRead;
|
2017-09-30 14:20:08 +00:00
|
|
|
class FileWrite;
|
2017-09-13 21:40:28 +00:00
|
|
|
|
2017-09-12 23:33:50 +00:00
|
|
|
class View
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
View() : View( "127.0.0.1" ) {}
|
|
|
|
View( const char* addr );
|
2017-09-30 14:58:02 +00:00
|
|
|
View( FileRead& f );
|
2017-09-12 23:33:50 +00:00
|
|
|
~View();
|
|
|
|
|
2017-09-13 00:08:35 +00:00
|
|
|
static bool ShouldExit();
|
2017-09-15 00:30:22 +00:00
|
|
|
static void Draw();
|
2017-09-13 00:08:35 +00:00
|
|
|
|
2017-09-12 23:33:50 +00:00
|
|
|
private:
|
2017-10-14 12:46:03 +00:00
|
|
|
struct MessagePending
|
|
|
|
{
|
|
|
|
int64_t time;
|
|
|
|
uint64_t thread;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MessageData
|
|
|
|
{
|
|
|
|
int64_t time;
|
|
|
|
const char* txt;
|
|
|
|
};
|
|
|
|
|
2017-09-21 23:15:58 +00:00
|
|
|
struct ThreadData
|
|
|
|
{
|
2017-09-21 23:58:59 +00:00
|
|
|
uint64_t id;
|
2017-10-12 17:47:56 +00:00
|
|
|
bool enabled;
|
2017-09-21 23:15:58 +00:00
|
|
|
Vector<Event*> timeline;
|
2017-10-14 12:46:03 +00:00
|
|
|
Vector<MessageData*> messages;
|
2017-09-21 23:15:58 +00:00
|
|
|
};
|
|
|
|
|
2017-10-04 16:17:31 +00:00
|
|
|
struct LockMap
|
|
|
|
{
|
|
|
|
uint64_t srcloc;
|
2017-10-04 16:51:50 +00:00
|
|
|
Vector<LockEvent*> timeline;
|
2017-10-08 21:03:38 +00:00
|
|
|
std::unordered_map<uint64_t, uint8_t> threadMap;
|
|
|
|
std::vector<uint64_t> threadList;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LockHighlight
|
|
|
|
{
|
|
|
|
int64_t id;
|
|
|
|
uint64_t begin;
|
|
|
|
uint64_t end;
|
|
|
|
uint8_t thread;
|
|
|
|
bool blocked;
|
2017-10-04 16:17:31 +00:00
|
|
|
};
|
|
|
|
|
2017-10-13 01:36:59 +00:00
|
|
|
struct PlotItem
|
|
|
|
{
|
|
|
|
int64_t time;
|
|
|
|
double val;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct PlotData
|
|
|
|
{
|
|
|
|
uint64_t name;
|
2017-10-13 13:32:59 +00:00
|
|
|
double min;
|
|
|
|
double max;
|
2017-10-13 13:41:20 +00:00
|
|
|
bool enabled;
|
2017-10-13 01:36:59 +00:00
|
|
|
std::vector<PlotItem> data;
|
|
|
|
};
|
|
|
|
|
2017-09-12 23:33:50 +00:00
|
|
|
void Worker();
|
|
|
|
|
2017-09-14 17:44:49 +00:00
|
|
|
void DispatchProcess( const QueueItem& ev );
|
|
|
|
void DispatchProcess( const QueueItem& ev, const char*& ptr );
|
|
|
|
|
2017-09-27 00:44:16 +00:00
|
|
|
void ServerQuery( uint8_t type, uint64_t data );
|
|
|
|
|
2017-09-14 17:44:49 +00:00
|
|
|
void Process( const QueueItem& ev );
|
2017-10-03 14:41:32 +00:00
|
|
|
void ProcessZoneBegin( const QueueZoneBegin& ev );
|
|
|
|
void ProcessZoneEnd( const QueueZoneEnd& ev );
|
|
|
|
void ProcessFrameMark( const QueueFrameMark& ev );
|
|
|
|
void ProcessZoneText( const QueueZoneText& ev );
|
|
|
|
void ProcessZoneName( const QueueZoneName& ev );
|
2017-10-04 16:32:22 +00:00
|
|
|
void ProcessLockWait( const QueueLockWait& ev );
|
|
|
|
void ProcessLockObtain( const QueueLockObtain& ev );
|
|
|
|
void ProcessLockRelease( const QueueLockRelease& ev );
|
2017-10-06 15:05:14 +00:00
|
|
|
void ProcessLockMark( const QueueLockMark& ev );
|
2017-10-13 01:36:59 +00:00
|
|
|
void ProcessPlotData( const QueuePlotData& ev );
|
2017-10-14 12:28:04 +00:00
|
|
|
void ProcessMessage( const QueueMessage& ev );
|
2017-09-14 00:00:13 +00:00
|
|
|
|
2017-09-14 00:16:51 +00:00
|
|
|
void CheckString( uint64_t ptr );
|
2017-09-21 23:30:57 +00:00
|
|
|
void CheckThreadString( uint64_t id );
|
2017-09-27 00:18:17 +00:00
|
|
|
void CheckCustomString( uint64_t ptr, Event* dst );
|
2017-09-26 00:28:14 +00:00
|
|
|
void CheckSourceLocation( uint64_t ptr );
|
|
|
|
|
2017-09-14 17:43:40 +00:00
|
|
|
void AddString( uint64_t ptr, std::string&& str );
|
2017-09-21 23:30:57 +00:00
|
|
|
void AddThreadString( uint64_t id, std::string&& str );
|
2017-09-27 00:18:17 +00:00
|
|
|
void AddCustomString( uint64_t ptr, std::string&& str );
|
2017-10-03 14:41:32 +00:00
|
|
|
void AddSourceLocation( const QueueSourceLocation& srcloc );
|
2017-10-14 12:28:04 +00:00
|
|
|
void AddMessageData( uint64_t ptr, const char* str, size_t sz );
|
2017-09-14 00:16:51 +00:00
|
|
|
|
2017-09-21 23:15:58 +00:00
|
|
|
void NewZone( Event* zone, uint64_t thread );
|
2017-09-15 17:56:55 +00:00
|
|
|
void UpdateZone( Event* zone );
|
2017-09-14 19:05:01 +00:00
|
|
|
|
2017-09-23 21:59:56 +00:00
|
|
|
void InsertZone( Event* zone, Event* parent, Vector<Event*>& vec );
|
|
|
|
|
2017-10-08 21:03:38 +00:00
|
|
|
void InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread );
|
|
|
|
void UpdateLockCount( LockMap& lockmap, size_t pos );
|
2017-10-04 16:51:50 +00:00
|
|
|
|
2017-10-13 01:36:59 +00:00
|
|
|
void InsertPlot( PlotData* plot, int64_t time, double val );
|
|
|
|
void HandlePlotName( uint64_t name, std::string&& str );
|
|
|
|
|
2017-09-18 19:26:22 +00:00
|
|
|
uint64_t GetFrameTime( size_t idx ) const;
|
2017-09-20 20:34:56 +00:00
|
|
|
uint64_t GetFrameBegin( size_t idx ) const;
|
|
|
|
uint64_t GetFrameEnd( size_t idx ) const;
|
2017-10-06 16:32:25 +00:00
|
|
|
int64_t GetLastTime() const;
|
2017-09-24 14:40:16 +00:00
|
|
|
int64_t GetZoneEnd( const Event& ev ) const;
|
2017-09-24 01:23:01 +00:00
|
|
|
Vector<Event*>& GetParentVector( const Event& ev );
|
2017-09-24 14:45:08 +00:00
|
|
|
const char* TimeToString( int64_t ns ) const;
|
2017-09-21 00:10:20 +00:00
|
|
|
const char* GetString( uint64_t ptr ) const;
|
2017-09-21 23:30:57 +00:00
|
|
|
const char* GetThreadString( uint64_t id ) const;
|
2017-09-26 16:54:48 +00:00
|
|
|
const QueueSourceLocation& GetSourceLocation( uint64_t srcloc ) const;
|
2017-09-18 00:22:59 +00:00
|
|
|
|
2017-09-15 00:30:22 +00:00
|
|
|
void DrawImpl();
|
2017-09-30 12:37:21 +00:00
|
|
|
void DrawConnection();
|
2017-09-18 00:37:25 +00:00
|
|
|
void DrawFrames();
|
2017-10-13 13:26:18 +00:00
|
|
|
bool DrawZoneFrames();
|
2017-09-20 22:57:26 +00:00
|
|
|
void DrawZones();
|
2017-09-23 22:12:26 +00:00
|
|
|
int DrawZoneLevel( const Vector<Event*>& vec, bool hover, double pxns, const ImVec2& wpos, int offset, int depth );
|
2017-10-08 21:03:38 +00:00
|
|
|
int DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, int offset, LockHighlight& highlight );
|
2017-09-29 19:49:14 +00:00
|
|
|
void DrawZoneInfoWindow();
|
2017-10-13 13:15:57 +00:00
|
|
|
int DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover );
|
|
|
|
void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, double val, double prev );
|
2017-10-13 11:32:23 +00:00
|
|
|
void DrawOptions();
|
2017-10-14 12:36:30 +00:00
|
|
|
void DrawMessages();
|
2017-09-15 00:30:22 +00:00
|
|
|
|
2017-10-12 20:27:17 +00:00
|
|
|
void HandleZoneViewMouse( int64_t timespan, const ImVec2& wpos, float w, double& pxns );
|
|
|
|
|
2017-10-01 17:31:22 +00:00
|
|
|
uint32_t GetZoneColor( const Event& ev );
|
|
|
|
uint32_t GetZoneColor( const QueueSourceLocation& srcloc );
|
2017-10-01 17:58:53 +00:00
|
|
|
uint32_t GetZoneHighlight( const Event& ev, bool migration );
|
2017-09-30 11:45:02 +00:00
|
|
|
float GetZoneThickness( const Event& ev );
|
2017-10-01 17:31:22 +00:00
|
|
|
|
2017-09-29 20:01:30 +00:00
|
|
|
void ZoomToZone( const Event& ev );
|
2017-09-29 20:55:24 +00:00
|
|
|
void ZoneTooltip( const Event& ev );
|
2017-09-29 19:57:00 +00:00
|
|
|
|
2017-09-30 14:20:08 +00:00
|
|
|
void Write( FileWrite& f );
|
|
|
|
void WriteTimeline( FileWrite& f, const Vector<Event*>& vec );
|
2017-09-30 15:09:00 +00:00
|
|
|
void ReadTimeline( FileRead& f, Vector<Event*>& vec, Event* parent, const std::unordered_map<uint64_t, const char*>& stringMap );
|
2017-09-30 14:20:08 +00:00
|
|
|
|
2017-09-12 23:33:50 +00:00
|
|
|
std::string m_addr;
|
|
|
|
|
2017-09-14 00:15:04 +00:00
|
|
|
Socket m_sock;
|
2017-09-12 23:33:50 +00:00
|
|
|
std::thread m_thread;
|
|
|
|
std::atomic<bool> m_shutdown;
|
2017-09-17 22:31:09 +00:00
|
|
|
std::atomic<bool> m_connected;
|
2017-09-20 18:38:12 +00:00
|
|
|
std::atomic<bool> m_hasData;
|
2017-09-30 14:58:02 +00:00
|
|
|
bool m_staticView;
|
2017-09-12 23:54:22 +00:00
|
|
|
|
2017-09-14 17:43:40 +00:00
|
|
|
// this block must be locked
|
2017-09-14 00:00:13 +00:00
|
|
|
std::mutex m_lock;
|
2017-09-15 22:40:51 +00:00
|
|
|
Vector<uint64_t> m_frames;
|
2017-09-28 19:05:51 +00:00
|
|
|
Vector<ThreadData*> m_threads;
|
2017-10-13 01:36:59 +00:00
|
|
|
Vector<PlotData*> m_plots;
|
2017-10-14 12:28:04 +00:00
|
|
|
Vector<MessageData*> m_messages;
|
2017-09-14 00:16:51 +00:00
|
|
|
std::unordered_map<uint64_t, std::string> m_strings;
|
2017-09-21 23:30:57 +00:00
|
|
|
std::unordered_map<uint64_t, std::string> m_threadNames;
|
2017-09-27 00:36:14 +00:00
|
|
|
std::unordered_set<const char*, charutil::Hasher, charutil::Comparator> m_customStrings;
|
2017-09-26 00:28:14 +00:00
|
|
|
std::unordered_map<uint64_t, QueueSourceLocation> m_sourceLocation;
|
2017-10-13 18:05:38 +00:00
|
|
|
std::unordered_map<uint32_t, LockMap> m_lockMap;
|
2017-09-25 21:38:49 +00:00
|
|
|
uint64_t m_zonesCnt;
|
2017-09-14 00:00:13 +00:00
|
|
|
|
2017-09-15 18:31:59 +00:00
|
|
|
std::mutex m_mbpslock;
|
|
|
|
std::vector<float> m_mbps;
|
|
|
|
|
2017-09-14 00:00:13 +00:00
|
|
|
// not used for vis - no need to lock
|
2017-10-03 14:41:32 +00:00
|
|
|
std::unordered_map<uint64_t, std::vector<Event*>> m_zoneStack;
|
2017-09-14 00:16:51 +00:00
|
|
|
std::unordered_set<uint64_t> m_pendingStrings;
|
2017-09-21 23:30:57 +00:00
|
|
|
std::unordered_set<uint64_t> m_pendingThreads;
|
2017-09-26 00:28:14 +00:00
|
|
|
std::unordered_set<uint64_t> m_pendingSourceLocation;
|
2017-09-27 00:18:17 +00:00
|
|
|
std::unordered_map<uint64_t, Event*> m_pendingCustomStrings;
|
2017-09-21 23:15:58 +00:00
|
|
|
std::unordered_map<uint64_t, uint32_t> m_threadMap;
|
2017-10-13 01:36:59 +00:00
|
|
|
std::unordered_map<uint64_t, uint32_t> m_plotMap;
|
|
|
|
std::unordered_map<std::string, uint32_t> m_plotRev;
|
|
|
|
std::unordered_map<uint64_t, PlotData*> m_pendingPlots;
|
2017-10-14 12:28:04 +00:00
|
|
|
std::unordered_map<uint64_t, MessagePending> m_pendingMessages;
|
2017-09-15 17:56:55 +00:00
|
|
|
|
|
|
|
Slab<EventSize*1024*1024> m_slab;
|
2017-09-17 11:10:42 +00:00
|
|
|
|
|
|
|
LZ4_streamDecode_t* m_stream;
|
|
|
|
char* m_buffer;
|
|
|
|
int m_bufferOffset;
|
2017-09-18 00:37:25 +00:00
|
|
|
|
|
|
|
int m_frameScale;
|
2017-09-18 22:26:40 +00:00
|
|
|
bool m_pause;
|
|
|
|
int m_frameStart;
|
2017-09-20 19:21:21 +00:00
|
|
|
|
2017-09-20 23:13:23 +00:00
|
|
|
int64_t m_zvStart;
|
|
|
|
int64_t m_zvEnd;
|
2017-09-24 14:10:28 +00:00
|
|
|
|
2017-09-26 19:49:50 +00:00
|
|
|
int64_t m_zvStartNext;
|
|
|
|
int64_t m_zvEndNext;
|
|
|
|
|
2017-09-24 14:10:28 +00:00
|
|
|
uint64_t m_delay;
|
2017-09-29 16:32:07 +00:00
|
|
|
uint64_t m_resolution;
|
2017-09-25 22:13:24 +00:00
|
|
|
double m_timerMul;
|
2017-10-03 21:26:41 +00:00
|
|
|
std::string m_captureName;
|
2017-09-29 19:49:14 +00:00
|
|
|
|
2017-10-01 17:58:53 +00:00
|
|
|
int8_t m_lastCpu;
|
|
|
|
|
2017-10-12 20:27:17 +00:00
|
|
|
uint64_t m_zvHeight;
|
|
|
|
uint64_t m_zvScroll;
|
|
|
|
|
2017-09-29 19:49:14 +00:00
|
|
|
const Event* m_zoneInfoWindow;
|
2017-09-29 20:38:38 +00:00
|
|
|
const Event* m_zoneHighlight;
|
2017-10-08 21:03:38 +00:00
|
|
|
LockHighlight m_lockHighlight;
|
2017-10-13 11:32:23 +00:00
|
|
|
|
|
|
|
bool m_showOptions;
|
2017-10-14 12:36:30 +00:00
|
|
|
bool m_showMessages;
|
2017-10-13 11:32:23 +00:00
|
|
|
bool m_drawZones;
|
|
|
|
bool m_drawLocks;
|
2017-10-13 12:54:32 +00:00
|
|
|
bool m_drawPlots;
|
2017-09-12 23:33:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|