diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 3e1c1192..712a3cf1 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -13,6 +13,7 @@ #include "../common/TracyProtocol.hpp" #include "../common/TracySystem.hpp" #include "../common/TracyQueue.hpp" +#include "TracyFileRead.hpp" #include "TracyFileWrite.hpp" #include "TracyImGui.hpp" #include "TracyView.hpp" @@ -37,6 +38,7 @@ View::View( const char* addr ) , m_shutdown( false ) , m_connected( false ) , m_hasData( false ) + , m_staticView( false ) , m_zonesCnt( 0 ) , m_mbps( 64 ) , m_stream( LZ4_createStreamDecode() ) @@ -59,10 +61,102 @@ View::View( const char* addr ) SetThreadName( m_thread, "Tracy View" ); } +View::View( FileRead& f ) + : m_shutdown( false ) + , m_connected( false ) + , m_hasData( true ) + , m_staticView( true ) + , m_zonesCnt( 0 ) + , m_frameScale( 0 ) + , m_pause( false ) + , m_frameStart( 0 ) + , m_zvStart( 0 ) + , m_zvEnd( 0 ) + , m_zoneInfoWindow( nullptr ) +{ + assert( s_instance == nullptr ); + s_instance = this; + + f.Read( &m_delay, sizeof( m_delay ) ); + f.Read( &m_resolution, sizeof( m_resolution ) ); + f.Read( &m_timerMul, sizeof( m_timerMul ) ); + + uint64_t sz; + f.Read( &sz, sizeof( sz ) ); + for( uint64_t i=0; i stringMap; + + f.Read( &sz, sizeof( sz ) ); + for( uint64_t i=0; iid, sizeof( td->id ) ); + ReadTimeline( f, td->timeline, nullptr, stringMap ); + m_threads.push_back( td ); + } +} + View::~View() { m_shutdown.store( true, std::memory_order_relaxed ); - m_thread.join(); + if( !m_staticView ) + { + m_thread.join(); + } delete[] m_buffer; LZ4_freeStreamDecode( m_stream ); @@ -703,7 +797,10 @@ void View::DrawImpl() return; } - DrawConnection(); + if( !m_staticView ) + { + DrawConnection(); + } std::lock_guard lock( m_lock ); ImGui::Begin( "Profiler", nullptr, ImGuiWindowFlags_ShowBorders ); @@ -1472,6 +1569,10 @@ void View::ZoneTooltip( const Event& ev ) void View::Write( FileWrite& f ) { + f.Write( &m_delay, sizeof( m_delay ) ); + f.Write( &m_resolution, sizeof( m_resolution ) ); + f.Write( &m_timerMul, sizeof( m_timerMul ) ); + uint64_t sz = m_frames.size(); f.Write( &sz, sizeof( sz ) ); f.Write( m_frames.data(), sizeof( uint64_t ) * sz ); @@ -1551,4 +1652,39 @@ void View::WriteTimeline( FileWrite& f, const Vector& vec ) } } +void View::ReadTimeline( FileRead& f, Vector& vec, Event* parent, const std::unordered_map stringMap ) +{ + uint64_t sz; + f.Read( &sz, sizeof( sz ) ); + + for( uint64_t i=0; i(); + vec.push_back( zone ); + + f.Read( &zone->start, sizeof( zone->start ) ); + f.Read( &zone->end, sizeof( zone->end ) ); + f.Read( &zone->srcloc, sizeof( zone->srcloc ) ); + + uint8_t flag; + f.Read( &flag, sizeof( flag ) ); + if( flag ) + { + zone->text = new TextData; + uint64_t ptr; + f.Read( &ptr, sizeof( ptr ) ); + zone->text->userText = ptr == 0 ? nullptr : stringMap.find( ptr )->second; + f.Read( &zone->text->zoneName, sizeof( zone->text->zoneName ) ); + } + else + { + zone->text = nullptr; + } + + zone->parent = parent; + + ReadTimeline( f, zone->child, zone, stringMap ); + } +} + } diff --git a/server/TracyView.hpp b/server/TracyView.hpp index cd2c4a02..0532f8f5 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -23,6 +23,7 @@ namespace tracy { struct QueueItem; +class FileRead; class FileWrite; class View @@ -30,6 +31,7 @@ class View public: View() : View( "127.0.0.1" ) {} View( const char* addr ); + View( FileRead& f ); ~View(); static bool ShouldExit(); @@ -96,6 +98,7 @@ private: void Write( FileWrite& f ); void WriteTimeline( FileWrite& f, const Vector& vec ); + void ReadTimeline( FileRead& f, Vector& vec, Event* parent, const std::unordered_map stringMap ); std::string m_addr; @@ -104,6 +107,7 @@ private: std::atomic m_shutdown; std::atomic m_connected; std::atomic m_hasData; + bool m_staticView; // this block must be locked std::mutex m_lock; diff --git a/standalone/src/main.cpp b/standalone/src/main.cpp index 3045f695..277fa882 100755 --- a/standalone/src/main.cpp +++ b/standalone/src/main.cpp @@ -6,6 +6,7 @@ #include #include "../nfd/nfd.h" +#include "../../server/TracyFileRead.hpp" #include "../../server/TracyView.hpp" static void error_callback(int error, const char* description) @@ -69,7 +70,11 @@ int main(int, char**) auto res = NFD_OpenDialog( "tracy", nullptr, &fn ); if( res == NFD_OKAY ) { - + auto f = std::unique_ptr( tracy::FileRead::Open( fn ) ); + if( f ) + { + view = std::make_unique( *f ); + } } } ImGui::End();