From d1e17de7c2770d375c8d4b1d0738636dfb97f3e3 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 20 Jun 2020 15:30:06 +0200 Subject: [PATCH] Allow import of plots. --- import-chrome/src/import-chrome.cpp | 4 ++- server/TracyWorker.cpp | 42 ++++++++++++++++++++++++++++- server/TracyWorker.hpp | 9 ++++++- 3 files changed, 52 insertions(+), 3 deletions(-) diff --git a/import-chrome/src/import-chrome.cpp b/import-chrome/src/import-chrome.cpp index 241e9198..a0708143 100644 --- a/import-chrome/src/import-chrome.cpp +++ b/import-chrome/src/import-chrome.cpp @@ -55,6 +55,7 @@ int main( int argc, char** argv ) std::vector timeline; std::vector messages; + std::vector plots; 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( 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; if( !timeline.empty() ) @@ -141,7 +143,7 @@ int main( int argc, char** argv ) while( *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::Open( output, clev ) ); if( !w ) diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index f0833710..61690dcd 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -270,7 +270,7 @@ Worker::Worker( const char* addr, int port ) m_threadNet = std::thread( [this] { SetThreadName( "Tracy Network" ); Network(); } ); } -Worker::Worker( const std::string& program, const std::vector& timeline, const std::vector& messages ) +Worker::Worker( const std::string& program, const std::vector& timeline, const std::vector& messages, const std::vector& plots ) : m_hasData( true ) , m_delay( 0 ) , m_resolution( 0 ) @@ -296,6 +296,13 @@ Worker::Worker( const std::string& program, const std::vector(); + 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 ) { char buf[64]; diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index 6677f326..74a83c98 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -107,6 +107,13 @@ public: std::string message; }; + struct ImportEventPlots + { + std::string name; + PlotValueFormatting format; + std::vector> data; + }; + struct ZoneThreadData { tracy_force_inline ZoneEvent* Zone() const { return (ZoneEvent*)( _zone_thread >> 16 ); } @@ -399,7 +406,7 @@ public: }; Worker( const char* addr, int port ); - Worker( const std::string& program, const std::vector& timeline, const std::vector& messages ); + Worker( const std::string& program, const std::vector& timeline, const std::vector& messages, const std::vector& plots ); Worker( FileRead& f, EventType::Type eventMask = EventType::All, bool bgTasks = true ); ~Worker();