tracy/server/TracyView.hpp

536 lines
16 KiB
C++
Raw Normal View History

2017-09-12 23:33:50 +00:00
#ifndef __TRACYVIEW_HPP__
#define __TRACYVIEW_HPP__
#include <atomic>
#include <functional>
#include <map>
2018-08-17 12:44:41 +00:00
#include <memory>
2017-09-12 23:33:50 +00:00
#include <string>
#include <thread>
2017-09-14 00:00:13 +00:00
#include <vector>
#include "TracyBuzzAnim.hpp"
#include "TracyDecayValue.hpp"
2019-06-06 20:14:25 +00:00
#include "TracyTexture.hpp"
2017-09-15 18:17:39 +00:00
#include "TracyVector.hpp"
#include "TracyWorker.hpp"
2017-11-15 22:15:59 +00:00
#include "tracy_flat_hash_map.hpp"
2017-09-12 23:33:50 +00:00
struct ImVec2;
2018-08-17 13:18:09 +00:00
struct ImFont;
2017-09-12 23:33:50 +00:00
namespace tracy
{
struct MemoryPage;
2017-09-13 21:40:28 +00:00
struct QueueItem;
2017-09-30 14:58:02 +00:00
class FileRead;
2018-08-17 12:44:41 +00:00
class TextEditor;
2017-09-13 21:40:28 +00:00
2017-09-12 23:33:50 +00:00
class View
{
2017-11-27 21:41:30 +00:00
struct Animation
{
bool active = false;
int64_t start0, start1;
int64_t end0, end1;
double progress;
};
struct Region
{
bool active = false;
int64_t start;
int64_t end;
};
2017-09-12 23:33:50 +00:00
public:
2019-02-21 20:18:41 +00:00
struct VisData
{
bool visible = true;
bool showFull = true;
int offset = 0;
int height = 0;
};
2019-03-17 16:21:30 +00:00
struct PlotView
{
double min;
double max;
};
using SetTitleCallback = void(*)( const char* );
View( ImFont* fixedWidth = nullptr, SetTitleCallback stcb = nullptr ) : View( "127.0.0.1", fixedWidth, stcb ) {}
View( const char* addr, ImFont* fixedWidth = nullptr, SetTitleCallback stcb = nullptr );
View( FileRead& f, ImFont* fixedWidth = nullptr, SetTitleCallback stcb = nullptr );
2017-09-12 23:33:50 +00:00
~View();
2018-04-29 23:16:08 +00:00
static bool Draw();
void NotifyRootWindowSize( float w, float h ) { m_rootWidth = w; m_rootHeight = h; }
2018-08-18 12:26:10 +00:00
void SetTextEditorFile( const char* fileName, int line );
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
};
enum class ShortcutAction : uint8_t
{
None,
OpenFind
};
2018-12-16 18:58:11 +00:00
enum { InvalidId = 0xFFFFFFFF };
struct PathData
{
uint32_t cnt;
uint64_t mem;
};
2018-08-17 12:44:41 +00:00
void InitTextEditor();
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 );
2018-04-29 23:16:08 +00:00
bool DrawImpl();
2018-11-25 18:29:20 +00:00
bool DrawConnection();
2017-09-18 00:37:25 +00:00
void DrawFrames();
2018-08-04 19:10:03 +00:00
bool DrawZoneFramesHeader();
bool DrawZoneFrames( const FrameData& frames );
2017-09-20 22:57:26 +00:00
void DrawZones();
2019-03-18 17:40:03 +00:00
int DispatchZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax );
int DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax );
int SkipZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, float yMin, float yMax );
int DispatchGpuZoneLevel( const Vector<GpuEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
int DrawGpuZoneLevel( const Vector<GpuEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
int SkipGpuZoneLevel( const Vector<GpuEvent*>& vec, bool hover, double pxns, int64_t nspx, const ImVec2& wpos, int offset, int depth, uint64_t thread, float yMin, float yMax, int64_t begin, int drift );
2019-02-24 16:30:58 +00:00
void DrawLockHeader( uint32_t id, const LockMap& lockmap, const SourceLocation& srcloc, bool hover, ImDrawList* draw, const ImVec2& wpos, float w, float ty, float offset, uint8_t tid );
2018-04-20 20:53:15 +00:00
int DrawLocks( uint64_t tid, bool hover, double pxns, const ImVec2& wpos, int offset, LockHighlight& highlight, float yMin, float yMax );
2018-04-20 21:00:26 +00:00
int DrawPlots( int offset, double pxns, const ImVec2& wpos, bool hover, float yMin, float yMax );
2018-06-28 22:38:56 +00:00
void DrawPlotPoint( const ImVec2& wpos, float x, float y, int offset, uint32_t color, bool hover, bool hasPrev, const PlotItem* item, double prev, bool merged, PlotType type, float PlotHeight );
2019-02-21 22:07:32 +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, PlotType type, float PlotHeight );
2017-10-13 11:32:23 +00:00
void DrawOptions();
2017-10-14 12:36:30 +00:00
void DrawMessages();
void DrawFindZone();
2018-03-24 13:40:48 +00:00
void DrawStatistics();
void DrawMemory();
2018-09-27 21:16:10 +00:00
void DrawAllocList();
2018-04-21 22:52:33 +00:00
void DrawCompare();
void DrawCallstackWindow();
2018-07-17 21:03:03 +00:00
void DrawMemoryAllocWindow();
2018-08-08 17:25:13 +00:00
void DrawInfo();
void DrawTextEditor();
2018-10-21 15:36:27 +00:00
void DrawGoToFrame();
2018-12-16 18:58:11 +00:00
void DrawLockInfoWindow();
2019-06-11 23:26:49 +00:00
void DrawPlayback();
2017-09-15 00:30:22 +00:00
template<class T>
void ListMemData( T ptr, T end, std::function<void(T&)> DrawAddress, const char* id = nullptr, int64_t startTime = -1 );
flat_hash_map<uint32_t, PathData, nohash<uint32_t>> GetCallstackPaths( const MemData& mem, bool onlyActive ) const;
flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> GetCallstackFrameTreeBottomUp( const MemData& mem ) const;
flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>> GetCallstackFrameTreeTopDown( const MemData& mem ) const;
void DrawFrameTreeLevel( const flat_hash_map<uint64_t, CallstackFrameTree, nohash<uint64_t>>& tree, int& idx );
void DrawZoneList( const Vector<ZoneEvent*>& zones );
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 );
void ZoomToPrevFrame();
void ZoomToNextFrame();
void CenterAtTime( int64_t t );
2018-05-02 17:23:46 +00:00
void ShowZoneInfo( const ZoneEvent& ev );
void ShowZoneInfo( const GpuEvent& ev, uint64_t thread );
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 );
2018-06-19 20:19:33 +00:00
void CallstackTooltip( uint32_t idx );
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;
2019-03-17 15:17:47 +00:00
const ThreadData* GetZoneThreadData( const ZoneEvent& zone ) const;
uint64_t GetZoneThread( const ZoneEvent& zone ) const;
2018-03-19 15:11:37 +00:00
uint64_t GetZoneThread( const GpuEvent& zone ) const;
const GpuCtxData* GetZoneCtx( const GpuEvent& zone ) const;
const ZoneEvent* FindZoneAtTime( uint64_t thread, int64_t time ) const;
2018-08-04 19:19:24 +00:00
const char* GetFrameText( const FrameData& fd, int i, uint64_t ftime, uint64_t offset ) const;
2017-09-29 19:57:00 +00:00
#ifndef TRACY_NO_STATISTICS
void FindZones();
2018-04-21 22:52:33 +00:00
void FindZonesCompare();
#endif
std::vector<MemoryPage> GetMemoryPages() const;
const char* GetPlotName( const PlotData* plot ) const;
2018-04-02 16:14:59 +00:00
void SmallCallstackButton( const char* name, uint32_t callstack, int& idx, bool tooltip = true );
void SetViewToLastFrames();
2019-01-23 12:39:44 +00:00
int64_t GetZoneChildTime( const ZoneEvent& zone );
2019-02-14 00:28:12 +00:00
int64_t GetZoneChildTime( const GpuEvent& zone );
int64_t GetZoneChildTimeFast( const ZoneEvent& zone );
2019-03-29 23:52:25 +00:00
int64_t GetZoneSelfTime( const ZoneEvent& zone );
int64_t GetZoneSelfTime( const GpuEvent& zone );
2018-07-17 20:53:38 +00:00
2019-06-12 22:12:06 +00:00
void SetPlaybackFrame( uint32_t idx );
flat_hash_map<const void*, VisData, nohash<const void*>> m_visData;
2018-08-18 17:57:36 +00:00
flat_hash_map<uint64_t, bool, nohash<uint64_t>> m_visibleMsgThread;
2018-06-27 23:08:08 +00:00
flat_hash_map<const void*, int, nohash<const void*>> m_gpuDrift;
2019-03-17 16:21:30 +00:00
flat_hash_map<const PlotData*, PlotView, nohash<const PlotData*>> m_plotView;
Vector<const ThreadData*> m_threadOrder;
tracy_force_inline VisData& Vis( const void* ptr )
{
auto it = m_visData.find( ptr );
if( it == m_visData.end() )
{
it = m_visData.emplace( ptr, VisData {} ).first;
}
return it->second;
}
2017-09-30 14:20:08 +00:00
2018-08-18 17:57:36 +00:00
tracy_force_inline bool& VisibleMsgThread( uint64_t thread )
{
auto it = m_visibleMsgThread.find( thread );
if( it == m_visibleMsgThread.end() )
{
it = m_visibleMsgThread.emplace( thread, true ).first;
}
return it->second;
}
2018-06-27 23:08:08 +00:00
tracy_force_inline int& GpuDrift( const void* ptr )
{
auto it = m_gpuDrift.find( ptr );
if( it == m_gpuDrift.end() )
{
it = m_gpuDrift.emplace( ptr, 0 ).first;
}
return it->second;
}
Worker m_worker;
2017-09-30 14:58:02 +00:00
bool m_staticView;
2017-09-12 23:54:22 +00:00
int m_frameScale = 0;
2017-09-18 22:26:40 +00:00
bool m_pause;
int m_frameStart = 0;
2017-09-20 19:21:21 +00:00
int64_t m_zvStart = 0;
int64_t m_zvEnd = 0;
int8_t m_lastCpu;
int m_zvHeight = 0;
int m_zvScroll = 0;
2017-10-12 20:27:17 +00:00
const ZoneEvent* m_zoneInfoWindow = nullptr;
2017-10-22 13:37:24 +00:00
const ZoneEvent* m_zoneHighlight;
DecayValue<int32_t> m_zoneSrcLocHighlight = 0;
LockHighlight m_lockHighlight { -1 };
DecayValue<const MessageData*> m_msgHighlight = nullptr;
2019-02-17 15:20:56 +00:00
DecayValue<uint32_t> m_lockHoverHighlight = InvalidId;
const MessageData* m_msgToFocus = nullptr;
const GpuEvent* m_gpuInfoWindow = nullptr;
2017-11-12 00:28:07 +00:00
const GpuEvent* m_gpuHighlight;
2017-11-13 23:48:26 +00:00
uint64_t m_gpuInfoWindowThread;
uint32_t m_callstackInfoWindow = 0;
int64_t m_memoryAllocInfoWindow = -1;
int64_t m_memoryAllocHover = -1;
int m_memoryAllocHoverWait = 0;
2018-08-04 17:47:09 +00:00
const FrameData* m_frames;
uint32_t m_lockInfoWindow = InvalidId;
2019-06-16 15:05:56 +00:00
ZoneEvent* m_zoneHover = nullptr;
int m_frameHover = -1;
2017-10-13 11:32:23 +00:00
Region m_highlight;
Region m_highlightZoom;
uint64_t m_gpuThread = 0;
int64_t m_gpuStart = 0;
int64_t m_gpuEnd = 0;
bool m_showOptions = false;
bool m_showMessages = false;
bool m_showStatistics = false;
bool m_showInfo = false;
2019-06-11 23:26:49 +00:00
bool m_showPlayback = false;
bool m_drawGpuZones = true;
bool m_drawZones = true;
bool m_drawLocks = true;
bool m_drawPlots = true;
bool m_onlyContendedLocks = true;
bool m_goToFrame = false;
bool m_drawEmptyLabels = false;
int m_statSort = 0;
bool m_statSelf = false;
bool m_showCallstackFrameAddress = false;
bool m_showUnknownFrames = true;
bool m_groupChildrenLocations = false;
bool m_allocTimeRelativeToZone = true;
ShortcutAction m_shortcut = ShortcutAction::None;
Namespace m_namespace = Namespace::Short;
2017-11-27 21:41:30 +00:00
Animation m_zoomAnim;
BuzzAnim<int> m_callstackBuzzAnim;
BuzzAnim<int> m_callstackTreeBuzzAnim;
2018-08-18 12:26:10 +00:00
BuzzAnim<const void*> m_zoneinfoBuzzAnim;
BuzzAnim<int> m_findZoneBuzzAnim;
BuzzAnim<uint32_t> m_optionsLockBuzzAnim;
2018-12-16 18:58:11 +00:00
BuzzAnim<uint32_t> m_lockInfoAnim;
BuzzAnim<uint32_t> m_statBuzzAnim;
2017-10-22 11:56:05 +00:00
2018-05-02 17:23:46 +00:00
Vector<const ZoneEvent*> m_zoneInfoStack;
Vector<const GpuEvent*> m_gpuInfoStack;
2018-08-17 12:44:41 +00:00
std::unique_ptr<TextEditor> m_textEditor;
2018-08-17 12:54:28 +00:00
const char* m_textEditorFile;
2018-08-17 13:18:09 +00:00
ImFont* m_textEditorFont;
2018-08-17 12:44:41 +00:00
float m_rootWidth, m_rootHeight;
SetTitleCallback m_stcb;
bool m_titleSet = false;
float m_notificationTime = 0;
std::string m_notificationText;
bool m_groupCallstackTreeByNameBottomUp = true;
bool m_groupCallstackTreeByNameTopDown = true;
bool m_activeOnlyBottomUp = false;
bool m_activeOnlyTopDown = false;
2019-02-06 20:45:26 +00:00
enum class SaveThreadState
{
Inert,
Saving,
NeedsJoin
};
2019-06-02 11:15:55 +00:00
std::atomic<SaveThreadState> m_saveThreadState { SaveThreadState::Inert };
std::thread m_saveThread;
2019-06-06 21:14:49 +00:00
void* m_frameTexture = nullptr;
2019-06-06 21:10:01 +00:00
const void* m_frameTexturePtr = nullptr;
2019-06-06 20:14:25 +00:00
struct FindZone {
enum : uint64_t { Unselected = std::numeric_limits<uint64_t>::max() - 1 };
enum class GroupBy : int { Thread, UserText, Callstack };
enum class SortBy : int { Order, Count, Time, Mtpc };
2019-02-07 13:51:34 +00:00
enum class TableSortBy : int { Starttime, Runtime, Name };
2018-07-21 21:53:11 +00:00
struct Group
{
Vector<ZoneEvent*> zones;
int64_t time = 0;
};
2018-04-01 19:24:30 +00:00
bool show = false;
bool ignoreCase = false;
std::vector<int32_t> match;
2018-07-21 21:53:11 +00:00
std::map<uint64_t, Group> groups;
size_t processed;
int selMatch = 0;
uint64_t selGroup = Unselected;
2018-04-01 19:24:30 +00:00
char pattern[1024] = {};
bool logVal = false;
bool logTime = true;
2018-03-05 19:15:18 +00:00
bool cumulateTime = false;
bool selfTime = false;
GroupBy groupBy = GroupBy::Thread;
SortBy sortBy = SortBy::Count;
2019-02-07 13:51:34 +00:00
TableSortBy tableSortBy = TableSortBy::Starttime;
2018-03-04 21:52:36 +00:00
Region highlight;
int64_t hlOrig_t0, hlOrig_t1;
2018-06-06 21:06:00 +00:00
int64_t numBins = -1;
std::unique_ptr<int64_t[]> bins, binTime, selBin;
std::vector<int64_t> sorted, selSort;
size_t sortedNum = 0, selSortNum, selSortActive;
float average, selAverage;
float median, selMedian;
int64_t total, selTotal;
bool drawAvgMed = true;
bool drawSelAvgMed = true;
bool scheduleResetMatch = false;
int selCs = 0;
int minBinVal = 1;
2018-03-04 21:52:36 +00:00
struct
{
int numBins = -1;
ptrdiff_t distBegin;
ptrdiff_t distEnd;
} binCache;
2018-03-04 21:52:36 +00:00
void Reset()
{
ResetMatch();
2018-03-04 21:52:36 +00:00
match.clear();
selMatch = 0;
selGroup = Unselected;
2018-03-04 21:52:36 +00:00
highlight.active = false;
}
void ResetMatch()
{
ResetGroups();
sorted.clear();
sortedNum = 0;
average = 0;
median = 0;
total = 0;
2018-03-04 21:52:36 +00:00
}
void ResetGroups()
{
ResetSelection();
groups.clear();
processed = 0;
selCs = 0;
}
void ResetSelection()
{
selSort.clear();
selSortNum = 0;
selSortActive = 0;
selAverage = 0;
selMedian = 0;
selTotal = 0;
binCache.numBins = -1;
}
void ShowZone( int32_t srcloc, const char* name )
{
show = true;
Reset();
match.emplace_back( srcloc );
strcpy( pattern, name );
}
} m_findZone;
2018-04-01 19:24:30 +00:00
tracy_force_inline uint64_t GetSelectionTarget( const Worker::ZoneThreadData& ev, FindZone::GroupBy groupBy ) const;
2018-06-06 21:09:46 +00:00
struct CompVal
{
double v0;
double v1;
};
2018-04-21 22:52:33 +00:00
struct {
bool show = false;
bool ignoreCase = false;
bool link = true;
2018-04-21 22:52:33 +00:00
std::unique_ptr<Worker> second;
std::thread loadThread;
2018-04-21 22:52:33 +00:00
int badVer = 0;
char pattern[1024] = {};
std::vector<int32_t> match[2];
int selMatch[2] = { 0, 0 };
bool logVal = false;
bool logTime = true;
bool cumulateTime = false;
bool normalize = true;
2018-06-06 21:09:46 +00:00
int64_t numBins = -1;
std::unique_ptr<CompVal[]> bins, binTime;
std::vector<int64_t> sorted[2];
size_t sortedNum[2] = { 0, 0 };
float average[2];
float median[2];
int64_t total[2];
int minBinVal = 1;
void ResetSelection()
{
for( int i=0; i<2; i++ )
{
sorted[i].clear();
sortedNum[i] = 0;
average[i] = 0;
median[i] = 0;
total[i] = 0;
}
}
2018-04-21 22:52:33 +00:00
void Reset()
{
ResetSelection();
2018-04-21 22:52:33 +00:00
for( int i=0; i<2; i++ )
{
match[i].clear();
selMatch[i] = 0;
}
}
} m_compare;
2018-04-01 19:24:30 +00:00
struct {
bool show = false;
char pattern[1024] = {};
uint64_t ptrFind = 0;
bool restrictTime = false;
2018-09-27 21:16:10 +00:00
bool showAllocList = false;
std::vector<size_t> allocList;
2018-04-01 19:24:30 +00:00
} m_memInfo;
struct {
2018-08-31 23:02:08 +00:00
std::vector<int64_t> data;
const FrameData* frameSet = nullptr;
size_t frameNum = 0;
float average = 0;
float median = 0;
2018-08-31 23:12:04 +00:00
int64_t total = 0;
2018-08-31 23:12:16 +00:00
bool logVal = false;
bool logTime = true;
int64_t numBins = -1;
std::unique_ptr<int64_t[]> bins;
bool drawAvgMed = true;
bool limitToView = false;
std::pair<int, int> limitRange = { -1, 0 };
int minBinVal = 1;
} m_frameSortData;
2019-03-29 23:52:25 +00:00
struct {
std::pair<const ZoneEvent*, int64_t> zoneSelfTime = { nullptr, 0 };
std::pair<const ZoneEvent*, int64_t> zoneSelfTime2 = { nullptr, 0 };
2019-03-29 23:52:25 +00:00
std::pair<const GpuEvent*, int64_t> gpuSelfTime = { nullptr, 0 };
std::pair<const GpuEvent*, int64_t> gpuSelfTime2 = { nullptr, 0 };
2019-03-29 23:52:25 +00:00
} m_cache;
2019-06-11 23:26:49 +00:00
struct {
void* texture = nullptr;
float timeLeft = 0;
float speed = 1;
uint32_t frame = 0;
uint32_t currFrame = -1;
bool pause = true;
bool sync = false;
} m_playback;
2017-09-12 23:33:50 +00:00
};
}
#endif