Allow specifying FileWrite compression level.

Note that extreme compression level is not exposed in the update
utility.

% time update.exe long.tracy out.tracy
long.tracy (0.3.201) -> out.tracy (0.3.204)
update.exe long.tracy   0,00s user 0,00s system 0% cpu 13,464 total
% time update.exe --hc long.tracy outhc.tracy
long.tracy (0.3.201) -> outhc.tracy (0.3.204)
update.exe --hc long.trac  0,00s user 0,00s system 0% cpu 3:46,23 total
% ls -l long.tracy out*
-rw-r--r-- 1 wolf Brak 1621546031 07-30 22:51 long.tracy
-rw-r--r-- 1 wolf Brak 1621579467 08-26 16:44 out.tracy
-rw-r--r-- 1 wolf Brak 1397610127 08-26 16:48 outhc.tracy
This commit is contained in:
Bartosz Taudul 2018-08-26 16:42:44 +02:00
parent 39fd3b3a6f
commit a5b99b54c8
2 changed files with 25 additions and 9 deletions

View File

@ -2,6 +2,7 @@
#define __TRACYFILEWRITE_HPP__
#include <algorithm>
#include <assert.h>
#include <stdio.h>
#include <string.h>
@ -16,10 +17,17 @@ namespace tracy
class FileWrite
{
public:
static FileWrite* Open( const char* fn, bool hc = false )
enum class Compression
{
Fast,
Slow,
Extreme
};
static FileWrite* Open( const char* fn, Compression comp = Compression::Fast )
{
auto f = fopen( fn, "wb" );
return f ? new FileWrite( f, hc ) : nullptr;
return f ? new FileWrite( f, comp ) : nullptr;
}
~FileWrite()
@ -47,7 +55,7 @@ public:
}
private:
FileWrite( FILE* f, bool hc )
FileWrite( FILE* f, Compression comp )
: m_stream( nullptr )
, m_streamHC( nullptr )
, m_file( f )
@ -55,13 +63,21 @@ private:
, m_second( m_bufData[1] )
, m_offset( 0 )
{
if( hc )
{
m_streamHC = LZ4_createStreamHC();
}
else
switch( comp )
{
case Compression::Fast:
m_stream = LZ4_createStream();
break;
case Compression::Slow:
m_streamHC = LZ4_createStreamHC();
break;
case Compression::Extreme:
m_streamHC = LZ4_createStreamHC();
LZ4_resetStreamHC( m_streamHC, LZ4HC_CLEVEL_OPT_MIN );
break;
default:
assert( false );
break;
}
fwrite( Lz4Header, 1, sizeof( Lz4Header ), m_file );

View File

@ -52,7 +52,7 @@ int main( int argc, char** argv )
{
tracy::Worker worker( *f );
auto w = std::unique_ptr<tracy::FileWrite>( tracy::FileWrite::Open( output, hc ) );
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" );