mirror of
https://github.com/wolfpld/tracy.git
synced 2024-11-25 23:44:35 +00:00
Extract thread compression into a separate class.
This commit is contained in:
parent
94382f54ca
commit
21e7a4bb16
@ -135,6 +135,7 @@
|
||||
<ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyMemory.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyPrint.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyWorker.cpp" />
|
||||
<ClCompile Include="..\..\src\capture.cpp" />
|
||||
<ClCompile Include="..\..\src\getopt.c" />
|
||||
@ -159,6 +160,7 @@
|
||||
<ClInclude Include="..\..\..\server\TracyPopcnt.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyPrint.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracySlab.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyVector.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyWorker.hpp" />
|
||||
<ClInclude Include="..\..\..\server\tracy_flat_hash_map.hpp" />
|
||||
|
@ -39,6 +39,9 @@
|
||||
<ClCompile Include="..\..\..\server\TracyPrint.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
||||
@ -110,5 +113,8 @@
|
||||
<ClInclude Include="..\..\..\server\TracyPrint.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -117,6 +117,7 @@
|
||||
<ClCompile Include="..\..\..\server\TracyPrint.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyStorage.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyTexture.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyUserData.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyView.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyWorker.cpp" />
|
||||
@ -172,6 +173,7 @@
|
||||
<ClInclude Include="..\..\..\server\TracyStorage.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyStringDiscovery.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyTexture.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyUserData.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyVarArray.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyVector.hpp" />
|
||||
|
@ -105,6 +105,9 @@
|
||||
<ClCompile Include="..\..\..\server\TracyUserData.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
||||
@ -281,6 +284,9 @@
|
||||
<ClInclude Include="..\..\..\server\TracyUserData.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Natvis Include="DebugVis.natvis" />
|
||||
|
78
server/TracyThreadCompress.cpp
Normal file
78
server/TracyThreadCompress.cpp
Normal file
@ -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;
|
||||
}
|
||||
|
||||
}
|
61
server/TracyThreadCompress.hpp
Normal file
61
server/TracyThreadCompress.hpp
Normal file
@ -0,0 +1,61 @@
|
||||
#ifndef __TRACY__THREADCOMPRESS_HPP__
|
||||
#define __TRACY__THREADCOMPRESS_HPP__
|
||||
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "../common/TracyForceInline.hpp"
|
||||
#include "tracy_flat_hash_map.hpp"
|
||||
#include "TracyVector.hpp"
|
||||
|
||||
namespace tracy
|
||||
{
|
||||
|
||||
class FileRead;
|
||||
class FileWrite;
|
||||
|
||||
class ThreadCompress
|
||||
{
|
||||
public:
|
||||
ThreadCompress();
|
||||
|
||||
void InitZero();
|
||||
void Load( FileRead& f, int fileVer );
|
||||
void Save( FileWrite& f ) const;
|
||||
|
||||
tracy_force_inline uint16_t CompressThread( uint64_t thread )
|
||||
{
|
||||
if( m_threadLast.first == thread ) return m_threadLast.second;
|
||||
return CompressThreadReal( thread );
|
||||
}
|
||||
|
||||
tracy_force_inline uint64_t DecompressThread( uint16_t thread ) const
|
||||
{
|
||||
assert( thread < m_threadExpand.size() );
|
||||
return m_threadExpand[thread];
|
||||
}
|
||||
|
||||
tracy_force_inline uint16_t DecompressMustRaw( uint64_t thread ) const
|
||||
{
|
||||
auto it = m_threadMap.find( thread );
|
||||
assert( it != m_threadMap.end() );
|
||||
return it->second;
|
||||
}
|
||||
|
||||
tracy_force_inline bool Exists( uint64_t thread ) const
|
||||
{
|
||||
return m_threadMap.find( thread ) != m_threadMap.end();
|
||||
}
|
||||
|
||||
private:
|
||||
uint16_t CompressThreadReal( uint64_t thread );
|
||||
uint16_t CompressThreadNew( uint64_t thread );
|
||||
|
||||
flat_hash_map<uint64_t, uint16_t, nohash<uint64_t>> m_threadMap;
|
||||
Vector<uint64_t> m_threadExpand;
|
||||
std::pair<uint64_t, uint16_t> m_threadLast;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -250,7 +250,7 @@ Worker::Worker( const char* addr )
|
||||
, m_loadTime( 0 )
|
||||
{
|
||||
m_data.sourceLocationExpand.push_back( 0 );
|
||||
m_data.threadExpand.push_back( 0 );
|
||||
m_data.localThreadCompress.InitZero();
|
||||
m_data.callstackPayload.push_back( nullptr );
|
||||
|
||||
memset( m_gpuCtxMap, 0, sizeof( m_gpuCtxMap ) );
|
||||
@ -515,23 +515,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
}
|
||||
}
|
||||
|
||||
if( fileVer >= FileVersion( 0, 4, 4 ) )
|
||||
{
|
||||
f.Read( sz );
|
||||
m_data.threadExpand.reserve_and_use( sz );
|
||||
f.Read( m_data.threadExpand.data(), sizeof( uint64_t ) * sz );
|
||||
m_data.threadMap.reserve( sz );
|
||||
for( size_t i=0; i<sz; i++ )
|
||||
{
|
||||
m_data.threadMap.emplace( m_data.threadExpand[i], i );
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
f.Read( sz );
|
||||
m_data.threadExpand.reserve( sz );
|
||||
m_data.threadExpand.push_back( 0 );
|
||||
}
|
||||
m_data.localThreadCompress.Load( f, fileVer );
|
||||
|
||||
f.Read( sz );
|
||||
for( uint64_t i=0; i<sz; i++ )
|
||||
@ -1548,9 +1532,7 @@ Worker::Worker( FileRead& f, EventType::Type eventMask )
|
||||
if( !t->timeline.empty() )
|
||||
{
|
||||
// Don't touch thread compression cache in a thread.
|
||||
auto it = m_data.threadMap.find( t->id );
|
||||
assert( it != m_data.threadMap.end() );
|
||||
ProcessTimeline( t->timeline, it->second );
|
||||
ProcessTimeline( t->timeline, m_data.localThreadCompress.DecompressMustRaw( t->id ) );
|
||||
}
|
||||
}
|
||||
for( auto& v : m_data.sourceLocationZones )
|
||||
@ -1881,7 +1863,7 @@ const char* Worker::GetThreadString( uint64_t id ) const
|
||||
|
||||
bool Worker::IsThreadLocal( uint64_t id ) const
|
||||
{
|
||||
return m_data.threadMap.find( id ) != m_data.threadMap.end();
|
||||
return m_data.localThreadCompress.Exists( id );
|
||||
}
|
||||
|
||||
const SourceLocation& Worker::GetSourceLocation( int16_t srcloc ) const
|
||||
@ -2040,31 +2022,6 @@ const Worker::SourceLocationZones& Worker::GetZonesForSourceLocation( int16_t sr
|
||||
}
|
||||
#endif
|
||||
|
||||
uint16_t Worker::CompressThreadReal( uint64_t thread )
|
||||
{
|
||||
auto it = m_data.threadMap.find( thread );
|
||||
if( it != m_data.threadMap.end() )
|
||||
{
|
||||
m_data.threadLast.first = thread;
|
||||
m_data.threadLast.second = it->second;
|
||||
return it->second;
|
||||
}
|
||||
else
|
||||
{
|
||||
return CompressThreadNew( thread );
|
||||
}
|
||||
}
|
||||
|
||||
uint16_t Worker::CompressThreadNew( uint64_t thread )
|
||||
{
|
||||
auto sz = m_data.threadExpand.size();
|
||||
m_data.threadExpand.push_back( thread );
|
||||
m_data.threadMap.emplace( thread, sz );
|
||||
m_data.threadLast.first = thread;
|
||||
m_data.threadLast.second = sz;
|
||||
return sz;
|
||||
}
|
||||
|
||||
void Worker::Exec()
|
||||
{
|
||||
auto ShouldExit = [this]
|
||||
@ -4828,9 +4785,7 @@ void Worker::Write( FileWrite& f )
|
||||
f.Write( &ptr, sizeof( ptr ) );
|
||||
}
|
||||
|
||||
sz = m_data.threadExpand.size();
|
||||
f.Write( &sz, sizeof( sz ) );
|
||||
f.Write( m_data.threadExpand.data(), sz * sizeof( uint64_t ) );
|
||||
m_data.localThreadCompress.Save( f );
|
||||
|
||||
sz = m_data.sourceLocation.size();
|
||||
f.Write( &sz, sizeof( sz ) );
|
||||
@ -5044,7 +4999,7 @@ void Worker::Write( FileWrite& f )
|
||||
ctxValid.reserve( m_data.ctxSwitch.size() );
|
||||
for( auto it = m_data.ctxSwitch.begin(); it != m_data.ctxSwitch.end(); ++it )
|
||||
{
|
||||
if( m_data.threadMap.find( it->first ) != m_data.threadMap.end() )
|
||||
if( m_data.localThreadCompress.Exists( it->first ) )
|
||||
{
|
||||
ctxValid.emplace_back( it );
|
||||
}
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include "TracyEvent.hpp"
|
||||
#include "TracySlab.hpp"
|
||||
#include "TracyStringDiscovery.hpp"
|
||||
#include "TracyThreadCompress.hpp"
|
||||
#include "TracyVarArray.hpp"
|
||||
|
||||
namespace tracy
|
||||
@ -151,7 +152,6 @@ private:
|
||||
, baseTime( 0 )
|
||||
, lastTime( 0 )
|
||||
, frameOffset( 0 )
|
||||
, threadLast( std::numeric_limits<uint64_t>::max(), 0 )
|
||||
, threadDataLast( std::numeric_limits<uint64_t>::max(), nullptr )
|
||||
, ctxSwitchLast( std::numeric_limits<uint64_t>::max(), nullptr )
|
||||
{}
|
||||
@ -193,9 +193,7 @@ private:
|
||||
|
||||
flat_hash_map<uint32_t, LockMap*, nohash<uint32_t>> lockMap;
|
||||
|
||||
flat_hash_map<uint64_t, uint16_t, nohash<uint64_t>> threadMap;
|
||||
Vector<uint64_t> threadExpand;
|
||||
std::pair<uint64_t, uint16_t> threadLast;
|
||||
ThreadCompress localThreadCompress;
|
||||
std::pair<uint64_t, ThreadData*> threadDataLast;
|
||||
|
||||
Vector<Vector<ZoneEvent*>> zoneChildren;
|
||||
@ -359,12 +357,8 @@ public:
|
||||
bool AreSourceLocationZonesReady() const { return m_data.sourceLocationZonesReady; }
|
||||
#endif
|
||||
|
||||
tracy_force_inline uint16_t CompressThread( uint64_t thread )
|
||||
{
|
||||
if( m_data.threadLast.first == thread ) return m_data.threadLast.second;
|
||||
return CompressThreadReal( thread );
|
||||
}
|
||||
tracy_force_inline uint64_t DecompressThread( uint16_t thread ) const { assert( thread < m_data.threadExpand.size() ); return m_data.threadExpand[thread]; }
|
||||
tracy_force_inline uint16_t CompressThread( uint64_t thread ) { return m_data.localThreadCompress.CompressThread( thread ); }
|
||||
tracy_force_inline uint64_t DecompressThread( uint16_t thread ) const { return m_data.localThreadCompress.DecompressThread( thread ); }
|
||||
|
||||
std::shared_mutex& GetMbpsDataLock() { return m_mbpsData.lock; }
|
||||
const std::vector<float>& GetMbpsData() const { return m_mbpsData.mbps; }
|
||||
@ -508,8 +502,6 @@ private:
|
||||
void HandlePostponedPlots();
|
||||
|
||||
StringLocation StoreString( char* str, size_t sz );
|
||||
uint16_t CompressThreadReal( uint64_t thread );
|
||||
uint16_t CompressThreadNew( uint64_t thread );
|
||||
const ContextSwitch* const GetContextSwitchDataImpl( uint64_t thread );
|
||||
|
||||
tracy_force_inline void ReadTimeline( FileRead& f, ZoneEvent* zone, uint16_t thread, int64_t& refTime );
|
||||
|
@ -134,6 +134,7 @@
|
||||
<ClCompile Include="..\..\..\common\tracy_lz4.cpp" />
|
||||
<ClCompile Include="..\..\..\common\tracy_lz4hc.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyMemory.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp" />
|
||||
<ClCompile Include="..\..\..\server\TracyWorker.cpp" />
|
||||
<ClCompile Include="..\..\src\update.cpp" />
|
||||
</ItemGroup>
|
||||
@ -156,6 +157,7 @@
|
||||
<ClInclude Include="..\..\..\server\TracyMemory.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyPopcnt.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracySlab.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyVector.hpp" />
|
||||
<ClInclude Include="..\..\..\server\TracyWorker.hpp" />
|
||||
<ClInclude Include="..\..\..\server\tracy_flat_hash_map.hpp" />
|
||||
|
@ -33,6 +33,9 @@
|
||||
<ClCompile Include="..\..\..\common\tracy_lz4hc.cpp">
|
||||
<Filter>common</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="..\..\..\server\TracyThreadCompress.cpp">
|
||||
<Filter>server</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4.hpp">
|
||||
@ -98,5 +101,8 @@
|
||||
<ClInclude Include="..\..\..\common\tracy_lz4hc.hpp">
|
||||
<Filter>common</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="..\..\..\server\TracyThreadCompress.hpp">
|
||||
<Filter>server</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Reference in New Issue
Block a user