Read and write whole ZoneEvent/GpuEvent data at once.

This commit is contained in:
Bartosz Taudul 2018-03-15 21:59:16 +01:00
parent e5796af196
commit 9dfa9c95cb
2 changed files with 9 additions and 24 deletions

View File

@ -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<ZoneEvent*> child;
};
enum { ZoneEventSize = sizeof( ZoneEvent ) };
static_assert( std::is_standard_layout<ZoneEvent>::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<GpuEvent*> child;
};
enum { GpuEventSize = sizeof( GpuEvent ) };
static_assert( std::is_standard_layout<GpuEvent>::value, "GpuEvent is not standard layout" );
#pragma pack()

View File

@ -1558,12 +1558,7 @@ void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec )
auto zone = m_slab.AllocInit<ZoneEvent>();
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<GpuEvent*>& vec )
auto zone = m_slab.AllocInit<GpuEvent>();
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<ZoneEvent*>& 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<GpuEvent*>& 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 );
}
}