Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBartosz Taudul <wolf.pld@gmail.com>2019-08-19 23:56:02 +0300
committerBartosz Taudul <wolf.pld@gmail.com>2019-08-19 23:56:58 +0300
commit21e7a4bb160c1f2285e854dbc76e4b7b0b58ef31 (patch)
tree67ae1dccaa39dd34ec530ba97e0f99aeef886c89 /server/TracyThreadCompress.cpp
parent94382f54ca3249db823dc8f5b4134e34e695a60c (diff)
Extract thread compression into a separate class.
Diffstat (limited to 'server/TracyThreadCompress.cpp')
-rw-r--r--server/TracyThreadCompress.cpp78
1 files changed, 78 insertions, 0 deletions
diff --git a/server/TracyThreadCompress.cpp b/server/TracyThreadCompress.cpp
new file mode 100644
index 00000000..8da6b118
--- /dev/null
+++ b/server/TracyThreadCompress.cpp
@@ -0,0 +1,78 @@
+#include <limits>
+
+#include "TracyFileRead.hpp"
+#include "TracyFileWrite.hpp"
+#include "TracyThreadCompress.hpp"
+
+namespace tracy
+{
+
+ThreadCompress::ThreadCompress()
+ : m_threadLast( std::numeric_limits<uint64_t>::max(), 0 )
+{
+}
+
+void ThreadCompress::InitZero()
+{
+ assert( m_threadExpand.empty() );
+ m_threadExpand.push_back( 0 );
+}
+
+void ThreadCompress::Load( FileRead& f, int fileVer )
+{
+ assert( m_threadExpand.empty() );
+ assert( m_threadMap.empty() );
+
+ uint64_t sz;
+ if( fileVer >= FileVersion( 0, 4, 4 ) )
+ {
+ f.Read( sz );
+ m_threadExpand.reserve_and_use( sz );
+ f.Read( m_threadExpand.data(), sizeof( uint64_t ) * sz );
+ m_threadMap.reserve( sz );
+ for( size_t i=0; i<sz; i++ )
+ {
+ m_threadMap.emplace( m_threadExpand[i], i );
+ }
+ }
+ else
+ {
+ f.Read( sz );
+ m_threadExpand.reserve( sz );
+ m_threadExpand.push_back( 0 );
+ }
+}
+
+void ThreadCompress::Save( FileWrite& f ) const
+{
+ uint64_t sz = m_threadExpand.size();
+ f.Write( &sz, sizeof( sz ) );
+ f.Write( m_threadExpand.data(), sz * sizeof( uint64_t ) );
+}
+
+uint16_t ThreadCompress::CompressThreadReal( uint64_t thread )
+{
+ auto it = m_threadMap.find( thread );
+ if( it != m_threadMap.end() )
+ {
+ m_threadLast.first = thread;
+ m_threadLast.second = it->second;
+ return it->second;
+ }
+ else
+ {
+ return CompressThreadNew( thread );
+ }
+}
+
+uint16_t ThreadCompress::CompressThreadNew( uint64_t thread )
+{
+ auto sz = m_threadExpand.size();
+ m_threadExpand.push_back( thread );
+ m_threadMap.emplace( thread, sz );
+ m_threadLast.first = thread;
+ m_threadLast.second = sz;
+ return sz;
+}
+
+}