Extract source file caching functionality.

This commit is contained in:
Bartosz Taudul 2022-03-30 16:06:35 +02:00
parent 9ba7171c3d
commit e086488928
No known key found for this signature in database
GPG Key ID: B7FE2008B7575DF3
2 changed files with 14 additions and 8 deletions

View File

@ -8705,14 +8705,7 @@ void Worker::CacheSource( const StringRef& str )
const auto execTime = GetExecutableTime(); const auto execTime = GetExecutableTime();
if( SourceFileValid( file, execTime != 0 ? execTime : GetCaptureTime() ) ) if( SourceFileValid( file, execTime != 0 ? execTime : GetCaptureTime() ) )
{ {
FILE* f = fopen( file, "rb" ); CacheSourceFromFile( file );
fseek( f, 0, SEEK_END );
const auto sz = ftell( f );
fseek( f, 0, SEEK_SET );
auto src = (char*)m_slab.AllocBig( sz );
fread( src, 1, sz, f );
fclose( f );
m_data.sourceFileCache.emplace( file, MemoryBlock{ src, uint32_t( sz ) } );
} }
else if( execTime != 0 ) else if( execTime != 0 )
{ {
@ -8721,6 +8714,18 @@ void Worker::CacheSource( const StringRef& str )
} }
} }
void Worker::CacheSourceFromFile( const char* fn )
{
FILE* f = fopen( fn, "rb" );
fseek( f, 0, SEEK_END );
const auto sz = ftell( f );
fseek( f, 0, SEEK_SET );
auto src = (char*)m_slab.AllocBig( sz );
fread( src, 1, sz, f );
fclose( f );
m_data.sourceFileCache.emplace( fn, MemoryBlock{ src, uint32_t( sz ) } );
}
uint64_t Worker::GetSourceFileCacheSize() const uint64_t Worker::GetSourceFileCacheSize() const
{ {
uint64_t cnt = 0; uint64_t cnt = 0;

View File

@ -883,6 +883,7 @@ private:
const ContextSwitch* const GetContextSwitchDataImpl( uint64_t thread ); const ContextSwitch* const GetContextSwitchDataImpl( uint64_t thread );
void CacheSource( const StringRef& str ); void CacheSource( const StringRef& str );
void CacheSourceFromFile( const char* fn );
tracy_force_inline Vector<short_ptr<ZoneEvent>>& GetZoneChildrenMutable( int32_t idx ) { return m_data.zoneChildren[idx]; } tracy_force_inline Vector<short_ptr<ZoneEvent>>& GetZoneChildrenMutable( int32_t idx ) { return m_data.zoneChildren[idx]; }
tracy_force_inline Vector<short_ptr<GpuEvent>>& GetGpuChildrenMutable( int32_t idx ) { return m_data.gpuChildren[idx]; } tracy_force_inline Vector<short_ptr<GpuEvent>>& GetGpuChildrenMutable( int32_t idx ) { return m_data.gpuChildren[idx]; }