Adapt WriteTimeline() to magic vectors.

This commit is contained in:
Bartosz Taudul 2019-11-10 16:34:38 +01:00
parent 4eb8acc973
commit 672093cf0e
2 changed files with 59 additions and 27 deletions

View File

@ -5855,28 +5855,42 @@ void Worker::WriteTimeline( FileWrite& f, const Vector<short_ptr<ZoneEvent>>& ve
{
uint64_t sz = vec.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : vec )
if( vec.is_magic() )
{
int16_t srcloc = v->SrcLoc();
f.Write( &srcloc, sizeof( srcloc ) );
int64_t start = v->Start();
WriteTimeOffset( f, refTime, start );
f.Write( &v->text, sizeof( v->text ) );
f.Write( &v->callstack, sizeof( v->callstack ) );
f.Write( &v->name, sizeof( v->name ) );
WriteTimelineImpl<VectorAdapterDirect<ZoneEvent>>( f, *(Vector<ZoneEvent>*)( &vec ), refTime );
}
else
{
WriteTimelineImpl<VectorAdapterPointer<ZoneEvent>>( f, vec, refTime );
}
}
if( v->Child() < 0 )
template<typename Adapter, typename V>
void Worker::WriteTimelineImpl( FileWrite& f, const V& vec, int64_t& refTime )
{
Adapter a;
for( auto& val : vec )
{
auto& v = a(val);
int16_t srcloc = v.SrcLoc();
f.Write( &srcloc, sizeof( srcloc ) );
int64_t start = v.Start();
WriteTimeOffset( f, refTime, start );
f.Write( &v.text, sizeof( v.text ) );
f.Write( &v.callstack, sizeof( v.callstack ) );
f.Write( &v.name, sizeof( v.name ) );
if( v.Child() < 0 )
{
sz = 0;
const uint64_t sz = 0;
f.Write( &sz, sizeof( sz ) );
}
else
{
WriteTimeline( f, GetZoneChildren( v->Child() ), refTime );
WriteTimeline( f, GetZoneChildren( v.Child() ), refTime );
}
WriteTimeOffset( f, refTime, v->End() );
WriteTimeOffset( f, refTime, v.End() );
}
}
@ -5884,29 +5898,43 @@ void Worker::WriteTimeline( FileWrite& f, const Vector<short_ptr<GpuEvent>>& vec
{
uint64_t sz = vec.size();
f.Write( &sz, sizeof( sz ) );
for( auto& v : vec )
if( vec.is_magic() )
{
WriteTimeOffset( f, refTime, v->CpuStart() );
WriteTimeOffset( f, refGpuTime, v->GpuStart() );
const int16_t srcloc = v->SrcLoc();
WriteTimelineImpl<VectorAdapterDirect<GpuEvent>>( f, *(Vector<GpuEvent>*)( &vec ), refTime, refGpuTime );
}
else
{
WriteTimelineImpl<VectorAdapterPointer<GpuEvent>>( f, vec, refTime, refGpuTime );
}
}
template<typename Adapter, typename V>
void Worker::WriteTimelineImpl( FileWrite& f, const V& vec, int64_t& refTime, int64_t& refGpuTime )
{
Adapter a;
for( auto& val : vec )
{
auto& v = a(val);
WriteTimeOffset( f, refTime, v.CpuStart() );
WriteTimeOffset( f, refGpuTime, v.GpuStart() );
const int16_t srcloc = v.SrcLoc();
f.Write( &srcloc, sizeof( srcloc ) );
f.Write( &v->callstack, sizeof( v->callstack ) );
const uint16_t thread = v->Thread();
f.Write( &v.callstack, sizeof( v.callstack ) );
const uint16_t thread = v.Thread();
f.Write( &thread, sizeof( thread ) );
if( v->Child() < 0 )
if( v.Child() < 0 )
{
sz = 0;
const uint64_t sz = 0;
f.Write( &sz, sizeof( sz ) );
}
else
{
WriteTimeline( f, GetGpuChildren( v->Child() ), refTime, refGpuTime );
WriteTimeline( f, GetGpuChildren( v.Child() ), refTime, refGpuTime );
}
WriteTimeOffset( f, refTime, v->CpuEnd() );
WriteTimeOffset( f, refGpuTime, v->GpuEnd() );
WriteTimeOffset( f, refTime, v.CpuEnd() );
WriteTimeOffset( f, refGpuTime, v.GpuEnd() );
}
}

View File

@ -589,8 +589,12 @@ private:
void ReadTimeline( FileRead& f, Vector<short_ptr<GpuEvent>>& vec, uint64_t size, int64_t& refTime, int64_t& refGpuTime, int32_t& childIdx );
void ReadTimelinePre0510( FileRead& f, Vector<short_ptr<GpuEvent>>& vec, uint64_t size, int64_t& refTime, int64_t& refGpuTime, int fileVer );
void WriteTimeline( FileWrite& f, const Vector<short_ptr<ZoneEvent>>& vec, int64_t& refTime );
void WriteTimeline( FileWrite& f, const Vector<short_ptr<GpuEvent>>& vec, int64_t& refTime, int64_t& refGpuTime );
tracy_force_inline void WriteTimeline( FileWrite& f, const Vector<short_ptr<ZoneEvent>>& vec, int64_t& refTime );
tracy_force_inline void WriteTimeline( FileWrite& f, const Vector<short_ptr<GpuEvent>>& vec, int64_t& refTime, int64_t& refGpuTime );
template<typename Adapter, typename V>
void WriteTimelineImpl( FileWrite& f, const V& vec, int64_t& refTime );
template<typename Adapter, typename V>
void WriteTimelineImpl( FileWrite& f, const V& vec, int64_t& refTime, int64_t& refGpuTime );
int64_t TscTime( int64_t tsc ) { return int64_t( tsc * m_timerMul ); }
int64_t TscTime( uint64_t tsc ) { return int64_t( tsc * m_timerMul ); }