Writing traces.

This commit is contained in:
Bartosz Taudul 2017-09-30 16:20:08 +02:00
parent 2021b7460a
commit f9ee2b853c
2 changed files with 91 additions and 1 deletions

View File

@ -13,6 +13,7 @@
#include "../common/TracyProtocol.hpp"
#include "../common/TracySystem.hpp"
#include "../common/TracyQueue.hpp"
#include "TracyFileWrite.hpp"
#include "TracyImGui.hpp"
#include "TracyView.hpp"
@ -771,7 +772,11 @@ void View::DrawConnection()
const char* fn = "trace.tracy";
#endif
{
auto f = std::unique_ptr<FileWrite>( FileWrite::Open( fn ) );
if( f )
{
Write( *f );
}
}
}
@ -1465,4 +1470,85 @@ void View::ZoneTooltip( const Event& ev )
ImGui::EndTooltip();
}
void View::Write( FileWrite& f )
{
uint64_t sz = m_frames.size();
f.Write( &sz, sizeof( sz ) );
f.Write( m_frames.data(), sizeof( uint64_t ) * sz );
sz = m_strings.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_strings )
{
f.Write( &v.first, sizeof( v.first ) );
sz = v.second.size();
f.Write( &sz, sizeof( sz ) );
f.Write( v.second.c_str(), v.second.size() );
}
sz = m_threadNames.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_threadNames )
{
f.Write( &v.first, sizeof( v.first ) );
sz = v.second.size();
f.Write( &sz, sizeof( sz ) );
f.Write( v.second.c_str(), v.second.size() );
}
sz = m_customStrings.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_customStrings )
{
uint64_t ptr = (uint64_t)v;
f.Write( &ptr, sizeof( ptr ) );
sz = strlen( v );
f.Write( &sz, sizeof( sz ) );
f.Write( v, sz );
}
sz = m_sourceLocation.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : m_sourceLocation )
{
f.Write( &v.first, sizeof( v.first ) );
f.Write( &v.second, sizeof( v.second ) );
}
sz = m_threads.size();
f.Write( &sz, sizeof( sz ) );
for( auto& thread : m_threads )
{
f.Write( &thread->id, sizeof( thread->id ) );
WriteTimeline( f, thread->timeline );
}
}
void View::WriteTimeline( FileWrite& f, const Vector<Event*>& vec )
{
uint64_t sz = vec.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : vec )
{
f.Write( &v->start, sizeof( v->start ) );
f.Write( &v->end, sizeof( v->end ) );
f.Write( &v->srcloc, sizeof( v->srcloc ) );
if( v->text )
{
uint8_t flag = 1;
f.Write( &flag, sizeof( flag ) );
f.Write( &v->text->userText, sizeof( v->text->userText ) );
f.Write( &v->text->zoneName, sizeof( v->text->zoneName ) );
}
else
{
uint8_t flag = 0;
f.Write( &flag, sizeof( flag ) );
}
WriteTimeline( f, v->child );
}
}
}

View File

@ -23,6 +23,7 @@ namespace tracy
{
struct QueueItem;
class FileWrite;
class View
{
@ -93,6 +94,9 @@ private:
void ZoomToZone( const Event& ev );
void ZoneTooltip( const Event& ev );
void Write( FileWrite& f );
void WriteTimeline( FileWrite& f, const Vector<Event*>& vec );
std::string m_addr;
Socket m_sock;