From 9dfa9c95cb22e38254cdd81cb25ab6fd84ba8ff6 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Thu, 15 Mar 2018 21:59:16 +0100 Subject: [PATCH] Read and write whole ZoneEvent/GpuEvent data at once. --- server/TracyEvent.hpp | 7 +++++-- server/TracyWorker.cpp | 26 ++++---------------------- 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index dbf3d7b8..062bb9a9 100644 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -79,13 +79,14 @@ struct ZoneEvent int32_t srcloc; int8_t cpu_start; int8_t cpu_end; - StringIdx text; + + // This must be last. All above is read/saved as-is. Vector child; }; enum { ZoneEventSize = sizeof( ZoneEvent ) }; - +static_assert( std::is_standard_layout::value, "ZoneEvent is not standard layout" ); struct LockEvent { @@ -129,10 +130,12 @@ struct GpuEvent int64_t gpuEnd; int32_t srcloc; + // This must be last. All above is read/saved as-is. Vector child; }; enum { GpuEventSize = sizeof( GpuEvent ) }; +static_assert( std::is_standard_layout::value, "GpuEvent is not standard layout" ); #pragma pack() diff --git a/server/TracyWorker.cpp b/server/TracyWorker.cpp index 9ed0f17a..00699f86 100644 --- a/server/TracyWorker.cpp +++ b/server/TracyWorker.cpp @@ -1558,12 +1558,7 @@ void Worker::ReadTimeline( FileRead& f, Vector& vec ) auto zone = m_slab.AllocInit(); vec.push_back_no_space_check( zone ); - f.Read( &zone->start, sizeof( zone->start ) ); - f.Read( &zone->end, sizeof( zone->end ) ); - f.Read( &zone->srcloc, sizeof( zone->srcloc ) ); - f.Read( &zone->cpu_start, sizeof( zone->cpu_start ) ); - f.Read( &zone->cpu_end, sizeof( zone->cpu_end ) ); - f.Read( &zone->text, sizeof( zone->text ) ); + f.Read( zone, sizeof( ZoneEvent ) - sizeof( ZoneEvent::child ) ); ReadTimeline( f, zone->child ); } } @@ -1579,11 +1574,7 @@ void Worker::ReadTimeline( FileRead& f, Vector& vec ) auto zone = m_slab.AllocInit(); vec.push_back_no_space_check( zone ); - f.Read( &zone->cpuStart, sizeof( zone->cpuStart ) ); - f.Read( &zone->cpuEnd, sizeof( zone->cpuEnd ) ); - f.Read( &zone->gpuStart, sizeof( zone->gpuStart ) ); - f.Read( &zone->gpuEnd, sizeof( zone->gpuEnd ) ); - f.Read( &zone->srcloc, sizeof( zone->srcloc ) ); + f.Read( zone, sizeof( GpuEvent ) - sizeof( GpuEvent::child ) ); ReadTimeline( f, zone->child ); } } @@ -1741,12 +1732,7 @@ void Worker::WriteTimeline( FileWrite& f, const Vector& vec ) for( auto& v : vec ) { - f.Write( &v->start, sizeof( v->start ) ); - f.Write( &v->end, sizeof( v->end ) ); - f.Write( &v->srcloc, sizeof( v->srcloc ) ); - f.Write( &v->cpu_start, sizeof( v->cpu_start ) ); - f.Write( &v->cpu_end, sizeof( v->cpu_end ) ); - f.Write( &v->text, sizeof( v->text ) ); + f.Write( v, sizeof( ZoneEvent ) - sizeof( ZoneEvent::child ) ); WriteTimeline( f, v->child ); } } @@ -1758,11 +1744,7 @@ void Worker::WriteTimeline( FileWrite& f, const Vector& vec ) for( auto& v : vec ) { - f.Write( &v->cpuStart, sizeof( v->cpuStart ) ); - f.Write( &v->cpuEnd, sizeof( v->cpuEnd ) ); - f.Write( &v->gpuStart, sizeof( v->gpuStart ) ); - f.Write( &v->gpuEnd, sizeof( v->gpuEnd ) ); - f.Write( &v->srcloc, sizeof( v->srcloc ) ); + f.Write( v, sizeof( GpuEvent ) - sizeof( GpuEvent::child ) ); WriteTimeline( f, v->child ); } }