Reading saved trace.

This commit is contained in:
Bartosz Taudul 2017-09-30 16:58:02 +02:00
parent f9ee2b853c
commit 06949e2f99
3 changed files with 148 additions and 3 deletions

View File

@ -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<sz; i++ )
{
uint64_t v;
f.Read( &v, sizeof( v ) );
m_frames.push_back( v );
}
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
{
uint64_t ptr;
f.Read( &ptr, sizeof( ptr ) );
uint64_t ssz;
f.Read( &ssz, sizeof( ssz ) );
char tmp[16*1024];
f.Read( tmp, ssz );
m_strings.emplace( ptr, std::string( tmp, tmp+ssz ) );
}
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
{
uint64_t ptr;
f.Read( &ptr, sizeof( ptr ) );
uint64_t ssz;
f.Read( &ssz, sizeof( ssz ) );
char tmp[16*1024];
f.Read( tmp, ssz );
m_threadNames.emplace( ptr, std::string( tmp, tmp+ssz ) );
}
std::unordered_map<uint64_t, const char*> stringMap;
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
{
uint64_t ptr;
f.Read( &ptr, sizeof( ptr ) );
uint64_t ssz;
f.Read( &ssz, sizeof( ssz ) );
auto dst = new char[ssz+1];
f.Read( dst, ssz );
dst[ssz] = '\0';
m_customStrings.emplace( dst );
stringMap.emplace( ptr, dst );
}
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
{
uint64_t ptr;
f.Read( &ptr, sizeof( ptr ) );
QueueSourceLocation srcloc;
f.Read( &srcloc, sizeof( srcloc ) );
m_sourceLocation.emplace( ptr, srcloc );
}
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
{
auto td = new ThreadData;
f.Read( &td->id, 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<std::mutex> 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<Event*>& vec )
}
}
void View::ReadTimeline( FileRead& f, Vector<Event*>& vec, Event* parent, const std::unordered_map<uint64_t, const char*> stringMap )
{
uint64_t sz;
f.Read( &sz, sizeof( sz ) );
for( uint64_t i=0; i<sz; i++ )
{
auto zone = m_slab.Alloc<Event>();
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 );
}
}
}

View File

@ -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<Event*>& vec );
void ReadTimeline( FileRead& f, Vector<Event*>& vec, Event* parent, const std::unordered_map<uint64_t, const char*> stringMap );
std::string m_addr;
@ -104,6 +107,7 @@ private:
std::atomic<bool> m_shutdown;
std::atomic<bool> m_connected;
std::atomic<bool> m_hasData;
bool m_staticView;
// this block must be locked
std::mutex m_lock;

View File

@ -6,6 +6,7 @@
#include <memory>
#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>( tracy::FileRead::Open( fn ) );
if( f )
{
view = std::make_unique<tracy::View>( *f );
}
}
}
ImGui::End();