tracy/server/TracyView.hpp

300 lines
10 KiB
C++
Raw Normal View History

2017-09-12 23:33:50 +00:00
#ifndef __TRACYVIEW_HPP__
#define __TRACYVIEW_HPP__
#include <atomic>
#include <map>
2017-09-12 23:33:50 +00:00
#include <string>
#include <thread>
2017-09-14 00:00:13 +00:00
#include <unordered_map>
#include <vector>
#include "../common/tracy_lz4.hpp"
#include "../common/TracySocket.hpp"
2017-09-14 00:00:13 +00:00
#include "../common/TracyQueue.hpp"
#include "TracyCharUtil.hpp"
2017-09-14 00:00:13 +00:00
#include "TracyEvent.hpp"
#include "TracySlab.hpp"
2017-09-15 18:17:39 +00:00
#include "TracyVector.hpp"
2017-11-15 20:49:41 +00:00
#include "tracy_benaphore.h"
2017-11-15 22:15:59 +00:00
#include "tracy_flat_hash_map.hpp"
2017-09-12 23:33:50 +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
{
2017-11-21 23:23:43 +00:00
template<typename T>
struct nohash
{
size_t operator()( const T& v ) { return (size_t)v; }
typedef tracy::power_of_two_hash_policy hash_policy;
};
2017-11-27 21:41:30 +00:00
struct Animation
{
bool active = false;
int64_t start0, start1;
int64_t end0, end1;
double progress;
double lenMod;
};
2017-09-12 23:33:50 +00:00
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();
static bool ShouldExit();
2017-09-15 00:30:22 +00:00
static void Draw();
2017-09-12 23:33:50 +00:00
private:
2017-10-22 11:56:05 +00:00
enum class Namespace : uint8_t
{
Full,
Mid,
Short
};
2017-09-12 23:33:50 +00:00
void Worker();
tracy_force_inline void DispatchProcess( const QueueItem& ev, char*& ptr );
2017-09-14 17:44:49 +00:00
void ServerQuery( uint8_t type, uint64_t data );
tracy_force_inline void Process( const QueueItem& ev );
tracy_force_inline void ProcessZoneBegin( const QueueZoneBegin& ev );
tracy_force_inline void ProcessZoneBeginAllocSrcLoc( const QueueZoneBegin& ev );
tracy_force_inline void ProcessZoneEnd( const QueueZoneEnd& ev );
tracy_force_inline void ProcessFrameMark( const QueueFrameMark& ev );
tracy_force_inline void ProcessZoneText( const QueueZoneText& ev );
2017-12-10 20:37:39 +00:00
tracy_force_inline void ProcessLockAnnounce( const QueueLockAnnounce& ev );
tracy_force_inline void ProcessLockWait( const QueueLockWait& ev );
tracy_force_inline void ProcessLockObtain( const QueueLockObtain& ev );
tracy_force_inline void ProcessLockRelease( const QueueLockRelease& ev );
tracy_force_inline void ProcessLockSharedWait( const QueueLockWait& ev );
tracy_force_inline void ProcessLockSharedObtain( const QueueLockObtain& ev );
tracy_force_inline void ProcessLockSharedRelease( const QueueLockRelease& ev );
tracy_force_inline void ProcessLockMark( const QueueLockMark& ev );
tracy_force_inline void ProcessPlotData( const QueuePlotData& ev );
tracy_force_inline void ProcessMessage( const QueueMessage& ev );
tracy_force_inline void ProcessMessageLiteral( const QueueMessage& ev );
tracy_force_inline void ProcessGpuNewContext( const QueueGpuNewContext& ev );
tracy_force_inline void ProcessGpuZoneBegin( const QueueGpuZoneBegin& ev );
tracy_force_inline void ProcessGpuZoneEnd( const QueueGpuZoneEnd& ev );
tracy_force_inline void ProcessGpuTime( const QueueGpuTime& ev );
tracy_force_inline void ProcessGpuResync( const QueueGpuResync& 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-11-24 00:05:42 +00:00
tracy_force_inline void CheckSourceLocation( uint64_t ptr );
void NewSourceLocation( uint64_t ptr );
void AddString( uint64_t ptr, char* str, size_t sz );
void AddThreadString( uint64_t id, char* str, size_t sz );
2017-11-10 18:15:00 +00:00
void AddCustomString( uint64_t ptr, char* str, size_t sz );
2017-10-03 14:41:32 +00:00
void AddSourceLocation( const QueueSourceLocation& srcloc );
void AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz );
2017-09-14 00:16:51 +00:00
2017-11-10 18:15:00 +00:00
StringLocation StoreString( char* str, size_t sz );
2017-11-19 18:23:07 +00:00
tracy_force_inline uint32_t ShrinkSourceLocation( uint64_t srcloc );
uint32_t NewShrinkedSourceLocation( uint64_t srcloc );
2017-10-21 10:39:26 +00:00
void InsertMessageData( MessageData* msg, uint64_t thread );
2017-11-19 18:23:07 +00:00
tracy_force_inline ThreadData* NoticeThread( uint64_t thread );
ThreadData* NewThread( uint64_t thread );
2017-10-21 11:14:20 +00:00
2017-11-19 18:39:25 +00:00
tracy_force_inline void NewZone( ZoneEvent* zone, uint64_t thread );
2017-10-08 21:03:38 +00:00
void InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread );
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 );
2017-11-10 18:41:37 +00:00
void HandlePlotName( uint64_t name, char* str, size_t sz );
2017-10-19 21:26:21 +00:00
void HandlePostponedPlots();
2017-10-13 01:36:59 +00:00
2017-10-28 19:50:06 +00:00
int64_t GetFrameTime( size_t idx ) const;
int64_t GetFrameBegin( size_t idx ) const;
int64_t GetFrameEnd( size_t idx ) const;
2017-10-22 13:37:24 +00:00
int64_t GetZoneEnd( const ZoneEvent& ev ) const;
2017-11-11 21:56:05 +00:00
int64_t GetZoneEnd( const GpuEvent& ev ) const;
2017-09-21 00:10:20 +00:00
const char* GetString( uint64_t ptr ) const;
const char* GetString( const StringRef& ref ) const;
const char* GetString( const StringIdx& idx ) const;
2017-09-21 23:30:57 +00:00
const char* GetThreadString( uint64_t id ) const;
const SourceLocation& GetSourceLocation( int32_t srcloc ) const;
2017-10-22 11:56:05 +00:00
const char* ShortenNamespace( const char* name ) const;
void DrawHelpMarker( const char* desc ) const;
void DrawTextContrast( ImDrawList* draw, const ImVec2& pos, uint32_t color, const char* text );
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();
bool DrawZoneFrames();
2017-09-20 22:57:26 +00:00
void DrawZones();
2017-10-22 13:37:24 +00:00
int DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, const ImVec2& wpos, int offset, int depth );
2017-11-13 23:48:26 +00:00
int DrawGpuZoneLevel( const Vector<GpuEvent*>& vec, bool hover, double pxns, const ImVec2& wpos, int offset, int depth, uint64_t thread );
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-10-13 13:15:57 +00:00
int DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover );
2017-10-18 20:29:59 +00:00
void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, double val, double prev, bool merged );
2017-10-13 11:32:23 +00:00
void DrawOptions();
2017-10-14 12:36:30 +00:00
void DrawMessages();
void DrawFindZone();
2017-09-15 00:30:22 +00:00
2017-11-12 00:25:44 +00:00
void DrawInfoWindow();
void DrawZoneInfoWindow();
void DrawGpuInfoWindow();
2017-10-12 20:27:17 +00:00
void HandleZoneViewMouse( int64_t timespan, const ImVec2& wpos, float w, double& pxns );
2017-10-22 13:37:24 +00:00
uint32_t GetZoneColor( const ZoneEvent& ev );
2017-11-11 21:56:05 +00:00
uint32_t GetZoneColor( const GpuEvent& ev );
2017-10-22 13:37:24 +00:00
uint32_t GetZoneHighlight( const ZoneEvent& ev, bool migration );
2017-11-11 21:56:05 +00:00
uint32_t GetZoneHighlight( const GpuEvent& ev );
2017-10-22 13:37:24 +00:00
float GetZoneThickness( const ZoneEvent& ev );
2017-11-11 21:56:05 +00:00
float GetZoneThickness( const GpuEvent& ev );
2017-10-01 17:31:22 +00:00
2017-10-22 13:37:24 +00:00
void ZoomToZone( const ZoneEvent& ev );
2017-11-11 21:56:05 +00:00
void ZoomToZone( const GpuEvent& ev );
void ZoomToRange( int64_t start, int64_t end );
2017-10-22 13:37:24 +00:00
void ZoneTooltip( const ZoneEvent& ev );
2017-11-11 21:56:05 +00:00
void ZoneTooltip( const GpuEvent& ev );
2017-10-22 14:15:27 +00:00
const ZoneEvent* GetZoneParent( const ZoneEvent& zone ) const;
2017-11-12 00:25:44 +00:00
const GpuEvent* GetZoneParent( const GpuEvent& zone ) const;
2017-09-29 19:57:00 +00:00
void FindZones();
void FindZones( const Vector<ZoneEvent*> &events, Vector<ZoneEvent*> &out, const int maxdepth = 0 );
2017-09-30 14:20:08 +00:00
void Write( FileWrite& f );
2017-10-22 13:37:24 +00:00
void WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec );
2017-11-12 00:12:28 +00:00
void WriteTimeline( FileWrite& f, const Vector<GpuEvent*>& vec );
void ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec );
2017-11-12 00:12:28 +00:00
void ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec );
2017-09-30 14:20:08 +00:00
2017-09-12 23:33:50 +00:00
std::string m_addr;
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;
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-11-15 20:49:41 +00:00
NonRecursiveBenaphore m_lock;
2017-10-28 19:50:06 +00:00
Vector<int64_t> m_frames;
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-11-11 18:44:09 +00:00
Vector<GpuCtxData*> m_gpuData;
2017-11-21 23:23:43 +00:00
flat_hash_map<uint64_t, const char*, nohash<uint64_t>> m_strings;
flat_hash_map<uint64_t, const char*, nohash<uint64_t>> m_threadNames;
flat_hash_map<uint64_t, SourceLocation, nohash<uint64_t>> m_sourceLocation;
std::vector<uint64_t> m_sourceLocationExpand;
std::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
Vector<const char*> m_stringData;
std::unordered_map<const char*, uint32_t, charutil::Hasher, charutil::Comparator> m_stringMap;
Vector<SourceLocation*> m_sourceLocationPayload;
flat_hash_map<SourceLocation*, uint32_t, SourceLocationHasher, SourceLocationComparator> m_sourceLocationPayloadMap;
2017-11-15 20:49:41 +00:00
NonRecursiveBenaphore m_mbpslock;
std::vector<float> m_mbps;
float m_compRatio;
2017-09-14 00:00:13 +00:00
// not used for vis - no need to lock
2017-11-21 23:23:43 +00:00
flat_hash_map<uint64_t, StringLocation, nohash<uint64_t>> m_pendingCustomStrings;
flat_hash_map<uint64_t, ThreadData*, nohash<uint64_t>> m_threadMap;
flat_hash_map<uint16_t, GpuCtxData*, nohash<uint16_t>> m_gpuCtxMap;
flat_hash_map<uint64_t, PlotData*, nohash<uint64_t>> m_plotMap;
2017-11-21 01:06:17 +00:00
std::unordered_map<const char*, PlotData*, charutil::Hasher, charutil::Comparator> m_plotRev;
2017-11-21 23:23:43 +00:00
flat_hash_map<uint64_t, PlotData*, nohash<uint64_t>> m_pendingPlots;
flat_hash_map<uint64_t, uint32_t, nohash<uint64_t>> m_sourceLocationShrink;
flat_hash_map<uint64_t, int32_t, nohash<uint64_t>> m_pendingSourceLocationPayload;
Vector<uint64_t> m_sourceLocationQueue;
uint32_t m_pendingStrings;
uint32_t m_pendingThreads;
2017-11-23 23:53:04 +00:00
uint32_t m_pendingSourceLocation;
2017-10-22 13:36:22 +00:00
Slab<64*1024*1024> m_slab;
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;
int64_t m_lastTime;
2017-10-28 19:36:47 +00:00
int64_t m_delay;
int64_t m_resolution;
double m_timerMul;
std::string m_captureName;
2017-09-29 19:49:14 +00:00
int8_t m_lastCpu;
2017-10-28 19:50:06 +00:00
int m_zvHeight;
int m_zvScroll;
2017-10-12 20:27:17 +00:00
2017-10-22 13:37:24 +00:00
const ZoneEvent* m_zoneInfoWindow;
const ZoneEvent* m_zoneHighlight;
2017-10-08 21:03:38 +00:00
LockHighlight m_lockHighlight;
2017-10-14 13:47:06 +00:00
const MessageData* m_msgHighlight;
2017-11-12 00:25:44 +00:00
const GpuEvent* m_gpuInfoWindow;
2017-11-12 00:28:07 +00:00
const GpuEvent* m_gpuHighlight;
2017-11-13 23:48:26 +00:00
uint64_t m_gpuInfoWindowThread;
2017-10-13 11:32:23 +00:00
bool m_drawRegion;
2017-10-18 21:36:50 +00:00
int64_t m_regionStart;
int64_t m_regionEnd;
2017-11-11 22:13:54 +00:00
uint64_t m_gpuThread;
int64_t m_gpuStart;
int64_t m_gpuEnd;
2017-10-13 11:32:23 +00:00
bool m_showOptions;
2017-10-14 12:36:30 +00:00
bool m_showMessages;
2017-11-11 21:56:05 +00:00
bool m_drawGpuZones;
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-10-22 11:32:27 +00:00
bool m_onlyContendedLocks;
2017-10-18 16:48:51 +00:00
2017-10-22 11:56:05 +00:00
Namespace m_namespace;
2017-11-27 21:41:30 +00:00
Animation m_zoomAnim;
2017-10-22 11:56:05 +00:00
struct {
bool show;
std::vector<std::unique_ptr<ThreadData>> result;
char pattern[1024] = { "" };
int maxZonesPerThread = 1000;
int maxDepth = 10;
bool logVal = false;
} m_findZone;
2017-10-18 16:48:51 +00:00
bool m_terminate;
2017-09-12 23:33:50 +00:00
};
}
#endif