From 9dea830f989b7f24f4c9237559ad23a28e61ccb5 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 31 May 2024 19:24:32 +0200 Subject: [PATCH] Move file compression enum out of FileWrite. --- import-chrome/src/import-chrome.cpp | 2 +- import-fuchsia/src/import-fuchsia.cpp | 2 +- profiler/src/profiler/TracyView.cpp | 8 +++---- profiler/src/profiler/TracyView.hpp | 2 +- server/TracyFileWrite.hpp | 30 +++++++++++++-------------- update/src/update.cpp | 8 +++---- 6 files changed, 26 insertions(+), 26 deletions(-) diff --git a/import-chrome/src/import-chrome.cpp b/import-chrome/src/import-chrome.cpp index 4421570c..19051cc5 100644 --- a/import-chrome/src/import-chrome.cpp +++ b/import-chrome/src/import-chrome.cpp @@ -50,7 +50,7 @@ int main( int argc, char** argv ) } #endif - tracy::FileWrite::Compression clev = tracy::FileWrite::Compression::Fast; + tracy::FileCompression clev = tracy::FileCompression::Fast; if( argc != 3 ) Usage(); diff --git a/import-fuchsia/src/import-fuchsia.cpp b/import-fuchsia/src/import-fuchsia.cpp index b375273d..83659f40 100644 --- a/import-fuchsia/src/import-fuchsia.cpp +++ b/import-fuchsia/src/import-fuchsia.cpp @@ -381,7 +381,7 @@ int main(int argc, char **argv) { } #endif - tracy::FileWrite::Compression clev = tracy::FileWrite::Compression::Fast; + tracy::FileCompression clev = tracy::FileCompression::Fast; if (argc != 3) Usage(); diff --git a/profiler/src/profiler/TracyView.cpp b/profiler/src/profiler/TracyView.cpp index 2a8e7293..7a7a7dcf 100644 --- a/profiler/src/profiler/TracyView.cpp +++ b/profiler/src/profiler/TracyView.cpp @@ -551,7 +551,7 @@ bool View::Draw() ImGui::PopFont(); ImGui::Separator(); - static FileWrite::Compression comp = FileWrite::Compression::Fast; + static FileCompression comp = FileCompression::Fast; static int zlvl = 6; ImGui::TextUnformatted( ICON_FA_FILE_ZIPPER " Trace compression" ); ImGui::SameLine(); @@ -560,7 +560,7 @@ bool View::Draw() int idx = 0; while( CompressionName[idx] ) { - if( ImGui::RadioButton( CompressionName[idx], (int)comp == idx ) ) comp = (FileWrite::Compression)idx; + if( ImGui::RadioButton( CompressionName[idx], (int)comp == idx ) ) comp = (FileCompression)idx; ImGui::SameLine(); TextDisabledUnformatted( CompressionDesc[idx] ); idx++; @@ -572,7 +572,7 @@ bool View::Draw() ImGui::Indent(); if( ImGui::SliderInt( "##zstd", &zlvl, 1, 22, "%d", ImGuiSliderFlags_AlwaysClamp ) ) { - comp = FileWrite::Compression::Zstd; + comp = FileCompression::Zstd; } ImGui::Unindent(); @@ -1340,7 +1340,7 @@ void View::DrawSourceTooltip( const char* filename, uint32_t srcline, int before ImGui::PopStyleVar(); } -bool View::Save( const char* fn, FileWrite::Compression comp, int zlevel, bool buildDict ) +bool View::Save( const char* fn, FileCompression comp, int zlevel, bool buildDict ) { std::unique_ptr f( FileWrite::Open( fn, comp, zlevel ) ); if( !f ) return false; diff --git a/profiler/src/profiler/TracyView.hpp b/profiler/src/profiler/TracyView.hpp index 30190693..55289f27 100644 --- a/profiler/src/profiler/TracyView.hpp +++ b/profiler/src/profiler/TracyView.hpp @@ -367,7 +367,7 @@ private: void CalcZoneTimeDataImpl( const V& children, const ContextSwitch* ctx, unordered_flat_map& data, int64_t& ztime ); void SetPlaybackFrame( uint32_t idx ); - bool Save( const char* fn, FileWrite::Compression comp, int zlevel, bool buildDict ); + bool Save( const char* fn, FileCompression comp, int zlevel, bool buildDict ); void Attention( bool& alreadyDone ); void UpdateTitle(); diff --git a/server/TracyFileWrite.hpp b/server/TracyFileWrite.hpp index bf247185..d01bc1ff 100644 --- a/server/TracyFileWrite.hpp +++ b/server/TracyFileWrite.hpp @@ -20,18 +20,18 @@ namespace tracy { +enum class FileCompression +{ + Fast, + Slow, + Extreme, + Zstd +}; + class FileWrite { public: - enum class Compression - { - Fast, - Slow, - Extreme, - Zstd - }; - - static FileWrite* Open( const char* fn, Compression comp = Compression::Fast, int level = 1 ) + static FileWrite* Open( const char* fn, FileCompression comp = FileCompression::Fast, int level = 1 ) { auto f = fopen( fn, "wb" ); return f ? new FileWrite( f, comp, level ) : nullptr; @@ -67,7 +67,7 @@ public: std::pair GetCompressionStatistics() const { return std::make_pair( m_srcBytes, m_dstBytes ); } private: - FileWrite( FILE* f, Compression comp, int level ) + FileWrite( FILE* f, FileCompression comp, int level ) : m_stream( nullptr ) , m_streamHC( nullptr ) , m_streamZstd( nullptr ) @@ -80,17 +80,17 @@ private: { switch( comp ) { - case Compression::Fast: + case FileCompression::Fast: m_stream = LZ4_createStream(); break; - case Compression::Slow: + case FileCompression::Slow: m_streamHC = LZ4_createStreamHC(); break; - case Compression::Extreme: + case FileCompression::Extreme: m_streamHC = LZ4_createStreamHC(); LZ4_resetStreamHC( m_streamHC, LZ4HC_CLEVEL_MAX ); break; - case Compression::Zstd: + case FileCompression::Zstd: m_streamZstd = ZSTD_createCStream(); ZSTD_CCtx_setParameter( m_streamZstd, ZSTD_c_compressionLevel, level ); ZSTD_CCtx_setParameter( m_streamZstd, ZSTD_c_contentSizeFlag, 0 ); @@ -100,7 +100,7 @@ private: break; } - if( comp == Compression::Zstd ) + if( comp == FileCompression::Zstd ) { fwrite( ZstdHeader, 1, sizeof( ZstdHeader ), m_file ); } diff --git a/update/src/update.cpp b/update/src/update.cpp index f3cedb58..a9bcf06a 100644 --- a/update/src/update.cpp +++ b/update/src/update.cpp @@ -50,7 +50,7 @@ int main( int argc, char** argv ) } #endif - tracy::FileWrite::Compression clev = tracy::FileWrite::Compression::Fast; + tracy::FileCompression clev = tracy::FileCompression::Fast; uint32_t events = tracy::EventType::All; int zstdLevel = 1; bool buildDict = false; @@ -64,13 +64,13 @@ int main( int argc, char** argv ) switch( c ) { case 'h': - clev = tracy::FileWrite::Compression::Slow; + clev = tracy::FileCompression::Slow; break; case 'e': - clev = tracy::FileWrite::Compression::Extreme; + clev = tracy::FileCompression::Extreme; break; case 'z': - clev = tracy::FileWrite::Compression::Zstd; + clev = tracy::FileCompression::Zstd; zstdLevel = atoi( optarg ); if( zstdLevel > ZSTD_maxCLevel() || zstdLevel < ZSTD_minCLevel() ) {