2018-07-08 14:53:31 +00:00
|
|
|
#ifdef _WIN32
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
|
2019-03-13 00:28:42 +00:00
|
|
|
#include <chrono>
|
2018-07-08 14:53:31 +00:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
|
|
|
#include "../../server/TracyFileRead.hpp"
|
|
|
|
#include "../../server/TracyFileWrite.hpp"
|
2020-02-08 12:18:42 +00:00
|
|
|
#include "../../server/TracyPrint.hpp"
|
2018-07-29 13:37:45 +00:00
|
|
|
#include "../../server/TracyVersion.hpp"
|
2018-07-08 14:53:31 +00:00
|
|
|
#include "../../server/TracyWorker.hpp"
|
2020-02-08 14:43:16 +00:00
|
|
|
#include "../../zstd/zstd.h"
|
2020-07-17 19:47:51 +00:00
|
|
|
#include "../../getopt/getopt.h"
|
2018-07-08 14:53:31 +00:00
|
|
|
|
2019-11-02 21:11:40 +00:00
|
|
|
#ifdef __CYGWIN__
|
|
|
|
# define ftello64(x) ftello(x)
|
2020-06-20 17:04:15 +00:00
|
|
|
#elif defined __APPLE__
|
|
|
|
# define ftello64(x) ftello(x)
|
2019-11-02 21:11:40 +00:00
|
|
|
#elif defined _WIN32
|
|
|
|
# define ftello64(x) _ftelli64(x)
|
|
|
|
#endif
|
|
|
|
|
2018-07-08 14:53:31 +00:00
|
|
|
void Usage()
|
|
|
|
{
|
2020-07-17 19:47:51 +00:00
|
|
|
printf( "Usage: update [options] input.tracy output.tracy\n\n" );
|
|
|
|
printf( " -h: enable LZ4HC compression\n" );
|
|
|
|
printf( " -e: enable extreme LZ4HC compression (very slow)\n" );
|
|
|
|
printf( " -z level: use Zstd compression with given compression level\n" );
|
2021-05-15 13:50:20 +00:00
|
|
|
printf( " -d: build dictionary for frame images\n" );
|
2020-07-17 20:06:15 +00:00
|
|
|
printf( " -s flags: strip selected data from capture:\n" );
|
|
|
|
printf( " l: locks, m: messages, p: plots, M: memory, i: frame images\n" );
|
|
|
|
printf( " c: context switches, s: sampling data, C: symbol code, S: source cache\n" );
|
2018-07-08 14:53:31 +00:00
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
int main( int argc, char** argv )
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
if( !AttachConsole( ATTACH_PARENT_PROCESS ) )
|
|
|
|
{
|
|
|
|
AllocConsole();
|
|
|
|
SetConsoleMode( GetStdHandle( STD_OUTPUT_HANDLE ), 0x07 );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-09-29 19:03:08 +00:00
|
|
|
tracy::FileWrite::Compression clev = tracy::FileWrite::Compression::Fast;
|
2020-07-17 20:06:15 +00:00
|
|
|
uint32_t events = tracy::EventType::All;
|
2020-02-08 14:43:16 +00:00
|
|
|
int zstdLevel = 1;
|
2021-05-15 13:50:20 +00:00
|
|
|
bool buildDict = false;
|
2020-07-17 19:47:51 +00:00
|
|
|
int c;
|
2021-05-15 13:50:20 +00:00
|
|
|
while( ( c = getopt( argc, argv, "hez:ds:" ) ) != -1 )
|
2018-08-26 14:28:46 +00:00
|
|
|
{
|
2020-07-17 19:47:51 +00:00
|
|
|
switch( c )
|
2019-09-29 19:03:08 +00:00
|
|
|
{
|
2020-07-17 19:47:51 +00:00
|
|
|
case 'h':
|
2019-09-29 19:03:08 +00:00
|
|
|
clev = tracy::FileWrite::Compression::Slow;
|
2020-07-17 19:47:51 +00:00
|
|
|
break;
|
|
|
|
case 'e':
|
2019-09-29 19:03:08 +00:00
|
|
|
clev = tracy::FileWrite::Compression::Extreme;
|
2020-07-17 19:47:51 +00:00
|
|
|
break;
|
|
|
|
case 'z':
|
|
|
|
clev = tracy::FileWrite::Compression::Zstd;
|
|
|
|
zstdLevel = atoi( optarg );
|
|
|
|
if( zstdLevel > ZSTD_maxCLevel() || zstdLevel < ZSTD_minCLevel() )
|
|
|
|
{
|
|
|
|
printf( "Available Zstd compression levels range: %i - %i\n", ZSTD_minCLevel(), ZSTD_maxCLevel() );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
break;
|
2021-05-15 13:50:20 +00:00
|
|
|
case 'd':
|
|
|
|
buildDict = true;
|
|
|
|
break;
|
2020-07-17 20:06:15 +00:00
|
|
|
case 's':
|
|
|
|
{
|
|
|
|
auto ptr = optarg;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
switch( *optarg )
|
|
|
|
{
|
|
|
|
case 'l':
|
|
|
|
events &= ~tracy::EventType::Locks;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
events &= ~tracy::EventType::Messages;
|
|
|
|
break;
|
|
|
|
case 'p':
|
|
|
|
events &= ~tracy::EventType::Plots;
|
|
|
|
break;
|
|
|
|
case 'M':
|
|
|
|
events &= ~tracy::EventType::Memory;
|
|
|
|
break;
|
|
|
|
case 'i':
|
|
|
|
events &= ~tracy::EventType::FrameImages;
|
|
|
|
break;
|
|
|
|
case 'c':
|
|
|
|
events &= ~tracy::EventType::ContextSwitches;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
events &= ~tracy::EventType::Samples;
|
|
|
|
break;
|
|
|
|
case 'C':
|
|
|
|
events &= ~tracy::EventType::SymbolCode;
|
|
|
|
break;
|
|
|
|
case 'S':
|
|
|
|
events &= ~tracy::EventType::SourceCache;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Usage();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while( *++optarg != '\0' );
|
|
|
|
break;
|
|
|
|
}
|
2020-07-17 19:47:51 +00:00
|
|
|
default:
|
2019-09-29 19:03:08 +00:00
|
|
|
Usage();
|
2020-07-17 19:47:51 +00:00
|
|
|
break;
|
2019-09-29 19:03:08 +00:00
|
|
|
}
|
2020-02-08 14:43:16 +00:00
|
|
|
}
|
2020-07-17 19:47:51 +00:00
|
|
|
if( argc - optind != 2 ) Usage();
|
2018-07-08 14:53:31 +00:00
|
|
|
|
2020-07-17 19:47:51 +00:00
|
|
|
const char* input = argv[optind];
|
|
|
|
const char* output = argv[optind+1];
|
2018-07-08 14:53:31 +00:00
|
|
|
|
2019-09-29 18:48:18 +00:00
|
|
|
printf( "Loading...\r" );
|
|
|
|
fflush( stdout );
|
2018-07-08 14:53:31 +00:00
|
|
|
auto f = std::unique_ptr<tracy::FileRead>( tracy::FileRead::Open( input ) );
|
|
|
|
if( !f )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Cannot open input file!\n" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
2020-02-08 12:35:36 +00:00
|
|
|
int64_t t;
|
2020-02-08 12:18:42 +00:00
|
|
|
float ratio;
|
2018-12-30 22:14:00 +00:00
|
|
|
int inVer;
|
2018-07-08 14:53:31 +00:00
|
|
|
{
|
2020-02-08 12:35:36 +00:00
|
|
|
const auto t0 = std::chrono::high_resolution_clock::now();
|
2020-07-17 20:06:15 +00:00
|
|
|
tracy::Worker worker( *f, (tracy::EventType::Type)events, false );
|
2018-12-30 22:14:00 +00:00
|
|
|
|
2019-03-13 00:28:42 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
|
|
|
while( !worker.AreSourceLocationZonesReady() ) std::this_thread::sleep_for( std::chrono::milliseconds( 10 ) );
|
|
|
|
#endif
|
|
|
|
|
2020-02-08 14:43:16 +00:00
|
|
|
auto w = std::unique_ptr<tracy::FileWrite>( tracy::FileWrite::Open( output, clev, zstdLevel ) );
|
2018-12-30 22:14:00 +00:00
|
|
|
if( !w )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Cannot open output file!\n" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
2019-09-29 18:48:18 +00:00
|
|
|
printf( "Saving... \r" );
|
|
|
|
fflush( stdout );
|
2021-05-15 13:50:20 +00:00
|
|
|
worker.Write( *w, buildDict );
|
2020-02-08 12:18:42 +00:00
|
|
|
w->Finish();
|
2020-02-08 12:35:36 +00:00
|
|
|
const auto t1 = std::chrono::high_resolution_clock::now();
|
2020-02-08 12:18:42 +00:00
|
|
|
const auto stats = w->GetCompressionStatistics();
|
|
|
|
ratio = 100.f * stats.second / stats.first;
|
2018-12-30 22:14:00 +00:00
|
|
|
inVer = worker.GetTraceVersion();
|
2020-02-08 12:35:36 +00:00
|
|
|
t = std::chrono::duration_cast<std::chrono::nanoseconds>( t1 - t0 ).count();
|
2018-07-08 14:53:31 +00:00
|
|
|
}
|
2018-07-29 13:37:45 +00:00
|
|
|
|
2018-12-30 22:14:00 +00:00
|
|
|
FILE* in = fopen( input, "rb" );
|
|
|
|
fseek( in, 0, SEEK_END );
|
2019-11-02 21:11:40 +00:00
|
|
|
const auto inSize = ftello64( in );
|
2018-12-30 22:14:00 +00:00
|
|
|
fclose( in );
|
|
|
|
|
|
|
|
FILE* out = fopen( output, "rb" );
|
|
|
|
fseek( out, 0, SEEK_END );
|
2019-11-02 21:11:40 +00:00
|
|
|
const auto outSize = ftello64( out );
|
2018-12-30 22:14:00 +00:00
|
|
|
fclose( out );
|
|
|
|
|
2020-02-08 12:35:36 +00:00
|
|
|
printf( "%s (%i.%i.%i) {%s} -> %s (%i.%i.%i) {%s, %.2f%%} %s, %.2f%% change\n",
|
2020-02-08 12:18:42 +00:00
|
|
|
input, inVer >> 16, ( inVer >> 8 ) & 0xFF, inVer & 0xFF, tracy::MemSizeToString( inSize ),
|
|
|
|
output, tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch, tracy::MemSizeToString( outSize ), ratio,
|
2020-02-08 12:35:36 +00:00
|
|
|
tracy::TimeToString( t ), float( outSize ) / inSize * 100 );
|
2018-07-08 14:53:31 +00:00
|
|
|
}
|
|
|
|
catch( const tracy::UnsupportedVersion& e )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "The file you are trying to open is from the future version.\n" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
|
|
|
catch( const tracy::NotTracyDump& e )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "The file you are trying to open is not a tracy dump.\n" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
2020-02-12 18:53:37 +00:00
|
|
|
catch( const tracy::FileReadError& e )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "The file you are trying to open cannot be mapped to memory.\n" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
2019-08-12 10:16:48 +00:00
|
|
|
catch( const tracy::LegacyVersion& e )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "The file you are trying to open is from a legacy version.\n" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
2018-07-08 14:53:31 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|