mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-26 16:04:34 +00:00
Gather file compression statistics.
This commit is contained in:
parent
068e752aa7
commit
6f554d7f00
@ -9,6 +9,7 @@
|
|||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <utility>
|
||||||
|
|
||||||
#include "TracyFileHeader.hpp"
|
#include "TracyFileHeader.hpp"
|
||||||
#include "../common/tracy_lz4.hpp"
|
#include "../common/tracy_lz4.hpp"
|
||||||
@ -36,16 +37,18 @@ public:
|
|||||||
|
|
||||||
~FileWrite()
|
~FileWrite()
|
||||||
{
|
{
|
||||||
if( m_offset > 0 )
|
if( m_offset > 0 ) WriteLz4Block();
|
||||||
{
|
|
||||||
WriteLz4Block();
|
|
||||||
}
|
|
||||||
fclose( m_file );
|
fclose( m_file );
|
||||||
|
|
||||||
if( m_stream ) LZ4_freeStream( m_stream );
|
if( m_stream ) LZ4_freeStream( m_stream );
|
||||||
if( m_streamHC ) LZ4_freeStreamHC( m_streamHC );
|
if( m_streamHC ) LZ4_freeStreamHC( m_streamHC );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Finish()
|
||||||
|
{
|
||||||
|
if( m_offset > 0 ) WriteLz4Block();
|
||||||
|
}
|
||||||
|
|
||||||
tracy_force_inline void Write( const void* ptr, size_t size )
|
tracy_force_inline void Write( const void* ptr, size_t size )
|
||||||
{
|
{
|
||||||
if( m_offset + size <= BufSize )
|
if( m_offset + size <= BufSize )
|
||||||
@ -58,6 +61,8 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::pair<size_t, size_t> GetCompressionStatistics() const { return std::make_pair( m_srcBytes, m_dstBytes ); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FileWrite( FILE* f, Compression comp )
|
FileWrite( FILE* f, Compression comp )
|
||||||
: m_stream( nullptr )
|
: m_stream( nullptr )
|
||||||
@ -66,6 +71,8 @@ private:
|
|||||||
, m_buf( m_bufData[0] )
|
, m_buf( m_bufData[0] )
|
||||||
, m_second( m_bufData[1] )
|
, m_second( m_bufData[1] )
|
||||||
, m_offset( 0 )
|
, m_offset( 0 )
|
||||||
|
, m_srcBytes( 0 )
|
||||||
|
, m_dstBytes( 0 )
|
||||||
{
|
{
|
||||||
switch( comp )
|
switch( comp )
|
||||||
{
|
{
|
||||||
@ -123,6 +130,10 @@ private:
|
|||||||
{
|
{
|
||||||
sz = LZ4_compress_HC_continue( m_streamHC, m_buf, lz4, m_offset, LZ4Size );
|
sz = LZ4_compress_HC_continue( m_streamHC, m_buf, lz4, m_offset, LZ4Size );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_srcBytes += m_offset;
|
||||||
|
m_dstBytes += sz;
|
||||||
|
|
||||||
fwrite( &sz, 1, sizeof( sz ), m_file );
|
fwrite( &sz, 1, sizeof( sz ), m_file );
|
||||||
fwrite( lz4, 1, sz, m_file );
|
fwrite( lz4, 1, sz, m_file );
|
||||||
m_offset = 0;
|
m_offset = 0;
|
||||||
@ -139,6 +150,8 @@ private:
|
|||||||
char* m_buf;
|
char* m_buf;
|
||||||
char* m_second;
|
char* m_second;
|
||||||
size_t m_offset;
|
size_t m_offset;
|
||||||
|
size_t m_srcBytes;
|
||||||
|
size_t m_dstBytes;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user