From b8cc3f59d64dbcfa2fdd018e81caa411a70623c3 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Sat, 14 Mar 2020 14:35:57 +0100 Subject: [PATCH] Count number of input and compressed frame image bytes. --- server/TracyTextureCompression.cpp | 9 +++++++-- server/TracyTextureCompression.hpp | 10 +++++++++- server/TracyView.cpp | 12 ++++++++++++ server/TracyWorker.hpp | 2 ++ 4 files changed, 30 insertions(+), 3 deletions(-) diff --git a/server/TracyTextureCompression.cpp b/server/TracyTextureCompression.cpp index 5bb33e7b..30e46920 100644 --- a/server/TracyTextureCompression.cpp +++ b/server/TracyTextureCompression.cpp @@ -21,7 +21,7 @@ TextureCompression::~TextureCompression() ZSTD_freeDCtx( m_dctx ); } -uint32_t TextureCompression::Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes ) const +uint32_t TextureCompression::Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes ) { const auto maxout = ZSTD_COMPRESSBOUND( inBytes ); if( bufsz < maxout ) @@ -31,7 +31,12 @@ uint32_t TextureCompression::Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& buf = new char[maxout]; } assert( ctx ); - return (uint32_t)ZSTD_compressCCtx( ctx, buf, maxout, image, inBytes, 3 ); + auto ret = (uint32_t)ZSTD_compressCCtx( ctx, buf, maxout, image, inBytes, 3 ); +#ifndef TRACY_NO_STATISTICS + m_inputBytes.fetch_add( inBytes, std::memory_order_relaxed ); + m_outputBytes.fetch_add( ret, std::memory_order_relaxed ); +#endif + return ret; } const char* TextureCompression::Unpack( const FrameImage& image ) diff --git a/server/TracyTextureCompression.hpp b/server/TracyTextureCompression.hpp index 5c5d8ebe..89b161bf 100644 --- a/server/TracyTextureCompression.hpp +++ b/server/TracyTextureCompression.hpp @@ -1,6 +1,8 @@ #ifndef __TRACY__TEXTURECOMPRESSION_HPP__ #define __TRACY__TEXTURECOMPRESSION_HPP__ +#include + #include #include @@ -20,7 +22,7 @@ public: TextureCompression(); ~TextureCompression(); - uint32_t Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes ) const; + uint32_t Pack( struct ZSTD_CCtx_s* ctx, char*& buf, size_t& bufsz, const char* image, uint32_t inBytes ); template const char* Pack( const char* image, uint32_t inBytes, uint32_t& csz, Slab& slab ) @@ -34,11 +36,17 @@ public: const char* Unpack( const FrameImage& image ); + uint64_t GetInputBytesCount() const { return m_inputBytes.load( std::memory_order_relaxed ); } + uint64_t GetOutputBytesCount() const { return m_outputBytes.load( std::memory_order_relaxed ); } + private: char* m_buf; size_t m_bufSize; struct ZSTD_CCtx_s* m_cctx; struct ZSTD_DCtx_s* m_dctx; + + std::atomic m_inputBytes { 0 }; + std::atomic m_outputBytes { 0 }; }; } diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 7915e111..c1abb01c 100644 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -11999,6 +11999,18 @@ void View::DrawInfo() } TextFocused( "Call stack samples:", RealToString( m_worker.GetCallstackSampleCount() ) ); TextFocused( "Frame images:", RealToString( ficnt ) ); + if( ficnt != 0 && ImGui::IsItemHovered() ) + { + const auto bytes = m_worker.GetTextureCompressionBytes(); + ImGui::BeginTooltip(); + TextFocused( "Input data:", MemSizeToString( bytes.first ) ); + TextFocused( "Compressed:", MemSizeToString( bytes.second ) ); + char buf[64]; + auto ptr = PrintFloat( buf, buf+62, 100. * bytes.second / bytes.first, 2 ); + memcpy( ptr, "%", 2 ); + TextFocused( "Ratio:", buf ); + ImGui::EndTooltip(); + } TextFocused( "Context switch regions:", RealToString( m_worker.GetContextSwitchCount() ) ); if( ImGui::IsItemHovered() ) { diff --git a/server/TracyWorker.hpp b/server/TracyWorker.hpp index e19167d2..554adf2b 100644 --- a/server/TracyWorker.hpp +++ b/server/TracyWorker.hpp @@ -493,6 +493,8 @@ public: const decltype(DataBlock::cpuTopology)& GetCpuTopology() const { return m_data.cpuTopology; } const CpuThreadTopology* GetThreadTopology( uint32_t cpuThread ) const; + std::pair GetTextureCompressionBytes() const { return std::make_pair( m_texcomp.GetInputBytesCount(), m_texcomp.GetOutputBytesCount() ); } + private: void Network(); void Exec();