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"
|
2018-07-29 13:37:45 +00:00
|
|
|
#include "../../server/TracyVersion.hpp"
|
2018-07-08 14:53:31 +00:00
|
|
|
#include "../../server/TracyWorker.hpp"
|
|
|
|
|
|
|
|
void Usage()
|
|
|
|
{
|
2018-08-26 14:28:46 +00:00
|
|
|
printf( "Usage: update [--hc] input.tracy output.tracy\n\n" );
|
|
|
|
printf( " --hc: enable LZ4HC compression\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
|
|
|
|
|
2018-08-26 14:28:46 +00:00
|
|
|
bool hc = false;
|
|
|
|
|
|
|
|
if( argc != 3 && argc != 4 ) Usage();
|
|
|
|
if( argc == 4 )
|
|
|
|
{
|
|
|
|
if( strcmp( argv[1], "--hc" ) != 0 ) Usage();
|
|
|
|
hc = true;
|
|
|
|
argv++;
|
|
|
|
}
|
2018-07-08 14:53:31 +00:00
|
|
|
|
|
|
|
const char* input = argv[1];
|
|
|
|
const char* output = argv[2];
|
|
|
|
|
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
|
|
|
|
{
|
2018-12-30 22:14:00 +00:00
|
|
|
int inVer;
|
2018-07-08 14:53:31 +00:00
|
|
|
{
|
2018-12-30 22:14:00 +00:00
|
|
|
tracy::Worker worker( *f );
|
|
|
|
|
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
|
|
|
|
|
2018-12-30 22:14:00 +00:00
|
|
|
auto w = std::unique_ptr<tracy::FileWrite>( tracy::FileWrite::Open( output, hc ? tracy::FileWrite::Compression::Slow : tracy::FileWrite::Compression::Fast ) );
|
|
|
|
if( !w )
|
|
|
|
{
|
|
|
|
fprintf( stderr, "Cannot open output file!\n" );
|
|
|
|
exit( 1 );
|
|
|
|
}
|
2019-09-29 18:48:18 +00:00
|
|
|
printf( "Saving... \r" );
|
|
|
|
fflush( stdout );
|
2018-12-30 22:14:00 +00:00
|
|
|
worker.Write( *w );
|
|
|
|
inVer = worker.GetTraceVersion();
|
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 );
|
|
|
|
const auto inSize = ftell( in );
|
|
|
|
fclose( in );
|
|
|
|
|
|
|
|
FILE* out = fopen( output, "rb" );
|
|
|
|
fseek( out, 0, SEEK_END );
|
|
|
|
const auto outSize = ftell( out );
|
|
|
|
fclose( out );
|
|
|
|
|
2019-02-16 22:42:29 +00:00
|
|
|
printf( "%s (%i.%i.%i) {%zu KB} -> %s (%i.%i.%i) {%zu KB} %.2f%% size change\n", input, inVer >> 16, ( inVer >> 8 ) & 0xFF, inVer & 0xFF, size_t( inSize / 1024 ), output, tracy::Version::Major, tracy::Version::Minor, tracy::Version::Patch, size_t( outSize / 1024 ), 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 );
|
|
|
|
}
|
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;
|
|
|
|
}
|