diff --git a/merge/src/merge.cpp b/merge/src/merge.cpp index 61f70120..29c43dc4 100644 --- a/merge/src/merge.cpp +++ b/merge/src/merge.cpp @@ -50,7 +50,7 @@ struct ExportedTrace return a.timestamp < b.timestamp; } - static std::optional fromFile( std::string const& filepath, size_t fileIndex, bool exportPlots ) + static std::optional fromFile( std::string const& filepath, size_t fileIndex ) { auto sourceFile = std::unique_ptr( tracy::FileRead::Open( filepath.c_str() ) ); if( !sourceFile ) @@ -130,20 +130,17 @@ struct ExportedTrace } std::sort( trace.messages.begin(), trace.messages.end(), orderMessages ); - if( exportPlots ) + auto& plots = worker.GetPlots(); + std::cout << " Plots: " << plots.size() << std::endl; + for( auto& plot : plots ) { - auto& plots = worker.GetPlots(); - std::cout << " Plots: " << plots.size() << std::endl; - for( auto& plot : plots ) + auto& importPlot = trace.plots.emplace_back(); + importPlot.name = worker.GetString( plot->name ); + importPlot.format = plot->format; + importPlot.data.reserve( plot->data.size() ); + for( auto& pt : plot->data ) { - auto& importPlot = trace.plots.emplace_back(); - importPlot.name = worker.GetString( plot->name ); - importPlot.format = plot->format; - importPlot.data.reserve( plot->data.size() ); - for( auto& pt : plot->data ) - { - importPlot.data.emplace_back( pt.time.Val(), pt.val ); - } + importPlot.data.emplace_back( pt.time.Val(), pt.val ); } } @@ -185,6 +182,16 @@ struct MergedTrace } } + std::unordered_map, size_t, PairHash> plotNameCounts; + for( auto const& trace : traces ) + { + for( auto const& plot : trace.plots ) + { + auto key = std::make_pair( trace.process, plot.name ); + plotNameCounts[key]++; + } + } + std::unordered_map, uint64_t, PairHash> tidMapping; size_t totalTimeline = 0, totalMessages = 0, totalPlots = 0; @@ -244,7 +251,17 @@ struct MergedTrace for( auto const& plot : trace.plots ) { - out.plots.push_back( plot ); + auto renamedPlot = plot; + auto key = std::make_pair( trace.process, plot.name ); + if( plotNameCounts[key] > 1 ) + { + renamedPlot.name = trace.process + "[" + std::to_string( trace.pid ) + "]/" + plot.name; + } + else + { + renamedPlot.name = trace.process + "/" + plot.name; + } + out.plots.push_back( renamedPlot ); } } @@ -261,7 +278,6 @@ struct MergedTrace printf( "Options:\n" ); printf( " -o, --output Output file path (required)\n" ); printf( " -f, --force Overwrite output file if it exists\n" ); - printf( " -p, --export-plots Include plots in merged output\n" ); printf( " -h, --help Show this help message\n" ); exit( 1 ); } @@ -271,18 +287,16 @@ int main( int argc, char** argv ) std::string outputFile; std::vector inputFiles; bool overwrite = false; - bool exportPlots = false; static struct option longOptions[] = { { "output", required_argument, nullptr, 'o' }, { "force", no_argument, nullptr, 'f' }, - { "export-plots", no_argument, nullptr, 'p' }, { "help", no_argument, nullptr, 'h' }, { nullptr, 0, nullptr, 0 } }; int c; - while( ( c = getopt_long( argc, argv, "o:fph", longOptions, nullptr ) ) != -1 ) + while( ( c = getopt_long( argc, argv, "o:fh", longOptions, nullptr ) ) != -1 ) { switch( c ) { @@ -292,9 +306,6 @@ int main( int argc, char** argv ) case 'f': overwrite = true; break; - case 'p': - exportPlots = true; - break; case 'h': default: Usage(); @@ -338,7 +349,7 @@ int main( int argc, char** argv ) for( size_t i = 0; i < inputFiles.size(); i++ ) { - auto trace = ExportedTrace::fromFile( inputFiles[i], i, exportPlots ); + auto trace = ExportedTrace::fromFile( inputFiles[i], i ); if( !trace ) { std::cerr << "Failed to read: " << inputFiles[i] << std::endl;