Allow import of plots.

This commit is contained in:
Bartosz Taudul 2020-06-20 15:30:06 +02:00
parent 25c7245566
commit d1e17de7c2
3 changed files with 52 additions and 3 deletions

View File

@ -55,6 +55,7 @@ int main( int argc, char** argv )
std::vector<tracy::Worker::ImportEventTimeline> timeline; std::vector<tracy::Worker::ImportEventTimeline> timeline;
std::vector<tracy::Worker::ImportEventMessages> messages; std::vector<tracy::Worker::ImportEventMessages> messages;
std::vector<tracy::Worker::ImportEventPlots> plots;
if( j.is_object() && j.contains( "traceEvents" ) ) if( j.is_object() && j.contains( "traceEvents" ) )
{ {
@ -121,6 +122,7 @@ int main( int argc, char** argv )
std::stable_sort( timeline.begin(), timeline.end(), [] ( const auto& l, const auto& r ) { return l.timestamp < r.timestamp; } ); std::stable_sort( timeline.begin(), timeline.end(), [] ( const auto& l, const auto& r ) { return l.timestamp < r.timestamp; } );
std::stable_sort( messages.begin(), messages.end(), [] ( const auto& l, const auto& r ) { return l.timestamp < r.timestamp; } ); std::stable_sort( messages.begin(), messages.end(), [] ( const auto& l, const auto& r ) { return l.timestamp < r.timestamp; } );
for( auto& v : plots ) std::stable_sort( v.data.begin(), v.data.end(), [] ( const auto& l, const auto& r ) { return l.first < r.first; } );
uint64_t mts = 0; uint64_t mts = 0;
if( !timeline.empty() ) if( !timeline.empty() )
@ -141,7 +143,7 @@ int main( int argc, char** argv )
while( *program ) program++; while( *program ) program++;
program--; program--;
while( program > input && ( *program != '/' || *program != '\\' ) ) program--; while( program > input && ( *program != '/' || *program != '\\' ) ) program--;
tracy::Worker worker( program, timeline, messages ); tracy::Worker worker( program, timeline, messages, plots );
auto w = std::unique_ptr<tracy::FileWrite>( tracy::FileWrite::Open( output, clev ) ); auto w = std::unique_ptr<tracy::FileWrite>( tracy::FileWrite::Open( output, clev ) );
if( !w ) if( !w )

View File

@ -270,7 +270,7 @@ Worker::Worker( const char* addr, int port )
m_threadNet = std::thread( [this] { SetThreadName( "Tracy Network" ); Network(); } ); m_threadNet = std::thread( [this] { SetThreadName( "Tracy Network" ); Network(); } );
} }
Worker::Worker( const std::string& program, const std::vector<ImportEventTimeline>& timeline, const std::vector<ImportEventMessages>& messages ) Worker::Worker( const std::string& program, const std::vector<ImportEventTimeline>& timeline, const std::vector<ImportEventMessages>& messages, const std::vector<ImportEventPlots>& plots )
: m_hasData( true ) : m_hasData( true )
, m_delay( 0 ) , m_delay( 0 )
, m_resolution( 0 ) , m_resolution( 0 )
@ -296,6 +296,13 @@ Worker::Worker( const std::string& program, const std::vector<ImportEventTimelin
{ {
if( m_data.lastTime < (int64_t)messages.back().timestamp ) m_data.lastTime = messages.back().timestamp; if( m_data.lastTime < (int64_t)messages.back().timestamp ) m_data.lastTime = messages.back().timestamp;
} }
if( !plots.empty() )
{
for( auto& v : plots )
{
if( m_data.lastTime < v.data.back().first ) m_data.lastTime = v.data.back().first;
}
}
for( auto& v : timeline ) for( auto& v : timeline )
{ {
@ -378,6 +385,39 @@ Worker::Worker( const std::string& program, const std::vector<ImportEventTimelin
InsertMessageData( msg ); InsertMessageData( msg );
} }
for( auto& v : plots )
{
uint64_t nptr = (uint64_t)&v.name;
auto it = m_data.strings.find( nptr );
if( it == m_data.strings.end() )
{
const auto sl = StoreString( v.name.c_str(), v.name.size() );
m_data.strings.emplace( nptr, sl.ptr );
}
auto plot = m_slab.AllocInit<PlotData>();
plot->name = nptr;
plot->type = PlotType::User;
plot->format = v.format;
double min = v.data.begin()->first;
double max = v.data.begin()->first;
plot->data.reserve_exact( v.data.size(), m_slab );
size_t idx = 0;
for( auto& p : v.data )
{
plot->data[idx].time.SetVal( p.first );
plot->data[idx].val = p.second;
idx++;
if( min > p.second ) min = p.second;
else if( max < p.second ) max = p.second;
}
plot->min = min;
plot->max = max;
m_data.plots.Data().push_back( plot );
}
for( auto& t : m_threadMap ) for( auto& t : m_threadMap )
{ {
char buf[64]; char buf[64];

View File

@ -107,6 +107,13 @@ public:
std::string message; std::string message;
}; };
struct ImportEventPlots
{
std::string name;
PlotValueFormatting format;
std::vector<std::pair<int64_t, double>> data;
};
struct ZoneThreadData struct ZoneThreadData
{ {
tracy_force_inline ZoneEvent* Zone() const { return (ZoneEvent*)( _zone_thread >> 16 ); } tracy_force_inline ZoneEvent* Zone() const { return (ZoneEvent*)( _zone_thread >> 16 ); }
@ -399,7 +406,7 @@ public:
}; };
Worker( const char* addr, int port ); Worker( const char* addr, int port );
Worker( const std::string& program, const std::vector<ImportEventTimeline>& timeline, const std::vector<ImportEventMessages>& messages ); Worker( const std::string& program, const std::vector<ImportEventTimeline>& timeline, const std::vector<ImportEventMessages>& messages, const std::vector<ImportEventPlots>& plots );
Worker( FileRead& f, EventType::Type eventMask = EventType::All, bool bgTasks = true ); Worker( FileRead& f, EventType::Type eventMask = EventType::All, bool bgTasks = true );
~Worker(); ~Worker();