2019-01-19 11:03:30 +00:00
|
|
|
#ifdef _WIN32
|
2018-02-22 11:10:15 +00:00
|
|
|
# include <winsock2.h>
|
|
|
|
#endif
|
|
|
|
|
2019-01-19 11:03:30 +00:00
|
|
|
#ifdef _WIN32
|
2018-12-18 15:52:05 +00:00
|
|
|
# include <malloc.h>
|
|
|
|
#else
|
|
|
|
# include <alloca.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <cctype>
|
2018-02-22 11:10:15 +00:00
|
|
|
#include <chrono>
|
2018-02-13 13:57:47 +00:00
|
|
|
#include <mutex>
|
2018-06-22 14:37:54 +00:00
|
|
|
#include <string.h>
|
2019-01-20 18:11:48 +00:00
|
|
|
#include <inttypes.h>
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-07-17 15:29:48 +00:00
|
|
|
#if ( defined _MSC_VER && _MSVC_LANG >= 201703L ) || __cplusplus >= 201703L
|
2018-07-17 16:10:49 +00:00
|
|
|
# if __has_include(<execution>)
|
|
|
|
# include <execution>
|
|
|
|
# else
|
|
|
|
# define MY_LIBCPP_SUCKS
|
|
|
|
# endif
|
2018-05-12 20:41:18 +00:00
|
|
|
#else
|
|
|
|
# define MY_LIBCPP_SUCKS
|
|
|
|
#endif
|
|
|
|
|
2018-07-17 16:29:07 +00:00
|
|
|
#ifdef MY_LIBCPP_SUCKS
|
2018-07-17 16:10:49 +00:00
|
|
|
# include "tracy_pdqsort.h"
|
|
|
|
#endif
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
#include "../common/TracyProtocol.hpp"
|
|
|
|
#include "../common/TracySystem.hpp"
|
|
|
|
#include "TracyFileRead.hpp"
|
|
|
|
#include "TracyFileWrite.hpp"
|
2018-07-29 12:20:44 +00:00
|
|
|
#include "TracyVersion.hpp"
|
2018-02-13 13:57:47 +00:00
|
|
|
#include "TracyWorker.hpp"
|
|
|
|
|
2018-03-20 14:44:13 +00:00
|
|
|
#include "tracy_flat_hash_map.hpp"
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
namespace tracy
|
|
|
|
{
|
|
|
|
|
2019-03-03 15:39:13 +00:00
|
|
|
static inline CallstackFrameId PackPointer( uint64_t ptr )
|
|
|
|
{
|
|
|
|
assert( ( ( ptr & 0x4000000000000000 ) << 1 ) == ( ptr & 0x8000000000000000 ) );
|
|
|
|
CallstackFrameId id;
|
|
|
|
id.idx = ptr;
|
|
|
|
id.sel = 0;
|
|
|
|
return id;
|
|
|
|
}
|
|
|
|
|
2018-04-21 11:45:48 +00:00
|
|
|
static constexpr int FileVersion( uint8_t h5, uint8_t h6, uint8_t h7 )
|
|
|
|
{
|
|
|
|
return ( h5 << 16 ) | ( h6 << 8 ) | h7;
|
|
|
|
}
|
|
|
|
|
2018-07-29 12:20:44 +00:00
|
|
|
static const uint8_t FileHeader[8] { 't', 'r', 'a', 'c', 'y', Version::Major, Version::Minor, Version::Patch };
|
2018-04-21 12:18:13 +00:00
|
|
|
enum { FileHeaderMagic = 5 };
|
2018-07-29 12:20:44 +00:00
|
|
|
static const int CurrentVersion = FileVersion( Version::Major, Version::Minor, Version::Patch );
|
2018-04-21 12:18:13 +00:00
|
|
|
|
2018-04-21 13:42:08 +00:00
|
|
|
|
|
|
|
static void UpdateLockCountLockable( LockMap& lockmap, size_t pos )
|
|
|
|
{
|
|
|
|
auto& timeline = lockmap.timeline;
|
2019-05-12 14:17:17 +00:00
|
|
|
bool isContended = lockmap.isContended;
|
2018-04-21 13:42:08 +00:00
|
|
|
uint8_t lockingThread;
|
|
|
|
uint8_t lockCount;
|
|
|
|
uint64_t waitList;
|
|
|
|
|
|
|
|
if( pos == 0 )
|
|
|
|
{
|
|
|
|
lockingThread = 0;
|
|
|
|
lockCount = 0;
|
|
|
|
waitList = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-16 13:18:43 +00:00
|
|
|
const auto& tl = timeline[pos-1];
|
|
|
|
lockingThread = tl.lockingThread;
|
|
|
|
lockCount = tl.lockCount;
|
|
|
|
waitList = tl.waitList;
|
2018-04-21 13:42:08 +00:00
|
|
|
}
|
|
|
|
const auto end = timeline.size();
|
|
|
|
|
|
|
|
while( pos != end )
|
|
|
|
{
|
2019-03-16 13:18:43 +00:00
|
|
|
auto& tl = timeline[pos];
|
|
|
|
const auto tbit = uint64_t( 1 ) << tl.ptr->thread;
|
|
|
|
switch( (LockEvent::Type)tl.ptr->type )
|
2018-04-21 13:42:08 +00:00
|
|
|
{
|
|
|
|
case LockEvent::Type::Wait:
|
|
|
|
waitList |= tbit;
|
|
|
|
break;
|
|
|
|
case LockEvent::Type::Obtain:
|
|
|
|
assert( lockCount < std::numeric_limits<uint8_t>::max() );
|
|
|
|
assert( ( waitList & tbit ) != 0 );
|
|
|
|
waitList &= ~tbit;
|
2019-03-16 13:18:43 +00:00
|
|
|
lockingThread = tl.ptr->thread;
|
2018-04-21 13:42:08 +00:00
|
|
|
lockCount++;
|
|
|
|
break;
|
|
|
|
case LockEvent::Type::Release:
|
|
|
|
assert( lockCount > 0 );
|
|
|
|
lockCount--;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-03-16 13:18:43 +00:00
|
|
|
tl.lockingThread = lockingThread;
|
|
|
|
tl.waitList = waitList;
|
|
|
|
tl.lockCount = lockCount;
|
2019-05-12 14:17:17 +00:00
|
|
|
if( !isContended ) isContended = lockCount != 0 && waitList != 0;
|
2018-04-21 13:42:08 +00:00
|
|
|
pos++;
|
|
|
|
}
|
2019-05-12 14:17:17 +00:00
|
|
|
|
|
|
|
lockmap.isContended = isContended;
|
2018-04-21 13:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateLockCountSharedLockable( LockMap& lockmap, size_t pos )
|
|
|
|
{
|
|
|
|
auto& timeline = lockmap.timeline;
|
2019-05-12 14:17:17 +00:00
|
|
|
bool isContended = lockmap.isContended;
|
2018-04-21 13:42:08 +00:00
|
|
|
uint8_t lockingThread;
|
|
|
|
uint8_t lockCount;
|
|
|
|
uint64_t waitShared;
|
|
|
|
uint64_t waitList;
|
|
|
|
uint64_t sharedList;
|
|
|
|
|
|
|
|
if( pos == 0 )
|
|
|
|
{
|
|
|
|
lockingThread = 0;
|
|
|
|
lockCount = 0;
|
|
|
|
waitShared = 0;
|
|
|
|
waitList = 0;
|
|
|
|
sharedList = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-16 13:18:43 +00:00
|
|
|
const auto& tl = timeline[pos-1];
|
|
|
|
const auto tlp = (LockEventShared*)tl.ptr;
|
|
|
|
lockingThread = tl.lockingThread;
|
|
|
|
lockCount = tl.lockCount;
|
|
|
|
waitShared = tlp->waitShared;
|
|
|
|
waitList = tl.waitList;
|
|
|
|
sharedList = tlp->sharedList;
|
2018-04-21 13:42:08 +00:00
|
|
|
}
|
|
|
|
const auto end = timeline.size();
|
|
|
|
|
|
|
|
// ObtainShared and ReleaseShared should assert on lockCount == 0, but
|
2019-05-12 13:59:53 +00:00
|
|
|
// due to the async retrieval of data from threads that's not possible.
|
2018-04-21 13:42:08 +00:00
|
|
|
while( pos != end )
|
|
|
|
{
|
2019-03-16 13:18:43 +00:00
|
|
|
auto& tl = timeline[pos];
|
|
|
|
const auto tlp = (LockEventShared*)tl.ptr;
|
|
|
|
const auto tbit = uint64_t( 1 ) << tlp->thread;
|
|
|
|
switch( (LockEvent::Type)tlp->type )
|
2018-04-21 13:42:08 +00:00
|
|
|
{
|
|
|
|
case LockEvent::Type::Wait:
|
|
|
|
waitList |= tbit;
|
|
|
|
break;
|
|
|
|
case LockEvent::Type::WaitShared:
|
|
|
|
waitShared |= tbit;
|
|
|
|
break;
|
|
|
|
case LockEvent::Type::Obtain:
|
|
|
|
assert( lockCount < std::numeric_limits<uint8_t>::max() );
|
|
|
|
assert( ( waitList & tbit ) != 0 );
|
|
|
|
waitList &= ~tbit;
|
2019-03-16 13:18:43 +00:00
|
|
|
lockingThread = tlp->thread;
|
2018-04-21 13:42:08 +00:00
|
|
|
lockCount++;
|
|
|
|
break;
|
|
|
|
case LockEvent::Type::Release:
|
|
|
|
assert( lockCount > 0 );
|
|
|
|
lockCount--;
|
|
|
|
break;
|
|
|
|
case LockEvent::Type::ObtainShared:
|
|
|
|
assert( ( waitShared & tbit ) != 0 );
|
|
|
|
assert( ( sharedList & tbit ) == 0 );
|
|
|
|
waitShared &= ~tbit;
|
|
|
|
sharedList |= tbit;
|
|
|
|
break;
|
|
|
|
case LockEvent::Type::ReleaseShared:
|
|
|
|
assert( ( sharedList & tbit ) != 0 );
|
|
|
|
sharedList &= ~tbit;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2019-03-16 13:18:43 +00:00
|
|
|
tl.lockingThread = lockingThread;
|
|
|
|
tlp->waitShared = waitShared;
|
|
|
|
tl.waitList = waitList;
|
|
|
|
tlp->sharedList = sharedList;
|
|
|
|
tl.lockCount = lockCount;
|
2019-05-12 14:17:17 +00:00
|
|
|
if( !isContended ) isContended = ( lockCount != 0 && ( waitList != 0 || waitShared != 0 ) ) || ( sharedList != 0 && waitList != 0 );
|
2018-04-21 13:42:08 +00:00
|
|
|
pos++;
|
|
|
|
}
|
2019-05-12 14:17:17 +00:00
|
|
|
|
|
|
|
lockmap.isContended = isContended;
|
2018-04-21 13:42:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void UpdateLockCount( LockMap& lockmap, size_t pos )
|
|
|
|
{
|
|
|
|
if( lockmap.type == LockType::Lockable )
|
|
|
|
{
|
|
|
|
UpdateLockCountLockable( lockmap, pos );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
UpdateLockCountSharedLockable( lockmap, pos );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-13 23:17:50 +00:00
|
|
|
static tracy_force_inline void WriteTimeOffset( FileWrite& f, int64_t& refTime, int64_t time )
|
2018-12-30 22:06:03 +00:00
|
|
|
{
|
|
|
|
int64_t timeOffset = time - refTime;
|
|
|
|
refTime += timeOffset;
|
|
|
|
f.Write( &timeOffset, sizeof( timeOffset ) );
|
|
|
|
}
|
|
|
|
|
2019-02-13 23:17:50 +00:00
|
|
|
static tracy_force_inline int64_t ReadTimeOffset( FileRead& f, int64_t& refTime )
|
2018-12-30 22:06:03 +00:00
|
|
|
{
|
|
|
|
int64_t timeOffset;
|
|
|
|
f.Read( timeOffset );
|
|
|
|
refTime += timeOffset;
|
|
|
|
return refTime;
|
|
|
|
}
|
2018-04-21 13:42:08 +00:00
|
|
|
|
2019-03-16 01:28:32 +00:00
|
|
|
static tracy_force_inline void UpdateLockRange( LockMap& lockmap, const LockEvent& ev )
|
|
|
|
{
|
|
|
|
const auto lt = ev.time;
|
|
|
|
auto& range = lockmap.range[ev.thread];
|
|
|
|
if( range.start > lt ) range.start = lt;
|
|
|
|
if( range.end < lt ) range.end = lt;
|
|
|
|
}
|
|
|
|
|
2018-07-28 15:59:17 +00:00
|
|
|
LoadProgress Worker::s_loadProgress;
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
Worker::Worker( const char* addr )
|
|
|
|
: m_addr( addr )
|
|
|
|
, m_hasData( false )
|
|
|
|
, m_stream( LZ4_createStreamDecode() )
|
|
|
|
, m_buffer( new char[TargetFrameSize*3 + 1] )
|
|
|
|
, m_bufferOffset( 0 )
|
|
|
|
, m_pendingStrings( 0 )
|
|
|
|
, m_pendingThreads( 0 )
|
|
|
|
, m_pendingSourceLocation( 0 )
|
2018-06-20 21:42:00 +00:00
|
|
|
, m_pendingCallstackFrames( 0 )
|
2019-01-20 18:11:48 +00:00
|
|
|
, m_pendingCallstackSubframes( 0 )
|
|
|
|
, m_callstackFrameStaging( nullptr )
|
2018-07-29 13:33:48 +00:00
|
|
|
, m_traceVersion( CurrentVersion )
|
2019-01-06 18:09:50 +00:00
|
|
|
, m_loadTime( 0 )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
m_data.sourceLocationExpand.push_back( 0 );
|
2018-06-17 17:03:06 +00:00
|
|
|
m_data.threadExpand.push_back( 0 );
|
2018-06-19 19:52:54 +00:00
|
|
|
m_data.callstackPayload.push_back( nullptr );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-06-22 13:14:44 +00:00
|
|
|
memset( m_gpuCtxMap, 0, sizeof( m_gpuCtxMap ) );
|
|
|
|
|
2018-04-30 01:54:09 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
|
|
|
m_data.sourceLocationZonesReady = true;
|
|
|
|
#endif
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
m_thread = std::thread( [this] { Exec(); } );
|
|
|
|
SetThreadName( m_thread, "Tracy Worker" );
|
|
|
|
}
|
|
|
|
|
2018-04-20 14:03:09 +00:00
|
|
|
Worker::Worker( FileRead& f, EventType::Type eventMask )
|
2019-01-06 18:04:50 +00:00
|
|
|
: m_hasData( true )
|
2018-02-13 13:57:47 +00:00
|
|
|
, m_stream( nullptr )
|
|
|
|
, m_buffer( nullptr )
|
|
|
|
{
|
2019-01-06 18:09:50 +00:00
|
|
|
auto loadStart = std::chrono::high_resolution_clock::now();
|
|
|
|
|
2018-06-19 19:52:54 +00:00
|
|
|
m_data.callstackPayload.push_back( nullptr );
|
2018-06-17 17:03:06 +00:00
|
|
|
|
2018-04-21 11:45:48 +00:00
|
|
|
int fileVer = 0;
|
|
|
|
|
|
|
|
uint8_t hdr[8];
|
|
|
|
f.Read( hdr, sizeof( hdr ) );
|
|
|
|
if( memcmp( FileHeader, hdr, FileHeaderMagic ) == 0 )
|
|
|
|
{
|
|
|
|
fileVer = FileVersion( hdr[FileHeaderMagic], hdr[FileHeaderMagic+1], hdr[FileHeaderMagic+2] );
|
2018-04-21 12:18:13 +00:00
|
|
|
if( fileVer > CurrentVersion )
|
|
|
|
{
|
|
|
|
throw UnsupportedVersion( fileVer );
|
|
|
|
}
|
|
|
|
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( m_delay );
|
2018-04-21 11:45:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-04-21 12:47:15 +00:00
|
|
|
static_assert( sizeof( m_delay ) == sizeof( hdr ), "Size mismatch" );
|
2018-04-21 11:45:48 +00:00
|
|
|
memcpy( &m_delay, hdr, sizeof( m_delay ) );
|
|
|
|
}
|
2018-07-29 13:33:48 +00:00
|
|
|
m_traceVersion = fileVer;
|
2018-04-21 11:45:48 +00:00
|
|
|
|
2018-07-28 15:59:17 +00:00
|
|
|
if( fileVer <= FileVersion( 0, 3, 1 ) )
|
|
|
|
{
|
2018-07-28 16:26:00 +00:00
|
|
|
s_loadProgress.total.store( 7, std::memory_order_relaxed );
|
2018-07-28 15:59:17 +00:00
|
|
|
}
|
2019-06-06 21:40:37 +00:00
|
|
|
else if( fileVer <= FileVersion( 0, 4, 8 ) )
|
2018-07-28 15:59:17 +00:00
|
|
|
{
|
2018-07-28 16:26:00 +00:00
|
|
|
s_loadProgress.total.store( 8, std::memory_order_relaxed );
|
2018-07-28 15:59:17 +00:00
|
|
|
}
|
2019-06-06 21:40:37 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
s_loadProgress.total.store( 9, std::memory_order_relaxed );
|
|
|
|
}
|
2018-07-28 15:59:17 +00:00
|
|
|
|
2018-07-28 16:56:52 +00:00
|
|
|
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
|
2018-07-29 14:56:46 +00:00
|
|
|
s_loadProgress.progress.store( LoadProgress::Initialization, std::memory_order_relaxed );
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( m_resolution );
|
|
|
|
f.Read( m_timerMul );
|
|
|
|
f.Read( m_data.lastTime );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-07-10 20:56:41 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 3, 200 ) )
|
|
|
|
{
|
|
|
|
f.Read( m_data.frameOffset );
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
uint64_t sz;
|
|
|
|
{
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-02-13 13:57:47 +00:00
|
|
|
assert( sz < 1024 );
|
|
|
|
char tmp[1024];
|
|
|
|
f.Read( tmp, sz );
|
|
|
|
m_captureName = std::string( tmp, tmp+sz );
|
|
|
|
}
|
|
|
|
|
2018-08-28 22:57:11 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 3, 205 ) )
|
|
|
|
{
|
|
|
|
f.Read( sz );
|
|
|
|
assert( sz < 1024 );
|
|
|
|
char tmp[1024];
|
|
|
|
f.Read( tmp, sz );
|
|
|
|
m_captureProgram = std::string( tmp, tmp+sz );
|
|
|
|
|
|
|
|
f.Read( m_captureTime );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto sz = m_captureName.size();
|
|
|
|
char tmp[1024];
|
|
|
|
memcpy( tmp, m_captureName.c_str(), sz );
|
|
|
|
tmp[sz] = '\0';
|
|
|
|
auto ptr = tmp + sz - 1;
|
|
|
|
while( *ptr != '@' )
|
|
|
|
{
|
|
|
|
if( *ptr == '#' ) *ptr = '\0';
|
|
|
|
ptr--;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_captureProgram = std::string( tmp, ptr-1 );
|
|
|
|
|
|
|
|
tm epoch = {};
|
|
|
|
sscanf( ptr+1, "%d-%d-%d %d:%d:%d", &epoch.tm_year, &epoch.tm_mon, &epoch.tm_mday, &epoch.tm_hour, &epoch.tm_min, &epoch.tm_sec );
|
|
|
|
epoch.tm_year -= 1900;
|
|
|
|
epoch.tm_mon--;
|
|
|
|
m_captureTime = (uint64_t)mktime( &epoch );
|
|
|
|
}
|
|
|
|
|
2018-08-19 16:28:48 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 3, 203 ) )
|
|
|
|
{
|
|
|
|
f.Read( sz );
|
|
|
|
assert( sz < 1024 );
|
|
|
|
char tmp[1024];
|
|
|
|
f.Read( tmp, sz );
|
|
|
|
m_hostInfo = std::string( tmp, tmp+sz );
|
|
|
|
}
|
|
|
|
|
2018-08-20 00:27:24 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 3, 204 ) )
|
|
|
|
{
|
2019-03-26 20:41:44 +00:00
|
|
|
f.Read( &m_data.crashEvent, sizeof( m_data.crashEvent ) );
|
2018-08-20 00:27:24 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 17:47:09 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 3, 202 ) )
|
|
|
|
{
|
|
|
|
f.Read( sz );
|
2019-02-15 00:58:23 +00:00
|
|
|
m_data.frames.Data().reserve_exact( sz, m_slab );
|
2018-08-04 17:47:09 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
auto ptr = m_slab.AllocInit<FrameData>();
|
|
|
|
f.Read( &ptr->name, sizeof( ptr->name ) );
|
2018-08-05 00:09:59 +00:00
|
|
|
f.Read( &ptr->continuous, sizeof( ptr->continuous ) );
|
2018-08-04 17:47:09 +00:00
|
|
|
uint64_t fsz;
|
|
|
|
f.Read( &fsz, sizeof( fsz ) );
|
2019-02-15 00:58:23 +00:00
|
|
|
ptr->frames.reserve_exact( fsz, m_slab );
|
2019-06-06 21:08:19 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 9 ) )
|
|
|
|
{
|
|
|
|
int64_t refTime = 0;
|
|
|
|
if( ptr->continuous )
|
|
|
|
{
|
|
|
|
for( uint64_t j=0; j<fsz; j++ )
|
|
|
|
{
|
|
|
|
ptr->frames[j].start = ReadTimeOffset( f, refTime );
|
|
|
|
ptr->frames[j].end = -1;
|
|
|
|
f.Read( &ptr->frames[j].frameImage, sizeof( int32_t ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t j=0; j<fsz; j++ )
|
|
|
|
{
|
|
|
|
ptr->frames[j].start = ReadTimeOffset( f, refTime );
|
|
|
|
ptr->frames[j].end = ReadTimeOffset( f, refTime );
|
|
|
|
f.Read( &ptr->frames[j].frameImage, sizeof( int32_t ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( fileVer >= FileVersion( 0, 4, 2 ) )
|
2018-08-05 00:09:59 +00:00
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
|
|
|
if( ptr->continuous )
|
2018-08-05 00:09:59 +00:00
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
for( uint64_t j=0; j<fsz; j++ )
|
|
|
|
{
|
|
|
|
ptr->frames[j].start = ReadTimeOffset( f, refTime );
|
|
|
|
ptr->frames[j].end = -1;
|
2019-06-06 21:08:19 +00:00
|
|
|
ptr->frames[j].frameImage = -1;
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t j=0; j<fsz; j++ )
|
|
|
|
{
|
|
|
|
ptr->frames[j].start = ReadTimeOffset( f, refTime );
|
|
|
|
ptr->frames[j].end = ReadTimeOffset( f, refTime );
|
2019-06-06 21:08:19 +00:00
|
|
|
ptr->frames[j].frameImage = -1;
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
2018-08-05 00:09:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
if( ptr->continuous )
|
|
|
|
{
|
|
|
|
for( uint64_t j=0; j<fsz; j++ )
|
|
|
|
{
|
|
|
|
f.Read( &ptr->frames[j].start, sizeof( int64_t ) );
|
|
|
|
ptr->frames[j].end = -1;
|
2019-06-06 21:08:19 +00:00
|
|
|
ptr->frames[j].frameImage = -1;
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-06-06 21:08:19 +00:00
|
|
|
for( uint64_t j=0; j<fsz; j++ )
|
|
|
|
{
|
|
|
|
f.Read( &ptr->frames[j].start, sizeof( int64_t ) );
|
|
|
|
f.Read( &ptr->frames[j].end, sizeof( int64_t ) );
|
|
|
|
ptr->frames[j].frameImage = -1;
|
|
|
|
}
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
2018-08-05 00:09:59 +00:00
|
|
|
}
|
2018-08-04 17:47:09 +00:00
|
|
|
m_data.frames.Data()[i] = ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_data.framesBase = m_data.frames.Data()[0];
|
|
|
|
assert( m_data.framesBase->name == 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto ptr = m_slab.AllocInit<FrameData>();
|
|
|
|
ptr->name = 0;
|
2018-08-05 00:09:59 +00:00
|
|
|
ptr->continuous = 1;
|
2018-08-04 17:47:09 +00:00
|
|
|
f.Read( sz );
|
2019-02-15 00:58:23 +00:00
|
|
|
ptr->frames.reserve_exact( sz, m_slab );
|
2018-08-05 00:09:59 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
f.Read( &ptr->frames[i].start, sizeof( int64_t ) );
|
|
|
|
ptr->frames[i].end = -1;
|
2019-06-06 21:08:19 +00:00
|
|
|
ptr->frames[i].frameImage = -1;
|
2018-08-05 00:09:59 +00:00
|
|
|
}
|
2018-08-04 17:47:09 +00:00
|
|
|
m_data.frames.Data().push_back( ptr );
|
|
|
|
m_data.framesBase = ptr;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-03-20 14:44:13 +00:00
|
|
|
flat_hash_map<uint64_t, const char*, nohash<uint64_t>> pointerMap;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2019-02-15 00:58:23 +00:00
|
|
|
m_data.stringData.reserve_exact( sz, m_slab );
|
2018-02-13 13:57:47 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
2018-04-30 23:47:56 +00:00
|
|
|
uint64_t ptr, ssz;
|
|
|
|
f.Read2( ptr, ssz );
|
2018-02-13 13:57:47 +00:00
|
|
|
auto dst = m_slab.Alloc<char>( ssz+1 );
|
|
|
|
f.Read( dst, ssz );
|
|
|
|
dst[ssz] = '\0';
|
2018-08-09 17:37:37 +00:00
|
|
|
m_data.stringData[i] = ( dst );
|
2018-02-13 13:57:47 +00:00
|
|
|
pointerMap.emplace( ptr, dst );
|
|
|
|
}
|
|
|
|
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-02-13 13:57:47 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint64_t id, ptr;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read2( id, ptr );
|
2018-10-21 14:38:20 +00:00
|
|
|
auto it = pointerMap.find( ptr );
|
|
|
|
if( it != pointerMap.end() )
|
|
|
|
{
|
|
|
|
m_data.strings.emplace( id, it->second );
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-02-13 13:57:47 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint64_t id, ptr;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read2( id, ptr );
|
2018-10-21 14:38:20 +00:00
|
|
|
auto it = pointerMap.find( ptr );
|
|
|
|
if( it != pointerMap.end() )
|
|
|
|
{
|
|
|
|
m_data.threadNames.emplace( id, it->second );
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 21:48:29 +00:00
|
|
|
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 );
|
2019-03-06 23:49:25 +00:00
|
|
|
m_data.threadMap.reserve( sz );
|
|
|
|
for( size_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
m_data.threadMap.emplace( m_data.threadExpand[i], i );
|
|
|
|
}
|
2019-02-16 21:48:29 +00:00
|
|
|
}
|
|
|
|
else if( fileVer >= FileVersion( 0, 3, 201 ) )
|
2018-07-29 13:19:44 +00:00
|
|
|
{
|
|
|
|
f.Read( sz );
|
|
|
|
m_data.threadExpand.reserve( sz );
|
2019-03-06 23:49:06 +00:00
|
|
|
m_data.threadExpand.push_back( 0 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_data.threadExpand.push_back( 0 );
|
2018-07-29 13:19:44 +00:00
|
|
|
}
|
|
|
|
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-02-13 13:57:47 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint64_t ptr;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( ptr );
|
2018-02-13 13:57:47 +00:00
|
|
|
SourceLocation srcloc;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( srcloc );
|
2018-02-13 13:57:47 +00:00
|
|
|
m_data.sourceLocation.emplace( ptr, srcloc );
|
|
|
|
}
|
|
|
|
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2019-02-15 00:58:23 +00:00
|
|
|
m_data.sourceLocationExpand.reserve_exact( sz, m_slab );
|
2018-03-15 20:42:00 +00:00
|
|
|
f.Read( m_data.sourceLocationExpand.data(), sizeof( uint64_t ) * sz );
|
2018-03-18 01:05:33 +00:00
|
|
|
const auto sle = sz;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2019-02-15 00:58:23 +00:00
|
|
|
m_data.sourceLocationPayload.reserve_exact( sz, m_slab );
|
2018-02-13 13:57:47 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
auto srcloc = m_slab.Alloc<SourceLocation>();
|
|
|
|
f.Read( srcloc, sizeof( *srcloc ) );
|
2018-08-09 17:37:37 +00:00
|
|
|
m_data.sourceLocationPayload[i] = srcloc;
|
2018-03-04 16:20:14 +00:00
|
|
|
m_data.sourceLocationPayloadMap.emplace( srcloc, uint32_t( i ) );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-03-18 11:55:54 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
2018-04-30 01:54:09 +00:00
|
|
|
m_data.sourceLocationZonesReady = false;
|
2018-03-18 01:05:33 +00:00
|
|
|
m_data.sourceLocationZones.reserve( sle + sz );
|
2018-07-29 12:58:01 +00:00
|
|
|
|
|
|
|
if( fileVer >= FileVersion( 0, 3, 201 ) )
|
2018-03-18 01:05:33 +00:00
|
|
|
{
|
2018-07-29 12:58:01 +00:00
|
|
|
f.Read( sz );
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
int32_t id;
|
|
|
|
uint64_t cnt;
|
|
|
|
f.Read( id );
|
|
|
|
f.Read( cnt );
|
|
|
|
auto status = m_data.sourceLocationZones.emplace( id, SourceLocationZones() );
|
|
|
|
assert( status.second );
|
|
|
|
status.first->second.zones.reserve( cnt );
|
|
|
|
}
|
2018-03-18 01:05:33 +00:00
|
|
|
}
|
2018-07-29 12:58:01 +00:00
|
|
|
else
|
2018-03-18 01:05:33 +00:00
|
|
|
{
|
2018-07-29 12:58:01 +00:00
|
|
|
for( uint64_t i=1; i<sle; i++ )
|
|
|
|
{
|
|
|
|
m_data.sourceLocationZones.emplace( int32_t( i ), SourceLocationZones() );
|
|
|
|
}
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
m_data.sourceLocationZones.emplace( -int32_t( i + 1 ), SourceLocationZones() );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
if( fileVer >= FileVersion( 0, 3, 201 ) )
|
|
|
|
{
|
|
|
|
f.Read( sz );
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
int32_t id;
|
|
|
|
f.Read( id );
|
|
|
|
f.Skip( sizeof( uint64_t ) );
|
|
|
|
m_data.sourceLocationZonesCnt.emplace( id, 0 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t i=1; i<sle; i++ )
|
|
|
|
{
|
|
|
|
m_data.sourceLocationZonesCnt.emplace( int32_t( i ), 0 );
|
|
|
|
}
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
m_data.sourceLocationZonesCnt.emplace( -int32_t( i + 1 ), 0 );
|
|
|
|
}
|
2018-03-18 01:05:33 +00:00
|
|
|
}
|
2018-03-18 11:55:54 +00:00
|
|
|
#endif
|
2018-03-18 01:05:33 +00:00
|
|
|
|
2018-07-29 14:56:46 +00:00
|
|
|
s_loadProgress.progress.store( LoadProgress::Locks, std::memory_order_relaxed );
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-04-20 14:03:09 +00:00
|
|
|
if( eventMask & EventType::Locks )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-07-28 17:05:01 +00:00
|
|
|
s_loadProgress.subTotal.store( sz, std::memory_order_relaxed );
|
2018-04-20 14:03:09 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-07-28 17:05:01 +00:00
|
|
|
s_loadProgress.subProgress.store( i, std::memory_order_relaxed );
|
2019-03-16 01:09:50 +00:00
|
|
|
auto lockmapPtr = m_slab.AllocInit<LockMap>();
|
|
|
|
auto& lockmap = *lockmapPtr;
|
2018-04-20 14:03:09 +00:00
|
|
|
uint32_t id;
|
|
|
|
uint64_t tsz;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( id );
|
|
|
|
f.Read( lockmap.srcloc );
|
|
|
|
f.Read( lockmap.type );
|
|
|
|
f.Read( lockmap.valid );
|
2019-05-12 14:17:17 +00:00
|
|
|
lockmap.isContended = false;
|
2018-12-16 19:52:06 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 1 ) )
|
|
|
|
{
|
|
|
|
f.Read2( lockmap.timeAnnounce, lockmap.timeTerminate );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lockmap.timeAnnounce = lockmap.timeTerminate = 0;
|
|
|
|
}
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( tsz );
|
2018-02-13 13:57:47 +00:00
|
|
|
for( uint64_t i=0; i<tsz; i++ )
|
|
|
|
{
|
2018-04-20 14:03:09 +00:00
|
|
|
uint64_t t;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( t );
|
2018-04-20 14:03:09 +00:00
|
|
|
lockmap.threadMap.emplace( t, lockmap.threadList.size() );
|
|
|
|
lockmap.threadList.emplace_back( t );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( tsz );
|
2019-02-15 00:58:23 +00:00
|
|
|
lockmap.timeline.reserve_exact( tsz, m_slab );
|
2018-04-29 01:21:40 +00:00
|
|
|
auto ptr = lockmap.timeline.data();
|
2018-12-30 22:06:03 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 2 ) )
|
|
|
|
{
|
|
|
|
int64_t refTime = lockmap.timeAnnounce;
|
|
|
|
if( lockmap.type == LockType::Lockable )
|
|
|
|
{
|
|
|
|
for( uint64_t i=0; i<tsz; i++ )
|
|
|
|
{
|
|
|
|
auto lev = m_slab.Alloc<LockEvent>();
|
|
|
|
lev->time = ReadTimeOffset( f, refTime );
|
2019-01-24 21:44:09 +00:00
|
|
|
f.Read( &lev->srcloc, sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
|
2019-03-16 13:18:43 +00:00
|
|
|
*ptr++ = { lev };
|
2019-03-16 01:28:32 +00:00
|
|
|
UpdateLockRange( lockmap, *lev );
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t i=0; i<tsz; i++ )
|
|
|
|
{
|
|
|
|
auto lev = m_slab.Alloc<LockEventShared>();
|
|
|
|
lev->time = ReadTimeOffset( f, refTime );
|
2019-01-24 21:44:09 +00:00
|
|
|
f.Read( &lev->srcloc, sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
|
2019-03-16 13:18:43 +00:00
|
|
|
*ptr++ = { lev };
|
2019-03-16 01:28:32 +00:00
|
|
|
UpdateLockRange( lockmap, *lev );
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( fileVer >= FileVersion( 0, 3, 0 ) )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-04-21 13:42:08 +00:00
|
|
|
if( lockmap.type == LockType::Lockable )
|
2018-04-20 14:03:09 +00:00
|
|
|
{
|
2018-04-21 13:42:08 +00:00
|
|
|
for( uint64_t i=0; i<tsz; i++ )
|
|
|
|
{
|
|
|
|
auto lev = m_slab.Alloc<LockEvent>();
|
2018-04-29 01:37:34 +00:00
|
|
|
f.Read( lev, sizeof( LockEvent::time ) + sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) + sizeof( LockEvent::type ) );
|
2019-03-16 13:18:43 +00:00
|
|
|
*ptr++ = { lev };
|
2019-03-16 01:28:32 +00:00
|
|
|
UpdateLockRange( lockmap, *lev );
|
2018-04-21 13:42:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t i=0; i<tsz; i++ )
|
|
|
|
{
|
|
|
|
auto lev = m_slab.Alloc<LockEventShared>();
|
2018-04-29 01:37:34 +00:00
|
|
|
f.Read( lev, sizeof( LockEventShared::time ) + sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) + sizeof( LockEventShared::type ) );
|
2019-03-16 13:18:43 +00:00
|
|
|
*ptr++ = { lev };
|
2019-03-16 01:28:32 +00:00
|
|
|
UpdateLockRange( lockmap, *lev );
|
2018-04-21 13:42:08 +00:00
|
|
|
}
|
2018-04-20 14:03:09 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2018-04-20 14:03:09 +00:00
|
|
|
else
|
|
|
|
{
|
2018-04-21 13:42:08 +00:00
|
|
|
if( lockmap.type == LockType::Lockable )
|
2018-04-20 14:03:09 +00:00
|
|
|
{
|
2018-04-21 13:42:08 +00:00
|
|
|
for( uint64_t i=0; i<tsz; i++ )
|
|
|
|
{
|
|
|
|
auto lev = m_slab.Alloc<LockEvent>();
|
2018-04-29 01:37:34 +00:00
|
|
|
f.Read( lev, sizeof( LockEvent::time ) + sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) );
|
2018-04-21 13:42:08 +00:00
|
|
|
f.Skip( sizeof( uint8_t ) );
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( lev->type );
|
2018-04-21 13:42:08 +00:00
|
|
|
f.Skip( sizeof( uint8_t ) + sizeof( uint64_t ) );
|
2019-03-16 13:18:43 +00:00
|
|
|
*ptr++ = { lev };
|
2019-03-16 01:28:32 +00:00
|
|
|
UpdateLockRange( lockmap, *lev );
|
2018-04-21 13:42:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t i=0; i<tsz; i++ )
|
|
|
|
{
|
|
|
|
auto lev = m_slab.Alloc<LockEventShared>();
|
2018-04-29 01:37:34 +00:00
|
|
|
f.Read( lev, sizeof( LockEventShared::time ) + sizeof( LockEventShared::srcloc ) + sizeof( LockEventShared::thread ) );
|
2018-04-21 13:42:08 +00:00
|
|
|
f.Skip( sizeof( uint8_t ) );
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( lev->type );
|
2018-04-21 13:42:08 +00:00
|
|
|
f.Skip( sizeof( uint8_t ) + sizeof( uint64_t ) * 3 );
|
2019-03-16 13:18:43 +00:00
|
|
|
*ptr++ = { lev };
|
2019-03-16 01:28:32 +00:00
|
|
|
UpdateLockRange( lockmap, *lev );
|
2018-04-21 13:42:08 +00:00
|
|
|
}
|
2018-04-20 14:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-21 13:42:08 +00:00
|
|
|
UpdateLockCount( lockmap, 0 );
|
2019-03-16 01:09:50 +00:00
|
|
|
m_data.lockMap.emplace( id, lockmapPtr );
|
2018-04-20 14:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
LockType type;
|
|
|
|
uint64_t tsz;
|
|
|
|
f.Skip( sizeof( uint32_t ) + sizeof( LockMap::srcloc ) );
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( type );
|
2018-04-20 14:03:09 +00:00
|
|
|
f.Skip( sizeof( LockMap::valid ) );
|
2019-01-08 16:19:04 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 1 ) )
|
|
|
|
{
|
|
|
|
f.Skip( sizeof( LockMap::timeAnnounce ) + sizeof( LockMap::timeTerminate ) );
|
|
|
|
}
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( tsz );
|
2018-04-20 14:03:09 +00:00
|
|
|
f.Skip( tsz * sizeof( uint64_t ) );
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( tsz );
|
2018-04-21 14:02:36 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 3, 0 ) )
|
|
|
|
{
|
2018-04-21 23:26:51 +00:00
|
|
|
f.Skip( tsz * ( sizeof( LockEvent::time ) + sizeof( LockEvent::type ) + sizeof( LockEvent::srcloc ) + sizeof( LockEvent::thread ) ) );
|
2018-04-21 14:02:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-26 19:25:29 +00:00
|
|
|
f.Skip( tsz * ( type == LockType::Lockable ? 24 : 40 ) );
|
2018-04-21 14:02:36 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-28 17:05:01 +00:00
|
|
|
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
|
2018-07-29 14:56:46 +00:00
|
|
|
s_loadProgress.progress.store( LoadProgress::Messages, std::memory_order_relaxed );
|
2018-03-20 14:44:13 +00:00
|
|
|
flat_hash_map<uint64_t, MessageData*, nohash<uint64_t>> msgMap;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-04-20 14:03:09 +00:00
|
|
|
if( eventMask & EventType::Messages )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2019-02-15 00:58:23 +00:00
|
|
|
m_data.messages.reserve_exact( sz, m_slab );
|
2019-05-10 18:32:47 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 8 ) )
|
2018-04-20 14:03:09 +00:00
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint64_t ptr;
|
|
|
|
f.Read( ptr );
|
|
|
|
auto msgdata = m_slab.Alloc<MessageData>();
|
|
|
|
msgdata->time = ReadTimeOffset( f, refTime );
|
|
|
|
f.Read( msgdata->ref );
|
2019-05-10 18:32:47 +00:00
|
|
|
f.Read( msgdata->color );
|
|
|
|
m_data.messages[i] = msgdata;
|
|
|
|
msgMap.emplace( ptr, msgdata );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( fileVer >= FileVersion( 0, 4, 2 ) )
|
|
|
|
{
|
|
|
|
int64_t refTime = 0;
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint64_t ptr;
|
|
|
|
f.Read( ptr );
|
|
|
|
auto msgdata = m_slab.Alloc<MessageData>();
|
|
|
|
msgdata->time = ReadTimeOffset( f, refTime );
|
|
|
|
f.Read( msgdata->ref );
|
|
|
|
msgdata->color = 0xFFFFFFFF;
|
2018-12-30 22:06:03 +00:00
|
|
|
m_data.messages[i] = msgdata;
|
|
|
|
msgMap.emplace( ptr, msgdata );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint64_t ptr;
|
|
|
|
f.Read( ptr );
|
|
|
|
auto msgdata = m_slab.Alloc<MessageData>();
|
|
|
|
f.Read( msgdata, sizeof( MessageData::time ) + sizeof( MessageData::ref ) );
|
|
|
|
if( fileVer <= FileVersion( 0, 3, 0 ) ) f.Skip( 7 );
|
2019-05-10 18:32:47 +00:00
|
|
|
msgdata->color = 0xFFFFFFFF;
|
2018-12-30 22:06:03 +00:00
|
|
|
m_data.messages[i] = msgdata;
|
|
|
|
msgMap.emplace( ptr, msgdata );
|
|
|
|
}
|
2018-04-20 14:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-05-25 19:09:43 +00:00
|
|
|
// Prior to 0.3.1 MessageData was saved with padding.
|
|
|
|
if( fileVer <= FileVersion( 0, 3, 0 ) )
|
|
|
|
{
|
|
|
|
f.Skip( sz * ( sizeof( uint64_t ) + 24 ) );
|
|
|
|
}
|
2019-05-10 18:32:47 +00:00
|
|
|
else if( fileVer <= FileVersion( 0, 4, 7 ) )
|
2018-05-25 19:09:43 +00:00
|
|
|
{
|
|
|
|
f.Skip( sz * ( sizeof( uint64_t ) + sizeof( MessageData::time ) + sizeof( MessageData::ref ) ) );
|
|
|
|
}
|
2019-05-10 18:32:47 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
f.Skip( sz * ( sizeof( uint64_t ) + sizeof( MessageData::time ) + sizeof( MessageData::ref ) + sizeof( MessageData::color ) ) );
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-07-29 14:56:46 +00:00
|
|
|
s_loadProgress.progress.store( LoadProgress::Zones, std::memory_order_relaxed );
|
2019-03-27 00:46:54 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 7 ) )
|
|
|
|
{
|
|
|
|
f.Read( sz );
|
|
|
|
s_loadProgress.subTotal.store( sz, std::memory_order_relaxed );
|
|
|
|
s_loadProgress.subProgress.store( 0, std::memory_order_relaxed );
|
|
|
|
}
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2019-02-15 00:58:23 +00:00
|
|
|
m_data.threads.reserve_exact( sz, m_slab );
|
2018-02-13 13:57:47 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
auto td = m_slab.AllocInit<ThreadData>();
|
2018-05-25 19:10:22 +00:00
|
|
|
uint64_t tid;
|
|
|
|
f.Read( tid );
|
|
|
|
td->id = tid;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( td->count );
|
2018-07-22 14:05:50 +00:00
|
|
|
uint64_t tsz;
|
|
|
|
f.Read( tsz );
|
2019-03-27 00:46:54 +00:00
|
|
|
if( fileVer < FileVersion( 0, 4, 7 ) )
|
|
|
|
{
|
|
|
|
s_loadProgress.subTotal.store( td->count, std::memory_order_relaxed );
|
|
|
|
s_loadProgress.subProgress.store( 0, std::memory_order_relaxed );
|
|
|
|
}
|
2018-07-22 19:15:28 +00:00
|
|
|
if( tsz != 0 )
|
2018-06-21 23:30:08 +00:00
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
if( fileVer <= FileVersion( 0, 4, 1 ) )
|
2018-07-22 19:15:28 +00:00
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
ReadTimelinePre042( f, td->timeline, CompressThread( tid ), tsz, fileVer );
|
2018-07-22 19:15:28 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
|
|
|
ReadTimeline( f, td->timeline, CompressThread( tid ), tsz, refTime );
|
2018-07-22 19:15:28 +00:00
|
|
|
}
|
2018-06-21 23:30:08 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
uint64_t msz;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( msz );
|
2018-04-20 14:03:09 +00:00
|
|
|
if( eventMask & EventType::Messages )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2019-02-15 00:58:23 +00:00
|
|
|
td->messages.reserve_exact( msz, m_slab );
|
2018-04-20 14:03:09 +00:00
|
|
|
for( uint64_t j=0; j<msz; j++ )
|
|
|
|
{
|
|
|
|
uint64_t ptr;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( ptr );
|
2018-05-25 19:10:22 +00:00
|
|
|
auto md = msgMap[ptr];
|
2018-08-09 17:37:37 +00:00
|
|
|
td->messages[j] = md;
|
2018-05-25 19:10:22 +00:00
|
|
|
md->thread = tid;
|
2018-04-20 14:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.Skip( msz * sizeof( uint64_t ) );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2018-08-09 17:37:37 +00:00
|
|
|
m_data.threads[i] = td;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-07-29 14:56:46 +00:00
|
|
|
s_loadProgress.progress.store( LoadProgress::GpuZones, std::memory_order_relaxed );
|
2019-03-27 00:46:54 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 7 ) )
|
|
|
|
{
|
|
|
|
f.Read( sz );
|
|
|
|
s_loadProgress.subTotal.store( sz, std::memory_order_relaxed );
|
|
|
|
s_loadProgress.subProgress.store( 0, std::memory_order_relaxed );
|
|
|
|
}
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2019-02-15 00:58:23 +00:00
|
|
|
m_data.gpuData.reserve_exact( sz, m_slab );
|
2018-02-13 13:57:47 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
auto ctx = m_slab.AllocInit<GpuCtxData>();
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( ctx->thread );
|
|
|
|
f.Read( ctx->accuracyBits );
|
|
|
|
f.Read( ctx->count );
|
2019-03-27 00:46:54 +00:00
|
|
|
if( fileVer < FileVersion( 0, 4, 7 ) )
|
|
|
|
{
|
|
|
|
s_loadProgress.subTotal.store( ctx->count, std::memory_order_relaxed );
|
|
|
|
s_loadProgress.subProgress.store( 0, std::memory_order_relaxed );
|
|
|
|
}
|
2019-02-16 22:04:34 +00:00
|
|
|
int64_t refTime = 0;
|
|
|
|
int64_t refGpuTime = 0;
|
2018-06-17 16:27:16 +00:00
|
|
|
if( fileVer <= FileVersion( 0, 3, 1 ) )
|
|
|
|
{
|
|
|
|
ctx->period = 1.f;
|
2018-07-22 17:47:01 +00:00
|
|
|
uint64_t tsz;
|
|
|
|
f.Read( tsz );
|
2018-07-22 19:15:28 +00:00
|
|
|
if( tsz != 0 )
|
|
|
|
{
|
2019-02-16 22:04:34 +00:00
|
|
|
ReadTimelinePre044( f, ctx->timeline, tsz, refTime, refGpuTime, fileVer );
|
2018-07-22 19:15:28 +00:00
|
|
|
}
|
2018-06-17 16:27:16 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.Read( ctx->period );
|
2018-07-22 17:47:01 +00:00
|
|
|
uint64_t tsz;
|
|
|
|
f.Read( tsz );
|
2018-07-22 19:15:28 +00:00
|
|
|
if( tsz != 0 )
|
|
|
|
{
|
2019-02-16 22:04:34 +00:00
|
|
|
if( fileVer <= FileVersion( 0, 4, 3 ) )
|
2018-12-30 22:06:03 +00:00
|
|
|
{
|
2019-02-16 22:04:34 +00:00
|
|
|
ReadTimelinePre044( f, ctx->timeline, tsz, refTime, refGpuTime, fileVer );
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-16 22:04:34 +00:00
|
|
|
|
2019-01-03 19:09:45 +00:00
|
|
|
ReadTimeline( f, ctx->timeline, tsz, refTime, refGpuTime );
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
2018-07-22 19:15:28 +00:00
|
|
|
}
|
2018-06-17 16:27:16 +00:00
|
|
|
}
|
2018-08-09 17:37:37 +00:00
|
|
|
m_data.gpuData[i] = ctx;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-07-29 14:56:46 +00:00
|
|
|
s_loadProgress.progress.store( LoadProgress::Plots, std::memory_order_relaxed );
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-04-20 14:03:09 +00:00
|
|
|
if( eventMask & EventType::Plots )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-08-04 14:33:03 +00:00
|
|
|
m_data.plots.Data().reserve( sz );
|
2018-08-04 13:17:37 +00:00
|
|
|
s_loadProgress.subTotal.store( sz, std::memory_order_relaxed );
|
2018-04-20 14:03:09 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
2018-08-04 13:17:37 +00:00
|
|
|
s_loadProgress.subProgress.store( i, std::memory_order_relaxed );
|
2018-04-20 14:03:09 +00:00
|
|
|
auto pd = m_slab.AllocInit<PlotData>();
|
2019-02-21 21:53:26 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 5 ) )
|
|
|
|
{
|
|
|
|
f.Read( pd->type );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pd->type = PlotType::User;
|
|
|
|
}
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( pd->name );
|
|
|
|
f.Read( pd->min );
|
|
|
|
f.Read( pd->max );
|
2018-04-20 14:03:09 +00:00
|
|
|
uint64_t psz;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( psz );
|
2019-02-15 00:58:23 +00:00
|
|
|
pd->data.reserve_exact( psz, m_slab );
|
2018-12-30 22:06:03 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 2 ) )
|
|
|
|
{
|
|
|
|
int64_t refTime = 0;
|
|
|
|
for( uint64_t j=0; j<psz; j++ )
|
|
|
|
{
|
|
|
|
pd->data[j].time = ReadTimeOffset( f, refTime );
|
|
|
|
f.Read( pd->data[j].val );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.Read( pd->data.data(), psz * sizeof( PlotItem ) );
|
|
|
|
}
|
2018-08-04 14:33:03 +00:00
|
|
|
m_data.plots.Data().push_back_no_space_check( pd );
|
2018-04-20 14:03:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
2019-03-15 14:27:37 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 5 ) )
|
|
|
|
{
|
|
|
|
f.Skip( sizeof( PlotData::name ) + sizeof( PlotData::min ) + sizeof( PlotData::max ) + sizeof( PlotData::type ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.Skip( sizeof( PlotData::name ) + sizeof( PlotData::min ) + sizeof( PlotData::max ) );
|
|
|
|
}
|
2018-04-20 14:03:09 +00:00
|
|
|
uint64_t psz;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( psz );
|
2018-04-20 14:03:09 +00:00
|
|
|
f.Skip( psz * sizeof( PlotItem ) );
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2018-04-02 00:05:16 +00:00
|
|
|
|
2019-02-14 00:13:11 +00:00
|
|
|
bool reconstructMemAllocPlot = false;
|
|
|
|
|
2018-04-02 00:05:16 +00:00
|
|
|
// Support pre-0.3 traces
|
2019-02-14 00:13:11 +00:00
|
|
|
if( fileVer == 0 && f.IsEOF() ) goto finishLoading;
|
2018-04-02 00:05:16 +00:00
|
|
|
|
2018-07-28 17:05:01 +00:00
|
|
|
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
|
2018-07-29 14:56:46 +00:00
|
|
|
s_loadProgress.progress.store( LoadProgress::Memory, std::memory_order_relaxed );
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-04-20 14:03:09 +00:00
|
|
|
if( eventMask & EventType::Memory )
|
2018-04-02 00:05:16 +00:00
|
|
|
{
|
2019-02-15 00:58:23 +00:00
|
|
|
m_data.memory.data.reserve_exact( sz, m_slab );
|
2018-07-29 13:29:56 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 3, 201 ) )
|
|
|
|
{
|
|
|
|
uint64_t activeSz, freesSz;
|
|
|
|
f.Read2( activeSz, freesSz );
|
|
|
|
m_data.memory.active.reserve( activeSz );
|
2019-02-15 00:58:23 +00:00
|
|
|
m_data.memory.frees.reserve_exact( freesSz, m_slab );
|
2018-07-29 13:29:56 +00:00
|
|
|
}
|
2018-04-20 14:03:09 +00:00
|
|
|
auto mem = m_data.memory.data.data();
|
2018-07-28 17:05:01 +00:00
|
|
|
s_loadProgress.subTotal.store( sz, std::memory_order_relaxed );
|
2018-08-09 17:37:37 +00:00
|
|
|
size_t fidx = 0;
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
2019-02-16 22:00:05 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 4 ) )
|
2018-04-02 00:05:16 +00:00
|
|
|
{
|
2019-02-16 22:00:05 +00:00
|
|
|
auto& frees = m_data.memory.frees;
|
|
|
|
auto& active = m_data.memory.active;
|
|
|
|
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
2018-12-30 22:06:03 +00:00
|
|
|
{
|
2019-02-16 22:00:05 +00:00
|
|
|
s_loadProgress.subProgress.store( i, std::memory_order_relaxed );
|
|
|
|
f.Read( mem, sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::csAlloc ) + sizeof( MemEvent::csFree ) + sizeof( MemEvent::threadAlloc ) + sizeof( MemEvent::threadFree ) );
|
2019-02-16 21:32:14 +00:00
|
|
|
refTime += mem->timeAlloc;
|
|
|
|
mem->timeAlloc = refTime;
|
2019-02-16 22:00:05 +00:00
|
|
|
if( mem->timeFree >= 0 )
|
|
|
|
{
|
|
|
|
mem->timeFree += refTime;
|
|
|
|
frees[fidx++] = i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
active.emplace( mem->ptr, i );
|
|
|
|
}
|
|
|
|
mem++;
|
2019-02-16 21:26:50 +00:00
|
|
|
}
|
2019-02-16 22:00:05 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
2019-02-16 21:26:50 +00:00
|
|
|
{
|
2019-02-16 22:00:05 +00:00
|
|
|
s_loadProgress.subProgress.store( i, std::memory_order_relaxed );
|
|
|
|
if( fileVer > FileVersion( 0, 4, 1 ) )
|
|
|
|
{
|
|
|
|
f.Read( mem, sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::csAlloc ) + sizeof( MemEvent::csFree ) );
|
|
|
|
refTime += mem->timeAlloc;
|
|
|
|
mem->timeAlloc = refTime;
|
|
|
|
if( mem->timeFree >= 0 ) mem->timeFree += refTime;
|
|
|
|
}
|
|
|
|
else if( fileVer > FileVersion( 0, 3, 1 ) )
|
|
|
|
{
|
|
|
|
f.Read( mem, sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::csAlloc ) + sizeof( MemEvent::csFree ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.Read( mem, sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) );
|
|
|
|
mem->csAlloc = 0;
|
|
|
|
mem->csFree = 0;
|
|
|
|
}
|
2018-06-19 19:51:06 +00:00
|
|
|
|
2019-02-16 22:00:05 +00:00
|
|
|
uint64_t t0, t1;
|
|
|
|
f.Read2( t0, t1 );
|
|
|
|
mem->threadAlloc = CompressThread( t0 );
|
|
|
|
if( t0 == t1 )
|
|
|
|
{
|
|
|
|
mem->threadFree = mem->threadAlloc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mem->threadFree = CompressThread( t1 );
|
|
|
|
}
|
2018-04-03 12:17:51 +00:00
|
|
|
|
2019-02-16 22:00:05 +00:00
|
|
|
if( mem->timeFree < 0 )
|
2018-08-09 17:37:37 +00:00
|
|
|
{
|
2019-02-16 22:00:05 +00:00
|
|
|
m_data.memory.active.emplace( mem->ptr, i );
|
2018-08-09 17:37:37 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-16 22:00:05 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 3, 201 ) )
|
|
|
|
{
|
|
|
|
m_data.memory.frees[fidx++] = i;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_data.memory.frees.push_back( i );
|
|
|
|
}
|
2018-08-09 17:37:37 +00:00
|
|
|
}
|
2018-04-20 14:03:09 +00:00
|
|
|
|
2019-02-16 22:00:05 +00:00
|
|
|
mem++;
|
|
|
|
}
|
2018-04-20 14:03:09 +00:00
|
|
|
}
|
2019-02-16 22:00:05 +00:00
|
|
|
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( m_data.memory.high );
|
|
|
|
f.Read( m_data.memory.low );
|
|
|
|
f.Read( m_data.memory.usage );
|
2018-04-28 14:18:56 +00:00
|
|
|
|
2018-05-04 14:08:16 +00:00
|
|
|
if( sz != 0 )
|
|
|
|
{
|
2018-06-24 15:10:46 +00:00
|
|
|
reconstructMemAllocPlot = true;
|
2018-05-04 14:08:16 +00:00
|
|
|
}
|
2018-04-20 14:03:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-29 13:29:56 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 3, 201 ) )
|
|
|
|
{
|
|
|
|
f.Skip( 2 * sizeof( uint64_t ) );
|
|
|
|
}
|
2019-02-16 22:00:05 +00:00
|
|
|
|
|
|
|
if( fileVer >= FileVersion( 0, 4, 4 ) )
|
2018-06-19 19:54:12 +00:00
|
|
|
{
|
2019-02-16 22:00:05 +00:00
|
|
|
f.Skip( sz * ( sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::csAlloc ) + sizeof( MemEvent::csFree ) + sizeof( MemEvent::threadAlloc ) + sizeof( MemEvent::threadFree ) ) );
|
|
|
|
}
|
|
|
|
else if( fileVer > FileVersion( 0, 4, 1 ) )
|
|
|
|
{
|
|
|
|
f.Skip( sz * ( sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::csAlloc ) + sizeof( MemEvent::csFree ) + 2 * sizeof( uint64_t ) ) );
|
|
|
|
}
|
|
|
|
else if( fileVer > FileVersion( 0, 3, 1 ) )
|
|
|
|
{
|
|
|
|
f.Skip( sz * ( sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + sizeof( MemEvent::csAlloc ) + sizeof( MemEvent::csFree ) + 2 * sizeof( uint64_t ) ) );
|
2018-06-19 19:54:12 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-16 22:00:05 +00:00
|
|
|
f.Skip( sz * ( sizeof( MemEvent::ptr ) + sizeof( MemEvent::size ) + sizeof( MemEvent::timeAlloc ) + sizeof( MemEvent::timeFree ) + 2 * sizeof( uint64_t ) ) );
|
2018-06-19 19:54:12 +00:00
|
|
|
}
|
2019-02-16 22:00:05 +00:00
|
|
|
|
2018-04-20 14:03:09 +00:00
|
|
|
f.Skip( sizeof( MemData::high ) + sizeof( MemData::low ) + sizeof( MemData::usage ) );
|
2018-04-02 00:05:16 +00:00
|
|
|
}
|
2018-06-19 20:04:26 +00:00
|
|
|
|
2018-06-24 15:10:46 +00:00
|
|
|
if( fileVer <= FileVersion( 0, 3, 1 ) ) goto finishLoading;
|
2018-06-19 20:04:26 +00:00
|
|
|
|
2018-07-28 17:05:01 +00:00
|
|
|
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
|
2018-07-29 14:56:46 +00:00
|
|
|
s_loadProgress.progress.store( LoadProgress::CallStacks, std::memory_order_relaxed );
|
2018-06-19 20:04:26 +00:00
|
|
|
f.Read( sz );
|
|
|
|
m_data.callstackPayload.reserve( sz );
|
2019-03-03 15:50:18 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 6 ) )
|
|
|
|
{
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint8_t csz;
|
|
|
|
f.Read( csz );
|
|
|
|
|
|
|
|
const auto memsize = sizeof( VarArray<CallstackFrameId> ) + csz * sizeof( CallstackFrameId );
|
|
|
|
auto mem = (char*)m_slab.AllocRaw( memsize );
|
|
|
|
|
|
|
|
auto data = (CallstackFrameId*)mem;
|
|
|
|
f.Read( data, csz * sizeof( CallstackFrameId ) );
|
|
|
|
|
|
|
|
auto arr = (VarArray<CallstackFrameId>*)( mem + csz * sizeof( CallstackFrameId ) );
|
|
|
|
new(arr) VarArray<CallstackFrameId>( csz, data );
|
|
|
|
|
|
|
|
m_data.callstackPayload.push_back_no_space_check( arr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2018-06-19 20:04:26 +00:00
|
|
|
{
|
2019-03-03 15:50:18 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint8_t csz;
|
|
|
|
f.Read( csz );
|
2018-06-19 20:04:26 +00:00
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
const auto memsize = sizeof( VarArray<CallstackFrameId> ) + csz * sizeof( CallstackFrameId );
|
|
|
|
auto mem = (char*)m_slab.AllocRaw( memsize );
|
2018-06-19 20:04:26 +00:00
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
auto data = (CallstackFrameId*)mem;
|
|
|
|
for( uint8_t j=0; j<csz; j++ )
|
|
|
|
{
|
|
|
|
uint64_t ptr;
|
|
|
|
f.Read( ptr );
|
|
|
|
data[j] = PackPointer( ptr );
|
|
|
|
}
|
2018-06-19 20:04:26 +00:00
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
auto arr = (VarArray<CallstackFrameId>*)( mem + csz * sizeof( CallstackFrameId ) );
|
|
|
|
new(arr) VarArray<CallstackFrameId>( csz, data );
|
2018-06-19 20:04:26 +00:00
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
m_data.callstackPayload.push_back_no_space_check( arr );
|
|
|
|
}
|
2018-06-19 20:04:26 +00:00
|
|
|
}
|
2018-06-19 23:59:25 +00:00
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 6 ) )
|
|
|
|
{
|
|
|
|
f.Read( sz );
|
|
|
|
m_data.callstackFrameMap.reserve( sz );
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
CallstackFrameId id;
|
|
|
|
f.Read( id );
|
|
|
|
|
|
|
|
auto frameData = m_slab.Alloc<CallstackFrameData>();
|
|
|
|
f.Read( frameData->size );
|
|
|
|
|
|
|
|
frameData->data = m_slab.Alloc<CallstackFrame>( frameData->size );
|
|
|
|
f.Read( frameData->data, sizeof( CallstackFrame ) * frameData->size );
|
|
|
|
|
|
|
|
m_data.callstackFrameMap.emplace( id, frameData );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( fileVer >= FileVersion( 0, 4, 3 ) )
|
2018-06-19 23:59:25 +00:00
|
|
|
{
|
2019-01-20 18:11:48 +00:00
|
|
|
f.Read( sz );
|
|
|
|
m_data.callstackFrameMap.reserve( sz );
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint64_t ptr;
|
|
|
|
f.Read( ptr );
|
|
|
|
|
|
|
|
auto frameData = m_slab.Alloc<CallstackFrameData>();
|
|
|
|
f.Read( frameData->size );
|
2018-06-19 23:59:25 +00:00
|
|
|
|
2019-01-20 18:11:48 +00:00
|
|
|
frameData->data = m_slab.Alloc<CallstackFrame>( frameData->size );
|
|
|
|
f.Read( frameData->data, sizeof( CallstackFrame ) * frameData->size );
|
2018-06-19 23:59:25 +00:00
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
m_data.callstackFrameMap.emplace( PackPointer( ptr ), frameData );
|
2019-01-20 18:11:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
f.Read( sz );
|
|
|
|
m_data.callstackFrameMap.reserve( sz );
|
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint64_t ptr;
|
|
|
|
f.Read( ptr );
|
|
|
|
|
|
|
|
auto frameData = m_slab.Alloc<CallstackFrameData>();
|
|
|
|
frameData->size = 1;
|
|
|
|
|
|
|
|
frameData->data = m_slab.Alloc<CallstackFrame>();
|
|
|
|
f.Read( frameData->data, sizeof( CallstackFrame ) );
|
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
m_data.callstackFrameMap.emplace( PackPointer( ptr ), frameData );
|
2019-01-20 18:11:48 +00:00
|
|
|
}
|
2018-06-19 23:59:25 +00:00
|
|
|
}
|
2018-06-24 15:10:46 +00:00
|
|
|
|
2019-06-06 21:08:19 +00:00
|
|
|
if( fileVer >= FileVersion( 0, 4, 9 ) )
|
|
|
|
{
|
2019-06-06 21:40:37 +00:00
|
|
|
s_loadProgress.subTotal.store( 0, std::memory_order_relaxed );
|
|
|
|
s_loadProgress.progress.store( LoadProgress::FrameImages, std::memory_order_relaxed );
|
|
|
|
|
2019-06-06 21:08:19 +00:00
|
|
|
if( eventMask & EventType::FrameImages )
|
|
|
|
{
|
2019-06-08 10:17:18 +00:00
|
|
|
size_t tmpbufsz = 0;
|
|
|
|
char* tmpbuf = nullptr;
|
2019-06-06 21:08:19 +00:00
|
|
|
f.Read( sz );
|
|
|
|
m_data.frameImage.reserve_exact( sz, m_slab );
|
2019-06-06 21:40:37 +00:00
|
|
|
s_loadProgress.subTotal.store( sz, std::memory_order_relaxed );
|
2019-06-06 21:08:19 +00:00
|
|
|
for( uint64_t i=0; i<sz; i++ )
|
|
|
|
{
|
2019-06-06 21:40:37 +00:00
|
|
|
s_loadProgress.subProgress.store( i, std::memory_order_relaxed );
|
2019-06-06 21:08:19 +00:00
|
|
|
auto fi = m_slab.Alloc<FrameImage>();
|
|
|
|
f.Read2( fi->w, fi->h );
|
2019-06-06 22:29:59 +00:00
|
|
|
const auto sz = fi->w * fi->h / 2;
|
2019-06-08 10:17:18 +00:00
|
|
|
if( tmpbufsz < sz )
|
|
|
|
{
|
|
|
|
tmpbufsz = sz;
|
|
|
|
delete[] tmpbuf;
|
|
|
|
tmpbuf = new char[sz];
|
|
|
|
}
|
|
|
|
f.Read( tmpbuf, sz );
|
|
|
|
fi->ptr = PackFrameImage( tmpbuf, fi->w, fi->h, fi->csz );
|
2019-06-06 21:08:19 +00:00
|
|
|
m_data.frameImage[i] = fi;
|
|
|
|
}
|
2019-06-08 10:17:18 +00:00
|
|
|
delete[] tmpbuf;
|
2019-06-11 22:55:02 +00:00
|
|
|
|
|
|
|
const auto& frames = GetFramesBase()->frames;
|
|
|
|
const auto fsz = uint32_t( frames.size() );
|
|
|
|
for( uint32_t i=0; i<fsz; i++ )
|
|
|
|
{
|
|
|
|
const auto& f = frames[i];
|
|
|
|
if( f.frameImage != -1 )
|
|
|
|
{
|
|
|
|
m_data.frameImage[f.frameImage]->frameRef = i;
|
|
|
|
}
|
|
|
|
}
|
2019-06-06 21:08:19 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Implement skip, if more data is added after frame image section
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-24 15:10:46 +00:00
|
|
|
finishLoading:
|
2019-02-14 00:17:37 +00:00
|
|
|
s_loadProgress.total.store( 0, std::memory_order_relaxed );
|
|
|
|
m_loadTime = std::chrono::duration_cast<std::chrono::nanoseconds>( std::chrono::high_resolution_clock::now() - loadStart ).count();
|
|
|
|
|
2019-06-02 13:00:38 +00:00
|
|
|
m_backgroundDone.store( false, std::memory_order_relaxed );
|
2019-02-14 00:17:37 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
|
|
|
m_threadBackground = std::thread( [this, reconstructMemAllocPlot] {
|
2019-03-13 00:46:05 +00:00
|
|
|
std::function<void(const Vector<ZoneEvent*>&, uint16_t)> ProcessTimeline;
|
|
|
|
ProcessTimeline = [this, &ProcessTimeline] ( const Vector<ZoneEvent*>& vec, uint16_t thread )
|
|
|
|
{
|
|
|
|
for( auto& zone : vec )
|
|
|
|
{
|
|
|
|
ReadTimelineUpdateStatistics( zone, thread );
|
|
|
|
if( zone->child >= 0 )
|
|
|
|
{
|
|
|
|
ProcessTimeline( GetZoneChildren( zone->child ), thread );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for( auto& t : m_data.threads )
|
|
|
|
{
|
2019-03-14 00:10:57 +00:00
|
|
|
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 );
|
|
|
|
}
|
2019-03-13 00:46:05 +00:00
|
|
|
}
|
2019-02-14 00:17:37 +00:00
|
|
|
for( auto& v : m_data.sourceLocationZones )
|
|
|
|
{
|
|
|
|
auto& zones = v.second.zones;
|
|
|
|
#ifdef MY_LIBCPP_SUCKS
|
|
|
|
pdqsort_branchless( zones.begin(), zones.end(), []( const auto& lhs, const auto& rhs ) { return lhs.zone->start < rhs.zone->start; } );
|
|
|
|
#else
|
|
|
|
std::sort( std::execution::par_unseq, zones.begin(), zones.end(), []( const auto& lhs, const auto& rhs ) { return lhs.zone->start < rhs.zone->start; } );
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
{
|
2019-05-28 17:21:53 +00:00
|
|
|
std::lock_guard<std::shared_mutex> lock( m_data.lock );
|
2019-02-14 00:17:37 +00:00
|
|
|
m_data.sourceLocationZonesReady = true;
|
|
|
|
}
|
|
|
|
if( reconstructMemAllocPlot ) ReconstructMemAllocPlot();
|
2019-06-02 13:00:38 +00:00
|
|
|
m_backgroundDone.store( true, std::memory_order_relaxed );
|
2019-02-14 00:17:37 +00:00
|
|
|
} );
|
|
|
|
#else
|
2018-06-24 15:10:46 +00:00
|
|
|
if( reconstructMemAllocPlot )
|
|
|
|
{
|
2019-06-02 13:00:38 +00:00
|
|
|
m_threadBackground = std::thread( [this] { ReconstructMemAllocPlot(); m_backgroundDone.store( true, std::memory_order_relaxed ); } );
|
2018-06-24 15:10:46 +00:00
|
|
|
}
|
2019-02-14 00:17:37 +00:00
|
|
|
#endif
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Worker::~Worker()
|
|
|
|
{
|
2018-02-15 12:19:20 +00:00
|
|
|
Shutdown();
|
2018-04-29 11:40:04 +00:00
|
|
|
|
|
|
|
if( m_thread.joinable() ) m_thread.join();
|
2019-02-14 00:17:37 +00:00
|
|
|
if( m_threadBackground.joinable() ) m_threadBackground.join();
|
2018-04-29 11:40:04 +00:00
|
|
|
|
2018-04-21 18:11:59 +00:00
|
|
|
delete[] m_buffer;
|
2018-02-15 12:19:20 +00:00
|
|
|
LZ4_freeStreamDecode( m_stream );
|
2018-04-21 18:12:16 +00:00
|
|
|
|
2019-06-08 10:17:18 +00:00
|
|
|
delete[] m_frameImageBuffer;
|
|
|
|
|
2018-04-21 18:34:29 +00:00
|
|
|
for( auto& v : m_data.threads )
|
|
|
|
{
|
2018-07-22 19:01:45 +00:00
|
|
|
v->timeline.~Vector();
|
|
|
|
v->stack.~Vector();
|
2018-04-21 18:36:33 +00:00
|
|
|
v->messages.~Vector();
|
2019-06-09 15:56:41 +00:00
|
|
|
v->zoneIdStack.~Vector();
|
2018-04-21 18:34:29 +00:00
|
|
|
}
|
2018-07-22 19:01:45 +00:00
|
|
|
for( auto& v : m_data.gpuData )
|
|
|
|
{
|
|
|
|
v->timeline.~Vector();
|
|
|
|
v->stack.~Vector();
|
|
|
|
}
|
2018-08-04 14:33:03 +00:00
|
|
|
for( auto& v : m_data.plots.Data() )
|
2018-04-21 18:12:16 +00:00
|
|
|
{
|
|
|
|
v->~PlotData();
|
|
|
|
}
|
2018-08-04 17:47:09 +00:00
|
|
|
for( auto& v : m_data.frames.Data() )
|
|
|
|
{
|
|
|
|
v->~FrameData();
|
|
|
|
}
|
2019-03-16 01:09:50 +00:00
|
|
|
for( auto& v : m_data.lockMap )
|
|
|
|
{
|
|
|
|
v.second->~LockMap();
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-08-08 17:21:53 +00:00
|
|
|
uint64_t Worker::GetLockCount() const
|
|
|
|
{
|
|
|
|
uint64_t cnt = 0;
|
|
|
|
for( auto& l : m_data.lockMap )
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
cnt += l.second->timeline.size();
|
2018-08-08 17:21:53 +00:00
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
uint64_t Worker::GetPlotCount() const
|
|
|
|
{
|
|
|
|
uint64_t cnt = 0;
|
|
|
|
for( auto& p : m_data.plots.Data() )
|
|
|
|
{
|
|
|
|
if( p->type != PlotType::Memory )
|
|
|
|
{
|
|
|
|
cnt += p->data.size();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return cnt;
|
|
|
|
}
|
|
|
|
|
2018-09-01 10:38:12 +00:00
|
|
|
size_t Worker::GetFullFrameCount( const FrameData& fd ) const
|
|
|
|
{
|
|
|
|
const auto sz = fd.frames.size();
|
|
|
|
assert( sz != 0 );
|
|
|
|
|
|
|
|
if( fd.continuous )
|
|
|
|
{
|
|
|
|
if( IsConnected() )
|
|
|
|
{
|
|
|
|
return sz - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto& last = fd.frames.back();
|
|
|
|
if( last.end >= 0 )
|
|
|
|
{
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return sz - 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-04 17:47:09 +00:00
|
|
|
int64_t Worker::GetFrameTime( const FrameData& fd, size_t idx ) const
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-08-05 00:09:59 +00:00
|
|
|
if( fd.continuous )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-08-05 00:09:59 +00:00
|
|
|
if( idx < fd.frames.size() - 1 )
|
|
|
|
{
|
|
|
|
return fd.frames[idx+1].start - fd.frames[idx].start;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert( m_data.lastTime != 0 );
|
|
|
|
return m_data.lastTime - fd.frames.back().start;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-29 21:10:14 +00:00
|
|
|
const auto& frame = fd.frames[idx];
|
|
|
|
if( frame.end >= 0 )
|
2018-08-05 00:09:59 +00:00
|
|
|
{
|
2019-01-29 21:10:14 +00:00
|
|
|
return frame.end - frame.start;
|
2018-08-05 00:09:59 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_data.lastTime - fd.frames.back().start;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-04 17:47:09 +00:00
|
|
|
int64_t Worker::GetFrameBegin( const FrameData& fd, size_t idx ) const
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-08-04 17:47:09 +00:00
|
|
|
assert( idx < fd.frames.size() );
|
2018-08-05 00:09:59 +00:00
|
|
|
return fd.frames[idx].start;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 17:47:09 +00:00
|
|
|
int64_t Worker::GetFrameEnd( const FrameData& fd, size_t idx ) const
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-08-05 00:09:59 +00:00
|
|
|
if( fd.continuous )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-08-05 00:09:59 +00:00
|
|
|
if( idx < fd.frames.size() - 1 )
|
|
|
|
{
|
|
|
|
return fd.frames[idx+1].start;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_data.lastTime;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-08-05 00:09:59 +00:00
|
|
|
if( fd.frames[idx].end >= 0 )
|
|
|
|
{
|
|
|
|
return fd.frames[idx].end;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_data.lastTime;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 19:48:01 +00:00
|
|
|
const FrameImage* Worker::GetFrameImage( const FrameData& fd, size_t idx ) const
|
|
|
|
{
|
|
|
|
assert( idx < fd.frames.size() );
|
|
|
|
const auto& v = fd.frames[idx].frameImage;
|
|
|
|
if( v < 0 ) return nullptr;
|
|
|
|
return m_data.frameImage[v];
|
|
|
|
}
|
|
|
|
|
2018-08-04 17:47:09 +00:00
|
|
|
std::pair <int, int> Worker::GetFrameRange( const FrameData& fd, int64_t from, int64_t to )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-08-05 00:09:59 +00:00
|
|
|
auto zitbegin = std::lower_bound( fd.frames.begin(), fd.frames.end(), from, [] ( const auto& lhs, const auto& rhs ) { return lhs.start < rhs; } );
|
2018-08-04 21:19:35 +00:00
|
|
|
if( zitbegin == fd.frames.end() ) zitbegin--;
|
|
|
|
|
2018-08-05 00:09:59 +00:00
|
|
|
const auto zitend = std::lower_bound( zitbegin, fd.frames.end(), to, [] ( const auto& lhs, const auto& rhs ) { return lhs.start < rhs; } );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-08-04 17:47:09 +00:00
|
|
|
int zbegin = std::distance( fd.frames.begin(), zitbegin );
|
2018-08-05 00:09:59 +00:00
|
|
|
if( zbegin > 0 && zitbegin->start != from ) --zbegin;
|
2018-08-04 17:47:09 +00:00
|
|
|
const int zend = std::distance( fd.frames.begin(), zitend );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
return std::make_pair( zbegin, zend );
|
|
|
|
}
|
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
const CallstackFrameData* Worker::GetCallstackFrame( const CallstackFrameId& ptr ) const
|
2018-06-19 23:18:59 +00:00
|
|
|
{
|
|
|
|
auto it = m_data.callstackFrameMap.find( ptr );
|
|
|
|
if( it == m_data.callstackFrameMap.end() )
|
|
|
|
{
|
|
|
|
return nullptr;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-23 00:50:38 +00:00
|
|
|
int64_t Worker::GetZoneEnd( const ZoneEvent& ev )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
auto ptr = &ev;
|
|
|
|
for(;;)
|
|
|
|
{
|
2018-03-24 01:00:20 +00:00
|
|
|
if( ptr->end >= 0 ) return ptr->end;
|
2018-07-22 14:05:50 +00:00
|
|
|
if( ptr->child < 0 ) return ptr->start;
|
|
|
|
ptr = GetZoneChildren( ptr->child ).back();
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-23 00:50:38 +00:00
|
|
|
int64_t Worker::GetZoneEnd( const GpuEvent& ev )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
auto ptr = &ev;
|
|
|
|
for(;;)
|
|
|
|
{
|
2018-03-24 01:00:20 +00:00
|
|
|
if( ptr->gpuEnd >= 0 ) return ptr->gpuEnd;
|
2018-07-22 17:47:01 +00:00
|
|
|
if( ptr->child < 0 ) return ptr->gpuStart;
|
|
|
|
ptr = GetGpuChildren( ptr->child ).back();
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Worker::GetString( uint64_t ptr ) const
|
|
|
|
{
|
|
|
|
const auto it = m_data.strings.find( ptr );
|
|
|
|
if( it == m_data.strings.end() || it->second == nullptr )
|
|
|
|
{
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Worker::GetString( const StringRef& ref ) const
|
|
|
|
{
|
|
|
|
if( ref.isidx )
|
|
|
|
{
|
|
|
|
assert( ref.active );
|
2018-03-04 16:52:51 +00:00
|
|
|
return m_data.stringData[ref.str];
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( ref.active )
|
|
|
|
{
|
2018-03-04 16:52:51 +00:00
|
|
|
return GetString( ref.str );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Worker::GetString( const StringIdx& idx ) const
|
|
|
|
{
|
|
|
|
assert( idx.active );
|
|
|
|
return m_data.stringData[idx.idx];
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Worker::GetThreadString( uint64_t id ) const
|
|
|
|
{
|
|
|
|
const auto it = m_data.threadNames.find( id );
|
|
|
|
if( it == m_data.threadNames.end() )
|
|
|
|
{
|
|
|
|
return "???";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const SourceLocation& Worker::GetSourceLocation( int32_t srcloc ) const
|
|
|
|
{
|
|
|
|
if( srcloc < 0 )
|
|
|
|
{
|
|
|
|
return *m_data.sourceLocationPayload[-srcloc-1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
const auto it = m_data.sourceLocation.find( m_data.sourceLocationExpand[srcloc] );
|
|
|
|
assert( it != m_data.sourceLocation.end() );
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-10 15:45:19 +00:00
|
|
|
const char* Worker::GetZoneName( const SourceLocation& srcloc ) const
|
|
|
|
{
|
|
|
|
if( srcloc.name.active )
|
|
|
|
{
|
|
|
|
return GetString( srcloc.name );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return GetString( srcloc.function );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-29 13:14:20 +00:00
|
|
|
const char* Worker::GetZoneName( const ZoneEvent& ev ) const
|
|
|
|
{
|
|
|
|
auto& srcloc = GetSourceLocation( ev.srcloc );
|
|
|
|
return GetZoneName( ev, srcloc );
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Worker::GetZoneName( const ZoneEvent& ev, const SourceLocation& srcloc ) const
|
|
|
|
{
|
2018-06-29 14:12:40 +00:00
|
|
|
if( ev.name.active )
|
|
|
|
{
|
|
|
|
return GetString( ev.name );
|
|
|
|
}
|
|
|
|
else if( srcloc.name.active )
|
2018-06-29 13:14:20 +00:00
|
|
|
{
|
|
|
|
return GetString( srcloc.name );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return GetString( srcloc.function );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Worker::GetZoneName( const GpuEvent& ev ) const
|
|
|
|
{
|
|
|
|
auto& srcloc = GetSourceLocation( ev.srcloc );
|
|
|
|
return GetZoneName( ev, srcloc );
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Worker::GetZoneName( const GpuEvent& ev, const SourceLocation& srcloc ) const
|
|
|
|
{
|
2018-07-15 17:00:40 +00:00
|
|
|
if( srcloc.name.active )
|
|
|
|
{
|
|
|
|
return GetString( srcloc.name );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return GetString( srcloc.function );
|
|
|
|
}
|
2018-06-29 13:14:20 +00:00
|
|
|
}
|
|
|
|
|
2018-12-18 15:52:05 +00:00
|
|
|
static bool strstr_nocase( const char* l, const char* r )
|
|
|
|
{
|
|
|
|
const auto lsz = strlen( l );
|
|
|
|
const auto rsz = strlen( r );
|
|
|
|
auto ll = (char*)alloca( lsz + 1 );
|
|
|
|
auto rl = (char*)alloca( lsz + 1 );
|
|
|
|
for( size_t i=0; i<lsz; i++ )
|
|
|
|
{
|
|
|
|
ll[i] = tolower( l[i] );
|
|
|
|
}
|
|
|
|
ll[lsz] = '\0';
|
|
|
|
for( size_t i=0; i<rsz; i++ )
|
|
|
|
{
|
|
|
|
rl[i] = tolower( r[i] );
|
|
|
|
}
|
|
|
|
rl[rsz] = '\0';
|
|
|
|
return strstr( ll, rl ) != nullptr;
|
|
|
|
}
|
|
|
|
|
2018-12-18 15:52:29 +00:00
|
|
|
std::vector<int32_t> Worker::GetMatchingSourceLocation( const char* query, bool ignoreCase ) const
|
2018-03-04 15:52:45 +00:00
|
|
|
{
|
|
|
|
std::vector<int32_t> match;
|
|
|
|
|
|
|
|
const auto sz = m_data.sourceLocationExpand.size();
|
2018-03-04 15:57:57 +00:00
|
|
|
for( size_t i=1; i<sz; i++ )
|
2018-03-04 15:52:45 +00:00
|
|
|
{
|
|
|
|
const auto it = m_data.sourceLocation.find( m_data.sourceLocationExpand[i] );
|
|
|
|
assert( it != m_data.sourceLocation.end() );
|
|
|
|
const auto& srcloc = it->second;
|
|
|
|
const auto str = GetString( srcloc.name.active ? srcloc.name : srcloc.function );
|
2018-12-18 15:52:29 +00:00
|
|
|
bool found = false;
|
|
|
|
if( ignoreCase )
|
|
|
|
{
|
|
|
|
found = strstr_nocase( str, query );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
found = strstr( str, query ) != nullptr;
|
|
|
|
}
|
|
|
|
if( found )
|
2018-03-04 15:52:45 +00:00
|
|
|
{
|
|
|
|
match.push_back( (int32_t)i );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for( auto& srcloc : m_data.sourceLocationPayload )
|
|
|
|
{
|
|
|
|
const auto str = GetString( srcloc->name.active ? srcloc->name : srcloc->function );
|
2018-12-18 15:52:29 +00:00
|
|
|
bool found = false;
|
|
|
|
if( ignoreCase )
|
|
|
|
{
|
|
|
|
found = strstr_nocase( str, query );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
found = strstr( str, query ) != nullptr;
|
|
|
|
}
|
|
|
|
if( found )
|
2018-03-04 15:52:45 +00:00
|
|
|
{
|
|
|
|
auto it = m_data.sourceLocationPayloadMap.find( srcloc );
|
|
|
|
assert( it != m_data.sourceLocationPayloadMap.end() );
|
2018-03-04 16:17:25 +00:00
|
|
|
match.push_back( -int32_t( it->second + 1 ) );
|
2018-03-04 15:52:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return match;
|
|
|
|
}
|
|
|
|
|
2018-03-18 11:55:54 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
2018-03-18 19:20:24 +00:00
|
|
|
const Worker::SourceLocationZones& Worker::GetZonesForSourceLocation( int32_t srcloc ) const
|
2018-03-18 01:35:39 +00:00
|
|
|
{
|
2018-03-18 19:20:24 +00:00
|
|
|
static const SourceLocationZones empty;
|
2018-03-18 01:35:39 +00:00
|
|
|
auto it = m_data.sourceLocationZones.find( srcloc );
|
2018-03-18 19:20:24 +00:00
|
|
|
return it != m_data.sourceLocationZones.end() ? it->second : empty;
|
2018-03-18 01:35:39 +00:00
|
|
|
}
|
2018-03-18 11:55:54 +00:00
|
|
|
#endif
|
2018-03-18 01:35:39 +00:00
|
|
|
|
2018-04-30 23:29:25 +00:00
|
|
|
uint16_t Worker::CompressThreadReal( uint64_t thread )
|
2018-03-18 19:45:22 +00:00
|
|
|
{
|
|
|
|
auto it = m_data.threadMap.find( thread );
|
|
|
|
if( it != m_data.threadMap.end() )
|
|
|
|
{
|
2018-04-30 23:29:25 +00:00
|
|
|
m_data.threadLast.first = thread;
|
|
|
|
m_data.threadLast.second = it->second;
|
2018-03-18 19:45:22 +00:00
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-03-24 00:31:58 +00:00
|
|
|
return CompressThreadNew( thread );
|
2018-03-18 19:45:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-24 00:31:58 +00:00
|
|
|
uint16_t Worker::CompressThreadNew( uint64_t thread )
|
2018-03-18 19:45:22 +00:00
|
|
|
{
|
2018-03-24 00:31:58 +00:00
|
|
|
auto sz = m_data.threadExpand.size();
|
|
|
|
m_data.threadExpand.push_back( thread );
|
|
|
|
m_data.threadMap.emplace( thread, sz );
|
2018-04-30 23:29:25 +00:00
|
|
|
m_data.threadLast.first = thread;
|
|
|
|
m_data.threadLast.second = sz;
|
2018-03-24 00:31:58 +00:00
|
|
|
return sz;
|
2018-03-18 19:45:22 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::Exec()
|
|
|
|
{
|
|
|
|
auto ShouldExit = [this]
|
|
|
|
{
|
|
|
|
return m_shutdown.load( std::memory_order_relaxed );
|
|
|
|
};
|
|
|
|
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
if( m_shutdown.load( std::memory_order_relaxed ) ) return;
|
2018-09-09 15:47:20 +00:00
|
|
|
if( m_sock.Connect( m_addr.c_str(), "8086" ) ) break;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
auto lz4buf = std::make_unique<char[]>( LZ4Size );
|
2018-09-09 17:28:53 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
std::chrono::time_point<std::chrono::high_resolution_clock> t0;
|
|
|
|
|
|
|
|
uint64_t bytes = 0;
|
|
|
|
uint64_t decBytes = 0;
|
|
|
|
|
2018-09-09 17:28:53 +00:00
|
|
|
m_sock.Send( HandshakeShibboleth, HandshakeShibbolethSize );
|
|
|
|
uint32_t protocolVersion = ProtocolVersion;
|
|
|
|
m_sock.Send( &protocolVersion, sizeof( protocolVersion ) );
|
|
|
|
HandshakeStatus handshake;
|
2019-02-12 00:41:09 +00:00
|
|
|
if( !m_sock.Read( &handshake, sizeof( handshake ), 10, ShouldExit ) )
|
|
|
|
{
|
|
|
|
m_handshake.store( HandshakeDropped, std::memory_order_relaxed );
|
|
|
|
goto close;
|
|
|
|
}
|
2018-09-09 17:28:53 +00:00
|
|
|
m_handshake.store( handshake, std::memory_order_relaxed );
|
|
|
|
switch( handshake )
|
|
|
|
{
|
|
|
|
case HandshakeWelcome:
|
|
|
|
break;
|
|
|
|
case HandshakeProtocolMismatch:
|
2018-09-09 17:42:06 +00:00
|
|
|
case HandshakeNotAvailable:
|
2018-09-09 17:28:53 +00:00
|
|
|
default:
|
|
|
|
goto close;
|
|
|
|
}
|
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
m_data.framesBase = m_data.frames.Retrieve( 0, [this] ( uint64_t name ) {
|
|
|
|
auto fd = m_slab.AllocInit<FrameData>();
|
|
|
|
fd->name = name;
|
|
|
|
fd->continuous = 1;
|
|
|
|
return fd;
|
|
|
|
}, [this] ( uint64_t name ) {
|
|
|
|
assert( name == 0 );
|
|
|
|
char tmp[6] = "Frame";
|
|
|
|
HandleFrameName( name, tmp, 5 );
|
|
|
|
} );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
{
|
|
|
|
WelcomeMessage welcome;
|
2019-02-12 10:07:12 +00:00
|
|
|
if( !m_sock.Read( &welcome, sizeof( welcome ), 10, ShouldExit ) )
|
|
|
|
{
|
|
|
|
m_handshake.store( HandshakeDropped, std::memory_order_relaxed );
|
|
|
|
goto close;
|
|
|
|
}
|
2018-09-09 15:47:20 +00:00
|
|
|
m_timerMul = welcome.timerMul;
|
|
|
|
const auto initEnd = TscTime( welcome.initEnd );
|
2019-06-06 19:44:48 +00:00
|
|
|
m_data.framesBase->frames.push_back( FrameEvent{ TscTime( welcome.initBegin ), -1, -1 } );
|
|
|
|
m_data.framesBase->frames.push_back( FrameEvent{ initEnd, -1, -1 } );
|
2018-09-09 15:47:20 +00:00
|
|
|
m_data.lastTime = initEnd;
|
|
|
|
m_delay = TscTime( welcome.delay );
|
|
|
|
m_resolution = TscTime( welcome.resolution );
|
|
|
|
m_onDemand = welcome.onDemand;
|
|
|
|
m_captureProgram = welcome.programName;
|
|
|
|
m_captureTime = welcome.epoch;
|
|
|
|
|
|
|
|
char dtmp[64];
|
|
|
|
time_t date = welcome.epoch;
|
|
|
|
auto lt = localtime( &date );
|
|
|
|
strftime( dtmp, 64, "%F %T", lt );
|
|
|
|
char tmp[1024];
|
|
|
|
sprintf( tmp, "%s @ %s", welcome.programName, dtmp );
|
|
|
|
m_captureName = tmp;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
m_hostInfo = welcome.hostInfo;
|
2018-08-04 17:47:09 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
if( welcome.onDemand != 0 )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-09-09 15:47:20 +00:00
|
|
|
OnDemandPayloadMessage onDemand;
|
2019-02-12 10:07:12 +00:00
|
|
|
if( !m_sock.Read( &onDemand, sizeof( onDemand ), 10, ShouldExit ) )
|
|
|
|
{
|
|
|
|
m_handshake.store( HandshakeDropped, std::memory_order_relaxed );
|
|
|
|
goto close;
|
|
|
|
}
|
2018-09-09 15:47:20 +00:00
|
|
|
m_data.frameOffset = onDemand.frames;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2018-09-09 15:47:20 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2019-06-09 13:58:56 +00:00
|
|
|
m_serverQuerySpaceLeft = ( m_sock.GetSendBufSize() / ServerQueryPacketSize ) - ServerQueryPacketSize; // leave space for terminate request
|
2018-09-09 15:47:20 +00:00
|
|
|
m_hasData.store( true, std::memory_order_release );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
LZ4_setStreamDecode( m_stream, nullptr, 0 );
|
|
|
|
m_connected.store( true, std::memory_order_relaxed );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
t0 = std::chrono::high_resolution_clock::now();
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
for(;;)
|
|
|
|
{
|
2019-06-09 14:06:34 +00:00
|
|
|
if( m_shutdown.load( std::memory_order_relaxed ) )
|
|
|
|
{
|
|
|
|
QueryTerminate();
|
|
|
|
return;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
auto buf = m_buffer + m_bufferOffset;
|
|
|
|
lz4sz_t lz4sz;
|
2019-02-10 14:45:23 +00:00
|
|
|
if( !m_sock.Read( &lz4sz, sizeof( lz4sz ), 10, ShouldExit ) ) goto close;
|
|
|
|
if( !m_sock.Read( lz4buf.get(), lz4sz, 10, ShouldExit ) ) goto close;
|
2018-09-09 15:47:20 +00:00
|
|
|
bytes += sizeof( lz4sz ) + lz4sz;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
auto sz = LZ4_decompress_safe_continue( m_stream, lz4buf.get(), buf, lz4sz, TargetFrameSize );
|
|
|
|
assert( sz >= 0 );
|
|
|
|
decBytes += sz;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
char* ptr = buf;
|
|
|
|
const char* end = buf + sz;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
{
|
2019-05-28 17:21:53 +00:00
|
|
|
std::lock_guard<std::shared_mutex> lock( m_data.lock );
|
2018-09-09 15:47:20 +00:00
|
|
|
while( ptr < end )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-09-09 15:47:20 +00:00
|
|
|
auto ev = (const QueueItem*)ptr;
|
2019-06-09 14:06:34 +00:00
|
|
|
if( !DispatchProcess( *ev, ptr ) )
|
|
|
|
{
|
|
|
|
QueryTerminate();
|
|
|
|
goto close;
|
|
|
|
}
|
2018-09-09 15:47:20 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
m_bufferOffset += sz;
|
|
|
|
if( m_bufferOffset > TargetFrameSize * 2 ) m_bufferOffset = 0;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
HandlePostponedPlots();
|
2019-04-01 17:47:29 +00:00
|
|
|
|
|
|
|
while( !m_serverQueryQueue.empty() && m_serverQuerySpaceLeft > 0 )
|
|
|
|
{
|
|
|
|
m_serverQuerySpaceLeft--;
|
|
|
|
const auto& query = m_serverQueryQueue.back();
|
|
|
|
m_sock.Send( &query, ServerQueryPacketSize );
|
|
|
|
m_serverQueryQueue.pop_back();
|
|
|
|
}
|
2018-09-09 15:47:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto t1 = std::chrono::high_resolution_clock::now();
|
|
|
|
auto td = std::chrono::duration_cast<std::chrono::milliseconds>( t1 - t0 ).count();
|
|
|
|
enum { MbpsUpdateTime = 200 };
|
|
|
|
if( td > MbpsUpdateTime )
|
|
|
|
{
|
2019-05-28 17:21:53 +00:00
|
|
|
std::lock_guard<std::shared_mutex> lock( m_mbpsData.lock );
|
2018-09-09 15:47:20 +00:00
|
|
|
m_mbpsData.mbps.erase( m_mbpsData.mbps.begin() );
|
|
|
|
m_mbpsData.mbps.emplace_back( bytes / ( td * 125.f ) );
|
|
|
|
m_mbpsData.compRatio = float( bytes ) / decBytes;
|
2019-04-01 17:55:37 +00:00
|
|
|
m_mbpsData.queue = m_serverQueryQueue.size();
|
2018-09-09 15:47:20 +00:00
|
|
|
t0 = t1;
|
|
|
|
bytes = 0;
|
|
|
|
decBytes = 0;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-09-09 15:47:20 +00:00
|
|
|
if( m_terminate )
|
|
|
|
{
|
|
|
|
if( m_pendingStrings != 0 || m_pendingThreads != 0 || m_pendingSourceLocation != 0 || m_pendingCallstackFrames != 0 ||
|
2019-06-06 19:39:54 +00:00
|
|
|
!m_pendingCustomStrings.empty() || m_data.plots.IsPending() || m_pendingCallstackPtr != 0 ||
|
|
|
|
m_pendingCallstackSubframes != 0 || !m_pendingFrameImageData.empty() )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-09-09 15:47:20 +00:00
|
|
|
continue;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2018-09-09 15:47:20 +00:00
|
|
|
if( !m_crashed )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-09-09 15:47:20 +00:00
|
|
|
bool done = true;
|
|
|
|
for( auto& v : m_data.threads )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-09-09 15:47:20 +00:00
|
|
|
if( !v->stack.empty() )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-09-09 15:47:20 +00:00
|
|
|
done = false;
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-09 15:47:20 +00:00
|
|
|
if( !done ) continue;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQueryTerminate, 0 );
|
2018-09-09 15:47:20 +00:00
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2018-09-09 15:47:20 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
close:
|
2018-09-09 15:47:20 +00:00
|
|
|
m_sock.Close();
|
|
|
|
m_connected.store( false, std::memory_order_relaxed );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 16:52:32 +00:00
|
|
|
void Worker::Query( ServerQuery type, uint64_t data )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2019-06-09 13:58:56 +00:00
|
|
|
ServerQueryPacket query { type, data };
|
2019-04-01 17:47:29 +00:00
|
|
|
if( m_serverQuerySpaceLeft > 0 )
|
|
|
|
{
|
|
|
|
m_serverQuerySpaceLeft--;
|
|
|
|
m_sock.Send( &query, ServerQueryPacketSize );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_serverQueryQueue.insert( m_serverQueryQueue.begin(), query );
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2019-06-09 13:58:56 +00:00
|
|
|
void Worker::QueryTerminate()
|
|
|
|
{
|
|
|
|
ServerQueryPacket query { ServerQueryTerminate, 0 };
|
|
|
|
m_sock.Send( &query, ServerQueryPacketSize );
|
|
|
|
}
|
|
|
|
|
2019-01-14 22:08:34 +00:00
|
|
|
bool Worker::DispatchProcess( const QueueItem& ev, char*& ptr )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-06-19 17:15:19 +00:00
|
|
|
if( ev.hdr.idx >= (int)QueueType::StringData )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
ptr += sizeof( QueueHeader ) + sizeof( QueueStringTransfer );
|
2019-06-06 19:39:54 +00:00
|
|
|
if( ev.hdr.type == QueueType::FrameImageData )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2019-06-06 19:39:54 +00:00
|
|
|
uint32_t sz;
|
|
|
|
memcpy( &sz, ptr, sizeof( sz ) );
|
|
|
|
ptr += sizeof( sz );
|
|
|
|
AddFrameImageData( ev.stringTransfer.ptr, ptr, sz );
|
|
|
|
ptr += sz;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
uint16_t sz;
|
|
|
|
memcpy( &sz, ptr, sizeof( sz ) );
|
|
|
|
ptr += sizeof( sz );
|
|
|
|
switch( ev.hdr.type )
|
|
|
|
{
|
|
|
|
case QueueType::CustomStringData:
|
|
|
|
AddCustomString( ev.stringTransfer.ptr, ptr, sz );
|
|
|
|
break;
|
|
|
|
case QueueType::StringData:
|
|
|
|
AddString( ev.stringTransfer.ptr, ptr, sz );
|
|
|
|
m_serverQuerySpaceLeft++;
|
|
|
|
break;
|
|
|
|
case QueueType::ThreadName:
|
|
|
|
AddThreadString( ev.stringTransfer.ptr, ptr, sz );
|
|
|
|
m_serverQuerySpaceLeft++;
|
|
|
|
break;
|
|
|
|
case QueueType::PlotName:
|
|
|
|
HandlePlotName( ev.stringTransfer.ptr, ptr, sz );
|
|
|
|
m_serverQuerySpaceLeft++;
|
|
|
|
break;
|
|
|
|
case QueueType::SourceLocationPayload:
|
|
|
|
AddSourceLocationPayload( ev.stringTransfer.ptr, ptr, sz );
|
|
|
|
break;
|
|
|
|
case QueueType::CallstackPayload:
|
|
|
|
AddCallstackPayload( ev.stringTransfer.ptr, ptr, sz );
|
|
|
|
break;
|
|
|
|
case QueueType::FrameName:
|
|
|
|
HandleFrameName( ev.stringTransfer.ptr, ptr, sz );
|
|
|
|
m_serverQuerySpaceLeft++;
|
|
|
|
break;
|
|
|
|
case QueueType::CallstackAllocPayload:
|
|
|
|
AddCallstackAllocPayload( ev.stringTransfer.ptr, ptr, sz );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ptr += sz;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2019-01-14 22:08:34 +00:00
|
|
|
return true;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ptr += QueueDataSize[ev.hdr.idx];
|
2019-01-14 22:08:34 +00:00
|
|
|
return Process( ev );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::CheckSourceLocation( uint64_t ptr )
|
|
|
|
{
|
2018-03-04 15:23:28 +00:00
|
|
|
if( m_data.sourceLocation.find( ptr ) == m_data.sourceLocation.end() )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
NewSourceLocation( ptr );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::NewSourceLocation( uint64_t ptr )
|
|
|
|
{
|
|
|
|
static const SourceLocation emptySourceLocation = {};
|
|
|
|
|
|
|
|
m_data.sourceLocation.emplace( ptr, emptySourceLocation );
|
|
|
|
m_pendingSourceLocation++;
|
|
|
|
m_sourceLocationQueue.push_back( ptr );
|
|
|
|
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQuerySourceLocation, ptr );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Worker::ShrinkSourceLocation( uint64_t srcloc )
|
|
|
|
{
|
|
|
|
auto it = m_sourceLocationShrink.find( srcloc );
|
|
|
|
if( it != m_sourceLocationShrink.end() )
|
|
|
|
{
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NewShrinkedSourceLocation( srcloc );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
uint32_t Worker::NewShrinkedSourceLocation( uint64_t srcloc )
|
|
|
|
{
|
2019-03-03 15:50:18 +00:00
|
|
|
const auto sz = int32_t( m_data.sourceLocationExpand.size() );
|
2018-02-13 13:57:47 +00:00
|
|
|
m_data.sourceLocationExpand.push_back( srcloc );
|
2018-03-18 11:55:54 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
2018-03-18 19:08:57 +00:00
|
|
|
m_data.sourceLocationZones.emplace( sz, SourceLocationZones() );
|
2018-07-29 12:16:13 +00:00
|
|
|
#else
|
|
|
|
m_data.sourceLocationZonesCnt.emplace( sz, 0 );
|
2018-03-18 11:55:54 +00:00
|
|
|
#endif
|
2018-02-13 13:57:47 +00:00
|
|
|
m_sourceLocationShrink.emplace( srcloc, sz );
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::InsertMessageData( MessageData* msg, uint64_t thread )
|
|
|
|
{
|
|
|
|
if( m_data.messages.empty() )
|
|
|
|
{
|
|
|
|
m_data.messages.push_back( msg );
|
|
|
|
}
|
|
|
|
else if( m_data.messages.back()->time < msg->time )
|
|
|
|
{
|
|
|
|
m_data.messages.push_back_non_empty( msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto mit = std::lower_bound( m_data.messages.begin(), m_data.messages.end(), msg->time, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } );
|
|
|
|
m_data.messages.insert( mit, msg );
|
|
|
|
}
|
|
|
|
|
|
|
|
auto vec = &NoticeThread( thread )->messages;
|
|
|
|
if( vec->empty() )
|
|
|
|
{
|
|
|
|
vec->push_back( msg );
|
|
|
|
}
|
|
|
|
else if( vec->back()->time < msg->time )
|
|
|
|
{
|
|
|
|
vec->push_back_non_empty( msg );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto tmit = std::lower_bound( vec->begin(), vec->end(), msg->time, [] ( const auto& lhs, const auto& rhs ) { return lhs->time < rhs; } );
|
|
|
|
vec->insert( tmit, msg );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadData* Worker::NoticeThread( uint64_t thread )
|
|
|
|
{
|
|
|
|
auto it = m_threadMap.find( thread );
|
|
|
|
if( it != m_threadMap.end() )
|
|
|
|
{
|
|
|
|
return it->second;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return NewThread( thread );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ThreadData* Worker::NewThread( uint64_t thread )
|
|
|
|
{
|
|
|
|
CheckThreadString( thread );
|
|
|
|
auto td = m_slab.AllocInit<ThreadData>();
|
|
|
|
td->id = thread;
|
|
|
|
td->count = 0;
|
2019-01-14 21:56:10 +00:00
|
|
|
td->nextZoneId = 0;
|
2018-02-13 13:57:47 +00:00
|
|
|
m_data.threads.push_back( td );
|
|
|
|
m_threadMap.emplace( thread, td );
|
|
|
|
return td;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::NewZone( ZoneEvent* zone, uint64_t thread )
|
|
|
|
{
|
|
|
|
m_data.zonesCnt++;
|
2018-03-18 01:05:33 +00:00
|
|
|
|
2018-03-18 11:55:54 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
2018-03-18 01:05:33 +00:00
|
|
|
auto it = m_data.sourceLocationZones.find( zone->srcloc );
|
|
|
|
assert( it != m_data.sourceLocationZones.end() );
|
2018-03-18 19:45:49 +00:00
|
|
|
it->second.zones.push_back( ZoneThreadData { zone, CompressThread( thread ) } );
|
2018-07-29 12:16:13 +00:00
|
|
|
#else
|
|
|
|
auto it = m_data.sourceLocationZonesCnt.find( zone->srcloc );
|
|
|
|
assert( it != m_data.sourceLocationZonesCnt.end() );
|
|
|
|
it->second++;
|
2018-03-18 11:55:54 +00:00
|
|
|
#endif
|
2018-03-18 01:05:33 +00:00
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
auto td = NoticeThread( thread );
|
|
|
|
td->count++;
|
|
|
|
if( td->stack.empty() )
|
|
|
|
{
|
|
|
|
td->stack.push_back( zone );
|
|
|
|
td->timeline.push_back( zone );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-07-22 14:05:50 +00:00
|
|
|
auto back = td->stack.back();
|
|
|
|
if( back->child < 0 )
|
|
|
|
{
|
2019-03-26 20:41:44 +00:00
|
|
|
back->child = int32_t( m_data.zoneChildren.size() );
|
2019-03-26 21:06:00 +00:00
|
|
|
if( m_data.zoneVectorCache.empty() )
|
|
|
|
{
|
|
|
|
m_data.zoneChildren.push_back( Vector<ZoneEvent*>( zone ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Vector<ZoneEvent*> vze = std::move( m_data.zoneVectorCache.back_and_pop() );
|
|
|
|
assert( !vze.empty() );
|
|
|
|
vze.clear();
|
|
|
|
vze.push_back_non_empty( zone );
|
|
|
|
m_data.zoneChildren.push_back( std::move( vze ) );
|
|
|
|
}
|
2018-07-22 14:05:50 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-26 20:41:44 +00:00
|
|
|
m_data.zoneChildren[back->child].push_back( zone );
|
2018-07-22 14:05:50 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
td->stack.push_back_non_empty( zone );
|
|
|
|
}
|
2019-01-14 22:08:34 +00:00
|
|
|
|
|
|
|
td->zoneIdStack.push_back( td->nextZoneId );
|
|
|
|
td->nextZoneId = 0;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::InsertLockEvent( LockMap& lockmap, LockEvent* lev, uint64_t thread )
|
|
|
|
{
|
2019-03-16 01:19:07 +00:00
|
|
|
const auto lt = lev->time;
|
|
|
|
m_data.lastTime = std::max( m_data.lastTime, lt );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
NoticeThread( thread );
|
|
|
|
|
|
|
|
auto it = lockmap.threadMap.find( thread );
|
|
|
|
if( it == lockmap.threadMap.end() )
|
|
|
|
{
|
|
|
|
assert( lockmap.threadList.size() < MaxLockThreads );
|
|
|
|
it = lockmap.threadMap.emplace( thread, lockmap.threadList.size() ).first;
|
|
|
|
lockmap.threadList.emplace_back( thread );
|
|
|
|
}
|
|
|
|
lev->thread = it->second;
|
|
|
|
assert( lev->thread == it->second );
|
|
|
|
auto& timeline = lockmap.timeline;
|
|
|
|
if( timeline.empty() )
|
|
|
|
{
|
2019-03-16 13:18:43 +00:00
|
|
|
timeline.push_back( { lev } );
|
2018-02-13 13:57:47 +00:00
|
|
|
UpdateLockCount( lockmap, timeline.size() - 1 );
|
|
|
|
}
|
2019-03-21 20:24:07 +00:00
|
|
|
else if( timeline.back().ptr->time <= lt )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2019-03-16 13:18:43 +00:00
|
|
|
timeline.push_back_non_empty( { lev } );
|
2018-02-13 13:57:47 +00:00
|
|
|
UpdateLockCount( lockmap, timeline.size() - 1 );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-21 20:24:07 +00:00
|
|
|
auto it = std::upper_bound( timeline.begin(), timeline.end(), lt, [] ( const auto& lhs, const auto& rhs ) { return lhs < rhs.ptr->time; } );
|
2019-03-16 13:18:43 +00:00
|
|
|
it = timeline.insert( it, { lev } );
|
2018-02-13 13:57:47 +00:00
|
|
|
UpdateLockCount( lockmap, std::distance( timeline.begin(), it ) );
|
|
|
|
}
|
2019-03-16 01:19:19 +00:00
|
|
|
|
|
|
|
auto& range = lockmap.range[it->second];
|
|
|
|
if( range.start > lt ) range.start = lt;
|
|
|
|
if( range.end < lt ) range.end = lt;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::CheckString( uint64_t ptr )
|
|
|
|
{
|
|
|
|
if( ptr == 0 ) return;
|
|
|
|
if( m_data.strings.find( ptr ) != m_data.strings.end() ) return;
|
|
|
|
|
|
|
|
m_data.strings.emplace( ptr, "???" );
|
|
|
|
m_pendingStrings++;
|
|
|
|
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQueryString, ptr );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::CheckThreadString( uint64_t id )
|
|
|
|
{
|
|
|
|
if( m_data.threadNames.find( id ) != m_data.threadNames.end() ) return;
|
|
|
|
|
|
|
|
m_data.threadNames.emplace( id, "???" );
|
|
|
|
m_pendingThreads++;
|
|
|
|
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQueryThreadString, id );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::AddSourceLocation( const QueueSourceLocation& srcloc )
|
|
|
|
{
|
|
|
|
assert( m_pendingSourceLocation > 0 );
|
|
|
|
m_pendingSourceLocation--;
|
|
|
|
|
|
|
|
const auto ptr = m_sourceLocationQueue.front();
|
|
|
|
m_sourceLocationQueue.erase( m_sourceLocationQueue.begin() );
|
|
|
|
|
|
|
|
auto it = m_data.sourceLocation.find( ptr );
|
|
|
|
assert( it != m_data.sourceLocation.end() );
|
|
|
|
CheckString( srcloc.name );
|
|
|
|
CheckString( srcloc.file );
|
|
|
|
CheckString( srcloc.function );
|
2019-05-10 18:20:08 +00:00
|
|
|
const uint32_t color = ( srcloc.r << 16 ) | ( srcloc.g << 8 ) | srcloc.b;
|
2018-02-13 13:57:47 +00:00
|
|
|
it->second = SourceLocation { srcloc.name == 0 ? StringRef() : StringRef( StringRef::Ptr, srcloc.name ), StringRef( StringRef::Ptr, srcloc.function ), StringRef( StringRef::Ptr, srcloc.file ), srcloc.line, color };
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz )
|
|
|
|
{
|
|
|
|
const auto start = data;
|
|
|
|
|
|
|
|
assert( m_pendingSourceLocationPayload.find( ptr ) == m_pendingSourceLocationPayload.end() );
|
|
|
|
|
|
|
|
uint32_t color, line;
|
|
|
|
memcpy( &color, data, 4 );
|
|
|
|
memcpy( &line, data + 4, 4 );
|
|
|
|
data += 8;
|
|
|
|
auto end = data;
|
|
|
|
|
|
|
|
while( *end ) end++;
|
|
|
|
const auto func = StoreString( data, end - data );
|
|
|
|
end++;
|
|
|
|
|
|
|
|
data = end;
|
|
|
|
while( *end ) end++;
|
|
|
|
const auto source = StoreString( data, end - data );
|
|
|
|
end++;
|
|
|
|
|
|
|
|
const auto nsz = sz - ( end - start );
|
|
|
|
|
|
|
|
color = ( ( color & 0x00FF0000 ) >> 16 ) |
|
|
|
|
( ( color & 0x0000FF00 ) ) |
|
|
|
|
( ( color & 0x000000FF ) << 16 );
|
|
|
|
|
|
|
|
SourceLocation srcloc { nsz == 0 ? StringRef() : StringRef( StringRef::Idx, StoreString( end, nsz ).idx ), StringRef( StringRef::Idx, func.idx ), StringRef( StringRef::Idx, source.idx ), line, color };
|
|
|
|
auto it = m_data.sourceLocationPayloadMap.find( &srcloc );
|
|
|
|
if( it == m_data.sourceLocationPayloadMap.end() )
|
|
|
|
{
|
|
|
|
auto slptr = m_slab.Alloc<SourceLocation>();
|
|
|
|
memcpy( slptr, &srcloc, sizeof( srcloc ) );
|
|
|
|
uint32_t idx = m_data.sourceLocationPayload.size();
|
|
|
|
m_data.sourceLocationPayloadMap.emplace( slptr, idx );
|
|
|
|
m_pendingSourceLocationPayload.emplace( ptr, -int32_t( idx + 1 ) );
|
|
|
|
m_data.sourceLocationPayload.push_back( slptr );
|
2018-03-18 11:55:54 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
2018-03-18 19:08:57 +00:00
|
|
|
m_data.sourceLocationZones.emplace( -int32_t( idx + 1 ), SourceLocationZones() );
|
2018-07-29 12:16:13 +00:00
|
|
|
#else
|
|
|
|
m_data.sourceLocationZonesCnt.emplace( -int32_t( idx + 1 ), 0 );
|
2018-03-18 11:55:54 +00:00
|
|
|
#endif
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pendingSourceLocationPayload.emplace( ptr, -int32_t( it->second + 1 ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::AddString( uint64_t ptr, char* str, size_t sz )
|
|
|
|
{
|
|
|
|
assert( m_pendingStrings > 0 );
|
|
|
|
m_pendingStrings--;
|
|
|
|
auto it = m_data.strings.find( ptr );
|
|
|
|
assert( it != m_data.strings.end() && strcmp( it->second, "???" ) == 0 );
|
|
|
|
const auto sl = StoreString( str, sz );
|
|
|
|
it->second = sl.ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::AddThreadString( uint64_t id, char* str, size_t sz )
|
|
|
|
{
|
|
|
|
assert( m_pendingThreads > 0 );
|
|
|
|
m_pendingThreads--;
|
|
|
|
auto it = m_data.threadNames.find( id );
|
|
|
|
assert( it != m_data.threadNames.end() && strcmp( it->second, "???" ) == 0 );
|
|
|
|
const auto sl = StoreString( str, sz );
|
|
|
|
it->second = sl.ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::AddCustomString( uint64_t ptr, char* str, size_t sz )
|
|
|
|
{
|
|
|
|
assert( m_pendingCustomStrings.find( ptr ) == m_pendingCustomStrings.end() );
|
|
|
|
m_pendingCustomStrings.emplace( ptr, StoreString( str, sz ) );
|
|
|
|
}
|
|
|
|
|
2019-06-06 19:39:54 +00:00
|
|
|
void Worker::AddFrameImageData( uint64_t ptr, char* data, size_t sz )
|
|
|
|
{
|
|
|
|
assert( m_pendingFrameImageData.find( ptr ) == m_pendingFrameImageData.end() );
|
|
|
|
auto image = m_slab.AllocBig( sz );
|
|
|
|
memcpy( image, data, sz );
|
|
|
|
m_pendingFrameImageData.emplace( ptr, image );
|
|
|
|
}
|
|
|
|
|
2019-03-03 15:39:13 +00:00
|
|
|
uint64_t Worker::GetCanonicalPointer( const CallstackFrameId& id ) const
|
|
|
|
{
|
|
|
|
assert( id.sel == 0 );
|
|
|
|
return ( id.idx & 0x7FFFFFFFFFFFFFFF ) | ( ( id.idx & 0x4000000000000000 ) << 1 );
|
|
|
|
}
|
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
void Worker::AddCallstackPayload( uint64_t ptr, char* _data, size_t _sz )
|
2018-06-19 19:15:36 +00:00
|
|
|
{
|
2019-03-05 18:30:17 +00:00
|
|
|
assert( m_pendingCallstackPtr == 0 );
|
2018-06-19 19:15:36 +00:00
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
const auto sz = _sz / sizeof( uint64_t );
|
|
|
|
const auto memsize = sizeof( VarArray<CallstackFrameId> ) + sz * sizeof( CallstackFrameId );
|
2018-06-19 19:15:36 +00:00
|
|
|
auto mem = (char*)m_slab.AllocRaw( memsize );
|
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
auto data = (CallstackFrameId*)mem;
|
|
|
|
auto dst = data;
|
|
|
|
auto src = (uint64_t*)_data;
|
|
|
|
for( size_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
*dst++ = PackPointer( *src++ );
|
|
|
|
}
|
2018-06-19 19:15:36 +00:00
|
|
|
|
2019-03-03 15:50:18 +00:00
|
|
|
auto arr = (VarArray<CallstackFrameId>*)( mem + sz * sizeof( CallstackFrameId ) );
|
|
|
|
new(arr) VarArray<CallstackFrameId>( sz, data );
|
2018-06-19 19:15:36 +00:00
|
|
|
|
2019-03-03 16:34:56 +00:00
|
|
|
uint32_t idx;
|
|
|
|
auto it = m_data.callstackMap.find( arr );
|
|
|
|
if( it == m_data.callstackMap.end() )
|
|
|
|
{
|
|
|
|
idx = m_data.callstackPayload.size();
|
|
|
|
m_data.callstackMap.emplace( arr, idx );
|
|
|
|
m_data.callstackPayload.push_back( arr );
|
|
|
|
|
|
|
|
for( auto& frame : *arr )
|
|
|
|
{
|
|
|
|
auto fit = m_data.callstackFrameMap.find( frame );
|
|
|
|
if( fit == m_data.callstackFrameMap.end() )
|
|
|
|
{
|
|
|
|
m_pendingCallstackFrames++;
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQueryCallstackFrame, GetCanonicalPointer( frame ) );
|
2019-03-03 16:34:56 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx = it->second;
|
|
|
|
m_slab.Unalloc( memsize );
|
|
|
|
}
|
|
|
|
|
2019-03-05 18:30:17 +00:00
|
|
|
m_pendingCallstackPtr = ptr;
|
|
|
|
m_pendingCallstackId = idx;
|
2019-03-03 16:34:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::AddCallstackAllocPayload( uint64_t ptr, char* data, size_t _sz )
|
|
|
|
{
|
2019-03-05 18:43:44 +00:00
|
|
|
assert( m_pendingCallstackPtr != 0 );
|
2019-03-03 16:34:56 +00:00
|
|
|
|
|
|
|
CallstackFrameId stack[64];
|
|
|
|
const auto sz = *(uint32_t*)data; data += 4;
|
|
|
|
assert( sz <= 64 );
|
|
|
|
for( uint32_t i=0; i<sz; i++ )
|
|
|
|
{
|
|
|
|
uint32_t sz;
|
|
|
|
CallstackFrame cf;
|
|
|
|
memcpy( &cf.line, data, 4 ); data += 4;
|
|
|
|
memcpy( &sz, data, 4 ); data += 4;
|
|
|
|
cf.name = StoreString( data, sz ).idx; data += sz;
|
|
|
|
memcpy( &sz, data, 4 ); data += 4;
|
|
|
|
cf.file = StoreString( data, sz ).idx; data += sz;
|
|
|
|
CallstackFrameData cfd = { &cf, 1 };
|
|
|
|
|
|
|
|
CallstackFrameId id;
|
|
|
|
auto it = m_data.revFrameMap.find( &cfd );
|
|
|
|
if( it == m_data.revFrameMap.end() )
|
|
|
|
{
|
|
|
|
auto frame = m_slab.Alloc<CallstackFrame>();
|
|
|
|
memcpy( frame, &cf, sizeof( CallstackFrame ) );
|
|
|
|
auto frameData = m_slab.Alloc<CallstackFrameData>();
|
|
|
|
frameData->data = frame;
|
|
|
|
frameData->size = 1;
|
|
|
|
id.idx = m_callstackAllocNextIdx++;
|
|
|
|
id.sel = 1;
|
|
|
|
m_data.callstackFrameMap.emplace( id, frameData );
|
|
|
|
m_data.revFrameMap.emplace( frameData, id );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
id = it->second;
|
|
|
|
}
|
|
|
|
stack[i] = id;
|
|
|
|
}
|
|
|
|
|
2019-03-05 18:43:44 +00:00
|
|
|
const auto nativeCs = m_data.callstackPayload[m_pendingCallstackId];
|
|
|
|
const auto nsz = nativeCs->size();
|
|
|
|
const auto tsz = sz + nsz;
|
|
|
|
|
|
|
|
const auto memsize = sizeof( VarArray<CallstackFrameId> ) + tsz * sizeof( CallstackFrameId );
|
2019-03-03 16:34:56 +00:00
|
|
|
auto mem = (char*)m_slab.AllocRaw( memsize );
|
|
|
|
memcpy( mem, stack, sizeof( CallstackFrameId ) * sz );
|
2019-03-05 18:43:44 +00:00
|
|
|
memcpy( mem + sizeof( CallstackFrameId ) * sz, nativeCs->data(), sizeof( CallstackFrameId ) * nsz );
|
2019-03-03 16:34:56 +00:00
|
|
|
|
2019-03-05 18:43:44 +00:00
|
|
|
auto arr = (VarArray<CallstackFrameId>*)( mem + tsz * sizeof( CallstackFrameId ) );
|
|
|
|
new(arr) VarArray<CallstackFrameId>( tsz, (CallstackFrameId*)mem );
|
2019-03-03 16:34:56 +00:00
|
|
|
|
2018-06-19 19:15:36 +00:00
|
|
|
uint32_t idx;
|
|
|
|
auto it = m_data.callstackMap.find( arr );
|
|
|
|
if( it == m_data.callstackMap.end() )
|
|
|
|
{
|
|
|
|
idx = m_data.callstackPayload.size();
|
|
|
|
m_data.callstackMap.emplace( arr, idx );
|
|
|
|
m_data.callstackPayload.push_back( arr );
|
2018-06-19 22:25:26 +00:00
|
|
|
|
|
|
|
for( auto& frame : *arr )
|
|
|
|
{
|
|
|
|
auto fit = m_data.callstackFrameMap.find( frame );
|
|
|
|
if( fit == m_data.callstackFrameMap.end() )
|
|
|
|
{
|
2018-06-20 21:42:00 +00:00
|
|
|
m_pendingCallstackFrames++;
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQueryCallstackFrame, GetCanonicalPointer( frame ) );
|
2018-06-19 22:25:26 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-19 19:15:36 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
idx = it->second;
|
|
|
|
m_slab.Unalloc( memsize );
|
|
|
|
}
|
|
|
|
|
2019-03-05 18:43:44 +00:00
|
|
|
m_pendingCallstackPtr = ptr;
|
|
|
|
m_pendingCallstackId = idx;
|
2018-06-19 19:15:36 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::InsertPlot( PlotData* plot, int64_t time, double val )
|
|
|
|
{
|
|
|
|
if( plot->data.empty() )
|
|
|
|
{
|
|
|
|
plot->min = val;
|
|
|
|
plot->max = val;
|
|
|
|
plot->data.push_back( { time, val } );
|
|
|
|
}
|
|
|
|
else if( plot->data.back().time < time )
|
|
|
|
{
|
|
|
|
if( plot->min > val ) plot->min = val;
|
|
|
|
else if( plot->max < val ) plot->max = val;
|
|
|
|
plot->data.push_back_non_empty( { time, val } );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if( plot->min > val ) plot->min = val;
|
|
|
|
else if( plot->max < val ) plot->max = val;
|
|
|
|
if( plot->postpone.empty() )
|
|
|
|
{
|
|
|
|
plot->postponeTime = std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count();
|
|
|
|
plot->postpone.push_back( { time, val } );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
plot->postpone.push_back_non_empty( { time, val } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::HandlePlotName( uint64_t name, char* str, size_t sz )
|
|
|
|
{
|
|
|
|
const auto sl = StoreString( str, sz );
|
2018-08-04 15:10:45 +00:00
|
|
|
m_data.plots.StringDiscovered( name, sl, m_data.strings, [this] ( PlotData* dst, PlotData* src ) {
|
2018-08-04 14:33:03 +00:00
|
|
|
for( auto& v : src->data )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-08-04 14:33:03 +00:00
|
|
|
InsertPlot( dst, v.time, v.val );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2018-08-04 14:33:03 +00:00
|
|
|
} );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 18:48:21 +00:00
|
|
|
void Worker::HandleFrameName( uint64_t name, char* str, size_t sz )
|
|
|
|
{
|
|
|
|
const auto sl = StoreString( str, sz );
|
2019-01-06 20:11:36 +00:00
|
|
|
m_data.frames.StringDiscovered( name, sl, m_data.strings, [] ( FrameData* dst, FrameData* src ) {
|
2018-08-04 18:48:21 +00:00
|
|
|
auto sz = dst->frames.size();
|
|
|
|
dst->frames.insert( dst->frames.end(), src->frames.begin(), src->frames.end() );
|
2018-08-05 00:09:59 +00:00
|
|
|
std::inplace_merge( dst->frames.begin(), dst->frames.begin() + sz, dst->frames.end(), [] ( const auto& lhs, const auto& rhs ) { return lhs.start < rhs.start; } );
|
2018-08-04 18:48:21 +00:00
|
|
|
} );
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::HandlePostponedPlots()
|
|
|
|
{
|
2018-08-04 14:33:03 +00:00
|
|
|
for( auto& plot : m_data.plots.Data() )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
auto& src = plot->postpone;
|
|
|
|
if( src.empty() ) continue;
|
|
|
|
if( std::chrono::duration_cast<std::chrono::milliseconds>( std::chrono::high_resolution_clock::now().time_since_epoch() ).count() - plot->postponeTime < 100 ) continue;
|
|
|
|
auto& dst = plot->data;
|
2018-05-12 20:41:18 +00:00
|
|
|
#ifdef MY_LIBCPP_SUCKS
|
|
|
|
pdqsort_branchless( src.begin(), src.end(), [] ( const auto& l, const auto& r ) { return l.time < r.time; } );
|
|
|
|
#else
|
2018-05-07 23:40:22 +00:00
|
|
|
std::sort( std::execution::par_unseq, src.begin(), src.end(), [] ( const auto& l, const auto& r ) { return l.time < r.time; } );
|
2018-05-12 20:41:18 +00:00
|
|
|
#endif
|
2018-02-13 13:57:47 +00:00
|
|
|
const auto ds = std::lower_bound( dst.begin(), dst.end(), src.front().time, [] ( const auto& l, const auto& r ) { return l.time < r; } );
|
|
|
|
const auto dsd = std::distance( dst.begin(), ds ) ;
|
|
|
|
const auto de = std::lower_bound( ds, dst.end(), src.back().time, [] ( const auto& l, const auto& r ) { return l.time < r; } );
|
|
|
|
const auto ded = std::distance( dst.begin(), de );
|
|
|
|
dst.insert( de, src.begin(), src.end() );
|
|
|
|
std::inplace_merge( dst.begin() + dsd, dst.begin() + ded, dst.begin() + ded + src.size(), [] ( const auto& l, const auto& r ) { return l.time < r.time; } );
|
|
|
|
src.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StringLocation Worker::StoreString( char* str, size_t sz )
|
|
|
|
{
|
|
|
|
StringLocation ret;
|
|
|
|
const char backup = str[sz];
|
|
|
|
str[sz] = '\0';
|
2019-02-12 19:23:14 +00:00
|
|
|
charutil::StringKey key = { str, sz };
|
|
|
|
auto sit = m_data.stringMap.find( key );
|
2018-02-13 13:57:47 +00:00
|
|
|
if( sit == m_data.stringMap.end() )
|
|
|
|
{
|
|
|
|
auto ptr = m_slab.Alloc<char>( sz+1 );
|
2018-03-19 14:41:28 +00:00
|
|
|
memcpy( ptr, str, sz );
|
|
|
|
ptr[sz] = '\0';
|
2018-02-13 13:57:47 +00:00
|
|
|
ret.ptr = ptr;
|
|
|
|
ret.idx = m_data.stringData.size();
|
2019-02-12 19:23:14 +00:00
|
|
|
m_data.stringMap.emplace( charutil::StringKey { ptr, sz }, m_data.stringData.size() );
|
2018-02-13 13:57:47 +00:00
|
|
|
m_data.stringData.push_back( ptr );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-02-12 19:23:14 +00:00
|
|
|
ret.ptr = sit->first.ptr;
|
2018-02-13 13:57:47 +00:00
|
|
|
ret.idx = sit->second;
|
|
|
|
}
|
|
|
|
str[sz] = backup;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2019-01-14 22:08:34 +00:00
|
|
|
bool Worker::Process( const QueueItem& ev )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
switch( ev.hdr.type )
|
|
|
|
{
|
|
|
|
case QueueType::ZoneBegin:
|
|
|
|
ProcessZoneBegin( ev.zoneBegin );
|
|
|
|
break;
|
2018-06-21 23:07:25 +00:00
|
|
|
case QueueType::ZoneBeginCallstack:
|
|
|
|
ProcessZoneBeginCallstack( ev.zoneBegin );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
case QueueType::ZoneBeginAllocSrcLoc:
|
|
|
|
ProcessZoneBeginAllocSrcLoc( ev.zoneBegin );
|
|
|
|
break;
|
2019-03-03 16:47:26 +00:00
|
|
|
case QueueType::ZoneBeginAllocSrcLocCallstack:
|
|
|
|
ProcessZoneBeginAllocSrcLocCallstack( ev.zoneBegin );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
case QueueType::ZoneEnd:
|
2019-01-15 17:55:21 +00:00
|
|
|
ProcessZoneEnd( ev.zoneEnd );
|
2018-02-13 13:57:47 +00:00
|
|
|
break;
|
2019-01-14 21:56:10 +00:00
|
|
|
case QueueType::ZoneValidation:
|
|
|
|
ProcessZoneValidation( ev.zoneValidation );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
case QueueType::FrameMarkMsg:
|
|
|
|
ProcessFrameMark( ev.frameMark );
|
|
|
|
break;
|
2018-08-05 00:09:59 +00:00
|
|
|
case QueueType::FrameMarkMsgStart:
|
|
|
|
ProcessFrameMarkStart( ev.frameMark );
|
|
|
|
break;
|
|
|
|
case QueueType::FrameMarkMsgEnd:
|
|
|
|
ProcessFrameMarkEnd( ev.frameMark );
|
|
|
|
break;
|
2019-06-06 19:39:54 +00:00
|
|
|
case QueueType::FrameImage:
|
|
|
|
ProcessFrameImage( ev.frameImage );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
case QueueType::SourceLocation:
|
|
|
|
AddSourceLocation( ev.srcloc );
|
2019-04-01 17:37:39 +00:00
|
|
|
m_serverQuerySpaceLeft++;
|
2018-02-13 13:57:47 +00:00
|
|
|
break;
|
|
|
|
case QueueType::ZoneText:
|
|
|
|
ProcessZoneText( ev.zoneText );
|
|
|
|
break;
|
2018-06-29 14:12:17 +00:00
|
|
|
case QueueType::ZoneName:
|
|
|
|
ProcessZoneName( ev.zoneText );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
case QueueType::LockAnnounce:
|
|
|
|
ProcessLockAnnounce( ev.lockAnnounce );
|
|
|
|
break;
|
2018-12-16 19:39:30 +00:00
|
|
|
case QueueType::LockTerminate:
|
|
|
|
ProcessLockTerminate( ev.lockTerminate );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
case QueueType::LockWait:
|
|
|
|
ProcessLockWait( ev.lockWait );
|
|
|
|
break;
|
|
|
|
case QueueType::LockObtain:
|
|
|
|
ProcessLockObtain( ev.lockObtain );
|
|
|
|
break;
|
|
|
|
case QueueType::LockRelease:
|
|
|
|
ProcessLockRelease( ev.lockRelease );
|
|
|
|
break;
|
|
|
|
case QueueType::LockSharedWait:
|
|
|
|
ProcessLockSharedWait( ev.lockWait );
|
|
|
|
break;
|
|
|
|
case QueueType::LockSharedObtain:
|
|
|
|
ProcessLockSharedObtain( ev.lockObtain );
|
|
|
|
break;
|
|
|
|
case QueueType::LockSharedRelease:
|
|
|
|
ProcessLockSharedRelease( ev.lockRelease );
|
|
|
|
break;
|
|
|
|
case QueueType::LockMark:
|
|
|
|
ProcessLockMark( ev.lockMark );
|
|
|
|
break;
|
|
|
|
case QueueType::PlotData:
|
|
|
|
ProcessPlotData( ev.plotData );
|
|
|
|
break;
|
|
|
|
case QueueType::Message:
|
|
|
|
ProcessMessage( ev.message );
|
|
|
|
break;
|
|
|
|
case QueueType::MessageLiteral:
|
|
|
|
ProcessMessageLiteral( ev.message );
|
|
|
|
break;
|
2019-05-10 18:17:44 +00:00
|
|
|
case QueueType::MessageColor:
|
|
|
|
ProcessMessageColor( ev.messageColor );
|
|
|
|
break;
|
|
|
|
case QueueType::MessageLiteralColor:
|
|
|
|
ProcessMessageLiteralColor( ev.messageColor );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
case QueueType::GpuNewContext:
|
|
|
|
ProcessGpuNewContext( ev.gpuNewContext );
|
|
|
|
break;
|
|
|
|
case QueueType::GpuZoneBegin:
|
|
|
|
ProcessGpuZoneBegin( ev.gpuZoneBegin );
|
|
|
|
break;
|
2018-06-21 23:56:32 +00:00
|
|
|
case QueueType::GpuZoneBeginCallstack:
|
|
|
|
ProcessGpuZoneBeginCallstack( ev.gpuZoneBegin );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
case QueueType::GpuZoneEnd:
|
|
|
|
ProcessGpuZoneEnd( ev.gpuZoneEnd );
|
|
|
|
break;
|
|
|
|
case QueueType::GpuTime:
|
|
|
|
ProcessGpuTime( ev.gpuTime );
|
|
|
|
break;
|
2018-03-31 19:56:05 +00:00
|
|
|
case QueueType::MemAlloc:
|
2018-04-01 00:03:34 +00:00
|
|
|
ProcessMemAlloc( ev.memAlloc );
|
2018-03-31 19:56:05 +00:00
|
|
|
break;
|
|
|
|
case QueueType::MemFree:
|
2018-04-01 00:03:34 +00:00
|
|
|
ProcessMemFree( ev.memFree );
|
2018-03-31 19:56:05 +00:00
|
|
|
break;
|
2018-06-19 16:52:45 +00:00
|
|
|
case QueueType::MemAllocCallstack:
|
|
|
|
ProcessMemAllocCallstack( ev.memAlloc );
|
|
|
|
break;
|
|
|
|
case QueueType::MemFreeCallstack:
|
|
|
|
ProcessMemFreeCallstack( ev.memFree );
|
|
|
|
break;
|
|
|
|
case QueueType::CallstackMemory:
|
|
|
|
ProcessCallstackMemory( ev.callstackMemory );
|
|
|
|
break;
|
2018-06-21 23:15:49 +00:00
|
|
|
case QueueType::Callstack:
|
|
|
|
ProcessCallstack( ev.callstack );
|
|
|
|
break;
|
2019-03-05 01:04:45 +00:00
|
|
|
case QueueType::CallstackAlloc:
|
|
|
|
ProcessCallstackAlloc( ev.callstackAlloc );
|
|
|
|
break;
|
2019-01-20 18:11:48 +00:00
|
|
|
case QueueType::CallstackFrameSize:
|
|
|
|
ProcessCallstackFrameSize( ev.callstackFrameSize );
|
2019-04-01 17:37:39 +00:00
|
|
|
m_serverQuerySpaceLeft++;
|
2019-01-20 18:11:48 +00:00
|
|
|
break;
|
2018-06-19 23:07:09 +00:00
|
|
|
case QueueType::CallstackFrame:
|
|
|
|
ProcessCallstackFrame( ev.callstackFrame );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
case QueueType::Terminate:
|
|
|
|
m_terminate = true;
|
|
|
|
break;
|
2018-07-10 19:33:22 +00:00
|
|
|
case QueueType::KeepAlive:
|
|
|
|
break;
|
2018-08-19 23:03:16 +00:00
|
|
|
case QueueType::Crash:
|
|
|
|
m_crashed = true;
|
|
|
|
break;
|
2018-08-20 00:07:31 +00:00
|
|
|
case QueueType::CrashReport:
|
|
|
|
ProcessCrashReport( ev.crashReport );
|
|
|
|
break;
|
2019-02-21 21:45:39 +00:00
|
|
|
case QueueType::SysTimeReport:
|
|
|
|
ProcessSysTime( ev.sysTime );
|
|
|
|
break;
|
2018-02-13 13:57:47 +00:00
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
2019-01-14 22:08:34 +00:00
|
|
|
|
2019-01-15 17:55:21 +00:00
|
|
|
return m_failure == Failure::None;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 23:07:25 +00:00
|
|
|
void Worker::ProcessZoneBeginImpl( ZoneEvent* zone, const QueueZoneBegin& ev )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
CheckSourceLocation( ev.srcloc );
|
|
|
|
|
|
|
|
zone->start = TscTime( ev.time );
|
|
|
|
zone->end = -1;
|
|
|
|
zone->srcloc = ShrinkSourceLocation( ev.srcloc );
|
|
|
|
assert( ev.cpu == 0xFFFFFFFF || ev.cpu <= std::numeric_limits<int8_t>::max() );
|
|
|
|
zone->cpu_start = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu;
|
2018-06-21 23:11:03 +00:00
|
|
|
zone->callstack = 0;
|
2018-07-22 14:05:50 +00:00
|
|
|
zone->child = -1;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
m_data.lastTime = std::max( m_data.lastTime, zone->start );
|
|
|
|
|
|
|
|
NewZone( zone, ev.thread );
|
|
|
|
}
|
|
|
|
|
2018-06-21 23:07:25 +00:00
|
|
|
void Worker::ProcessZoneBegin( const QueueZoneBegin& ev )
|
|
|
|
{
|
|
|
|
auto zone = m_slab.AllocInit<ZoneEvent>();
|
|
|
|
ProcessZoneBeginImpl( zone, ev );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessZoneBeginCallstack( const QueueZoneBegin& ev )
|
|
|
|
{
|
|
|
|
auto zone = m_slab.AllocInit<ZoneEvent>();
|
|
|
|
ProcessZoneBeginImpl( zone, ev );
|
|
|
|
|
|
|
|
auto& next = m_nextCallstack[ev.thread];
|
|
|
|
next.type = NextCallstackType::Zone;
|
|
|
|
next.zone = zone;
|
|
|
|
}
|
|
|
|
|
2019-03-03 16:47:26 +00:00
|
|
|
void Worker::ProcessZoneBeginAllocSrcLocImpl( ZoneEvent* zone, const QueueZoneBegin& ev )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
auto it = m_pendingSourceLocationPayload.find( ev.srcloc );
|
|
|
|
assert( it != m_pendingSourceLocationPayload.end() );
|
|
|
|
|
|
|
|
zone->start = TscTime( ev.time );
|
|
|
|
zone->end = -1;
|
|
|
|
zone->srcloc = it->second;
|
|
|
|
assert( ev.cpu == 0xFFFFFFFF || ev.cpu <= std::numeric_limits<int8_t>::max() );
|
|
|
|
zone->cpu_start = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu;
|
2018-06-21 23:11:03 +00:00
|
|
|
zone->callstack = 0;
|
2018-07-22 14:05:50 +00:00
|
|
|
zone->child = -1;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
m_data.lastTime = std::max( m_data.lastTime, zone->start );
|
|
|
|
|
|
|
|
NewZone( zone, ev.thread );
|
|
|
|
|
|
|
|
m_pendingSourceLocationPayload.erase( it );
|
|
|
|
}
|
|
|
|
|
2019-03-03 16:47:26 +00:00
|
|
|
void Worker::ProcessZoneBeginAllocSrcLoc( const QueueZoneBegin& ev )
|
|
|
|
{
|
|
|
|
auto zone = m_slab.AllocInit<ZoneEvent>();
|
|
|
|
ProcessZoneBeginAllocSrcLocImpl( zone, ev );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessZoneBeginAllocSrcLocCallstack( const QueueZoneBegin& ev )
|
|
|
|
{
|
|
|
|
auto zone = m_slab.AllocInit<ZoneEvent>();
|
|
|
|
ProcessZoneBeginAllocSrcLocImpl( zone, ev );
|
|
|
|
|
|
|
|
auto& next = m_nextCallstack[ev.thread];
|
|
|
|
next.type = NextCallstackType::Zone;
|
|
|
|
next.zone = zone;
|
|
|
|
}
|
|
|
|
|
2019-01-15 17:55:21 +00:00
|
|
|
void Worker::ProcessZoneEnd( const QueueZoneEnd& ev )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
auto tit = m_threadMap.find( ev.thread );
|
2019-01-15 23:45:48 +00:00
|
|
|
if( tit == m_threadMap.end() || tit->second->zoneIdStack.empty() )
|
|
|
|
{
|
|
|
|
ZoneEndFailure( ev.thread );
|
|
|
|
return;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
auto td = tit->second;
|
2019-01-14 22:08:34 +00:00
|
|
|
auto zoneId = td->zoneIdStack.back_and_pop();
|
2019-01-14 22:22:31 +00:00
|
|
|
if( zoneId != td->nextZoneId )
|
|
|
|
{
|
|
|
|
ZoneStackFailure( ev.thread, td->stack.back() );
|
2019-01-15 17:55:21 +00:00
|
|
|
return;
|
2019-01-14 22:22:31 +00:00
|
|
|
}
|
2019-01-14 22:08:34 +00:00
|
|
|
td->nextZoneId = 0;
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
auto& stack = td->stack;
|
|
|
|
assert( !stack.empty() );
|
|
|
|
auto zone = stack.back_and_pop();
|
|
|
|
assert( zone->end == -1 );
|
|
|
|
zone->end = TscTime( ev.time );
|
|
|
|
assert( ev.cpu == 0xFFFFFFFF || ev.cpu <= std::numeric_limits<int8_t>::max() );
|
|
|
|
zone->cpu_end = ev.cpu == 0xFFFFFFFF ? -1 : (int8_t)ev.cpu;
|
|
|
|
assert( zone->end >= zone->start );
|
|
|
|
|
|
|
|
m_data.lastTime = std::max( m_data.lastTime, zone->end );
|
2018-03-18 19:15:45 +00:00
|
|
|
|
2019-03-26 21:06:00 +00:00
|
|
|
if( zone->child >= 0 )
|
|
|
|
{
|
|
|
|
auto& childVec = m_data.zoneChildren[zone->child];
|
|
|
|
const auto sz = childVec.size();
|
|
|
|
if( sz <= 8 * 1024 )
|
|
|
|
{
|
|
|
|
Vector<ZoneEvent*> fitVec;
|
|
|
|
fitVec.reserve_exact( sz, m_slab );
|
|
|
|
memcpy( fitVec.data(), childVec.data(), sz * sizeof( ZoneEvent* ) );
|
2019-03-26 22:02:39 +00:00
|
|
|
fitVec.swap( childVec );
|
2019-03-26 21:06:00 +00:00
|
|
|
m_data.zoneVectorCache.push_back( std::move( fitVec ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-03-18 19:15:45 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
2018-06-05 22:39:22 +00:00
|
|
|
auto timeSpan = zone->end - zone->start;
|
2018-03-18 19:15:45 +00:00
|
|
|
if( timeSpan > 0 )
|
|
|
|
{
|
2018-03-18 19:24:35 +00:00
|
|
|
auto it = m_data.sourceLocationZones.find( zone->srcloc );
|
|
|
|
assert( it != m_data.sourceLocationZones.end() );
|
2019-01-29 20:59:52 +00:00
|
|
|
auto& slz = it->second;
|
|
|
|
slz.min = std::min( slz.min, timeSpan );
|
|
|
|
slz.max = std::max( slz.max, timeSpan );
|
|
|
|
slz.total += timeSpan;
|
2019-03-14 00:23:37 +00:00
|
|
|
slz.sumSq += double( timeSpan ) * timeSpan;
|
2018-07-22 14:05:50 +00:00
|
|
|
if( zone->child >= 0 )
|
2018-06-05 22:39:22 +00:00
|
|
|
{
|
2018-07-22 14:05:50 +00:00
|
|
|
for( auto& v : GetZoneChildren( zone->child ) )
|
|
|
|
{
|
|
|
|
const auto childSpan = std::max( int64_t( 0 ), v->end - v->start );
|
|
|
|
timeSpan -= childSpan;
|
|
|
|
}
|
2018-06-05 22:39:22 +00:00
|
|
|
}
|
2019-01-29 20:59:52 +00:00
|
|
|
slz.selfMin = std::min( slz.selfMin, timeSpan );
|
|
|
|
slz.selfMax = std::max( slz.selfMax, timeSpan );
|
|
|
|
slz.selfTotal += timeSpan;
|
2018-03-18 19:15:45 +00:00
|
|
|
}
|
|
|
|
#endif
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2019-01-14 22:22:31 +00:00
|
|
|
void Worker::ZoneStackFailure( uint64_t thread, const ZoneEvent* ev )
|
|
|
|
{
|
|
|
|
m_failure = Failure::ZoneStack;
|
|
|
|
m_failureData.thread = thread;
|
|
|
|
m_failureData.srcloc = ev->srcloc;
|
|
|
|
}
|
|
|
|
|
2019-01-15 23:45:48 +00:00
|
|
|
void Worker::ZoneEndFailure( uint64_t thread )
|
|
|
|
{
|
|
|
|
m_failure = Failure::ZoneEnd;
|
|
|
|
m_failureData.thread = thread;
|
|
|
|
m_failureData.srcloc = 0;
|
|
|
|
}
|
|
|
|
|
2019-01-16 00:17:01 +00:00
|
|
|
void Worker::ZoneTextFailure( uint64_t thread )
|
|
|
|
{
|
|
|
|
m_failure = Failure::ZoneText;
|
|
|
|
m_failureData.thread = thread;
|
|
|
|
m_failureData.srcloc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ZoneNameFailure( uint64_t thread )
|
|
|
|
{
|
|
|
|
m_failure = Failure::ZoneName;
|
|
|
|
m_failureData.thread = thread;
|
|
|
|
m_failureData.srcloc = 0;
|
|
|
|
}
|
|
|
|
|
2019-01-15 17:56:26 +00:00
|
|
|
void Worker::MemFreeFailure( uint64_t thread )
|
|
|
|
{
|
|
|
|
m_failure = Failure::MemFree;
|
|
|
|
m_failureData.thread = thread;
|
|
|
|
m_failureData.srcloc = 0;
|
|
|
|
}
|
|
|
|
|
2019-02-28 18:32:42 +00:00
|
|
|
void Worker::FrameEndFailure()
|
|
|
|
{
|
|
|
|
m_failure = Failure::ZoneEnd;
|
|
|
|
m_failureData.thread = 0;
|
|
|
|
m_failureData.srcloc = 0;
|
|
|
|
}
|
|
|
|
|
2019-06-09 11:44:53 +00:00
|
|
|
void Worker::FrameImageIndexFailure()
|
|
|
|
{
|
|
|
|
m_failure = Failure::FrameImageIndex;
|
|
|
|
m_failureData.thread = 0;
|
|
|
|
m_failureData.srcloc = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::FrameImageTwiceFailure()
|
|
|
|
{
|
|
|
|
m_failure = Failure::FrameImageTwice;
|
|
|
|
m_failureData.thread = 0;
|
|
|
|
m_failureData.srcloc = 0;
|
|
|
|
}
|
|
|
|
|
2019-01-14 21:56:10 +00:00
|
|
|
void Worker::ProcessZoneValidation( const QueueZoneValidation& ev )
|
|
|
|
{
|
|
|
|
auto td = NoticeThread( ev.thread );
|
|
|
|
td->nextZoneId = ev.id;
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::ProcessFrameMark( const QueueFrameMark& ev )
|
|
|
|
{
|
2018-08-04 17:47:09 +00:00
|
|
|
auto fd = m_data.frames.Retrieve( ev.name, [this] ( uint64_t name ) {
|
|
|
|
auto fd = m_slab.AllocInit<FrameData>();
|
|
|
|
fd->name = name;
|
2018-08-05 00:09:59 +00:00
|
|
|
fd->continuous = 1;
|
2018-08-04 17:47:09 +00:00
|
|
|
return fd;
|
|
|
|
}, [this] ( uint64_t name ) {
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQueryFrameName, name );
|
2018-08-04 17:47:09 +00:00
|
|
|
} );
|
|
|
|
|
2018-08-05 00:09:59 +00:00
|
|
|
assert( fd->continuous == 1 );
|
2018-02-13 13:57:47 +00:00
|
|
|
const auto time = TscTime( ev.time );
|
2019-03-21 20:24:07 +00:00
|
|
|
assert( fd->frames.empty() || fd->frames.back().start <= time );
|
2019-06-06 19:44:48 +00:00
|
|
|
fd->frames.push_back( FrameEvent{ time, -1, -1 } );
|
2018-08-05 00:09:59 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessFrameMarkStart( const QueueFrameMark& ev )
|
|
|
|
{
|
|
|
|
auto fd = m_data.frames.Retrieve( ev.name, [this] ( uint64_t name ) {
|
|
|
|
auto fd = m_slab.AllocInit<FrameData>();
|
|
|
|
fd->name = name;
|
|
|
|
fd->continuous = 0;
|
|
|
|
return fd;
|
|
|
|
}, [this] ( uint64_t name ) {
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQueryFrameName, name );
|
2018-08-05 00:09:59 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
assert( fd->continuous == 0 );
|
|
|
|
const auto time = TscTime( ev.time );
|
2019-03-21 20:24:07 +00:00
|
|
|
assert( fd->frames.empty() || ( fd->frames.back().end <= time && fd->frames.back().end != -1 ) );
|
2019-06-06 19:44:48 +00:00
|
|
|
fd->frames.push_back( FrameEvent{ time, -1, -1 } );
|
2018-08-05 00:09:59 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, time );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessFrameMarkEnd( const QueueFrameMark& ev )
|
|
|
|
{
|
|
|
|
auto fd = m_data.frames.Retrieve( ev.name, [this] ( uint64_t name ) {
|
|
|
|
auto fd = m_slab.AllocInit<FrameData>();
|
|
|
|
fd->name = name;
|
|
|
|
fd->continuous = 0;
|
|
|
|
return fd;
|
|
|
|
}, [this] ( uint64_t name ) {
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQueryFrameName, name );
|
2018-08-05 00:09:59 +00:00
|
|
|
} );
|
|
|
|
|
|
|
|
assert( fd->continuous == 0 );
|
|
|
|
const auto time = TscTime( ev.time );
|
|
|
|
if( fd->frames.empty() )
|
|
|
|
{
|
2019-02-28 18:32:42 +00:00
|
|
|
FrameEndFailure();
|
2018-08-05 00:09:59 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
assert( fd->frames.back().end == -1 );
|
|
|
|
fd->frames.back().end = time;
|
2018-02-13 13:57:47 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, time );
|
|
|
|
}
|
|
|
|
|
2019-06-06 19:39:54 +00:00
|
|
|
void Worker::ProcessFrameImage( const QueueFrameImage& ev )
|
|
|
|
{
|
|
|
|
auto it = m_pendingFrameImageData.find( ev.image );
|
|
|
|
assert( it != m_pendingFrameImageData.end() );
|
|
|
|
|
2019-06-09 11:44:53 +00:00
|
|
|
auto& frames = m_data.framesBase->frames;
|
|
|
|
const auto fidx = (int64_t)frames.size() - 1 - ev.offset;
|
2019-06-09 13:37:49 +00:00
|
|
|
if( m_onDemand && fidx <= 1 )
|
|
|
|
{
|
|
|
|
m_pendingFrameImageData.erase( it );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else if( fidx <= 0 )
|
2019-06-09 11:44:53 +00:00
|
|
|
{
|
|
|
|
FrameImageIndexFailure();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if( frames[fidx].frameImage >= 0 )
|
|
|
|
{
|
|
|
|
FrameImageTwiceFailure();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-06-06 19:39:54 +00:00
|
|
|
auto fi = m_slab.Alloc<FrameImage>();
|
2019-06-08 10:17:18 +00:00
|
|
|
fi->ptr = PackFrameImage( (const char*)it->second, ev.w, ev.h, fi->csz );
|
2019-06-06 19:39:54 +00:00
|
|
|
fi->w = ev.w;
|
|
|
|
fi->h = ev.h;
|
2019-06-11 22:55:02 +00:00
|
|
|
fi->frameRef = fidx;
|
2019-06-06 19:39:54 +00:00
|
|
|
|
|
|
|
const auto idx = m_data.frameImage.size();
|
2019-06-06 20:15:30 +00:00
|
|
|
m_data.frameImage.push_back( fi );
|
2019-06-07 18:13:08 +00:00
|
|
|
frames[fidx].frameImage = idx;
|
2019-06-06 19:39:54 +00:00
|
|
|
|
|
|
|
m_pendingFrameImageData.erase( it );
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::ProcessZoneText( const QueueZoneText& ev )
|
|
|
|
{
|
|
|
|
auto tit = m_threadMap.find( ev.thread );
|
2019-01-16 00:17:01 +00:00
|
|
|
if( tit == m_threadMap.end() || tit->second->stack.empty() || tit->second->nextZoneId != tit->second->zoneIdStack.back() )
|
|
|
|
{
|
|
|
|
ZoneTextFailure( ev.thread );
|
|
|
|
return;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
auto td = tit->second;
|
2019-01-16 00:17:01 +00:00
|
|
|
td->nextZoneId = 0;
|
2018-02-13 13:57:47 +00:00
|
|
|
auto& stack = td->stack;
|
|
|
|
auto zone = stack.back();
|
|
|
|
auto it = m_pendingCustomStrings.find( ev.text );
|
|
|
|
assert( it != m_pendingCustomStrings.end() );
|
|
|
|
zone->text = StringIdx( it->second.idx );
|
|
|
|
m_pendingCustomStrings.erase( it );
|
|
|
|
}
|
|
|
|
|
2018-06-29 14:12:17 +00:00
|
|
|
void Worker::ProcessZoneName( const QueueZoneText& ev )
|
|
|
|
{
|
|
|
|
auto tit = m_threadMap.find( ev.thread );
|
2019-01-16 00:17:01 +00:00
|
|
|
if( tit == m_threadMap.end() || tit->second->stack.empty() || tit->second->nextZoneId != tit->second->zoneIdStack.back() )
|
|
|
|
{
|
|
|
|
ZoneNameFailure( ev.thread );
|
|
|
|
return;
|
|
|
|
}
|
2018-06-29 14:12:17 +00:00
|
|
|
|
|
|
|
auto td = tit->second;
|
2019-01-16 00:17:01 +00:00
|
|
|
td->nextZoneId = 0;
|
2018-06-29 14:12:17 +00:00
|
|
|
auto& stack = td->stack;
|
|
|
|
auto zone = stack.back();
|
|
|
|
auto it = m_pendingCustomStrings.find( ev.text );
|
|
|
|
assert( it != m_pendingCustomStrings.end() );
|
|
|
|
zone->name = StringIdx( it->second.idx );
|
|
|
|
m_pendingCustomStrings.erase( it );
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::ProcessLockAnnounce( const QueueLockAnnounce& ev )
|
|
|
|
{
|
|
|
|
auto it = m_data.lockMap.find( ev.id );
|
|
|
|
if( it == m_data.lockMap.end() )
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
auto lm = m_slab.AllocInit<LockMap>();
|
|
|
|
lm->srcloc = ShrinkSourceLocation( ev.lckloc );
|
|
|
|
lm->type = ev.type;
|
|
|
|
lm->timeAnnounce = TscTime( ev.time );
|
|
|
|
lm->timeTerminate = 0;
|
|
|
|
lm->valid = true;
|
2019-05-12 14:17:17 +00:00
|
|
|
lm->isContended = false;
|
2019-03-16 01:09:50 +00:00
|
|
|
m_data.lockMap.emplace( ev.id, lm );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
it->second->srcloc = ShrinkSourceLocation( ev.lckloc );
|
|
|
|
assert( it->second->type == ev.type );
|
|
|
|
it->second->timeAnnounce = TscTime( ev.time );
|
|
|
|
it->second->valid = true;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
CheckSourceLocation( ev.lckloc );
|
|
|
|
}
|
|
|
|
|
2018-12-16 19:39:30 +00:00
|
|
|
void Worker::ProcessLockTerminate( const QueueLockTerminate& ev )
|
|
|
|
{
|
2018-12-16 19:46:02 +00:00
|
|
|
auto it = m_data.lockMap.find( ev.id );
|
|
|
|
if( it == m_data.lockMap.end() )
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
auto lm = m_slab.AllocInit<LockMap>();
|
|
|
|
lm->type = ev.type;
|
|
|
|
lm->timeAnnounce = 0;
|
|
|
|
lm->timeTerminate = TscTime( ev.time );
|
|
|
|
lm->valid = false;
|
2019-05-12 14:17:17 +00:00
|
|
|
lm->isContended = false;
|
2019-03-16 01:09:50 +00:00
|
|
|
m_data.lockMap.emplace( ev.id, lm );
|
2018-12-16 19:46:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
assert( it->second->type == ev.type );
|
|
|
|
it->second->timeTerminate = TscTime( ev.time );
|
2018-12-16 19:46:02 +00:00
|
|
|
}
|
2018-12-16 19:39:30 +00:00
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::ProcessLockWait( const QueueLockWait& ev )
|
|
|
|
{
|
|
|
|
auto it = m_data.lockMap.find( ev.id );
|
|
|
|
if( it == m_data.lockMap.end() )
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
auto lm = m_slab.AllocInit<LockMap>();
|
|
|
|
lm->timeAnnounce = 0;
|
|
|
|
lm->timeTerminate = 0;
|
|
|
|
lm->valid = false;
|
|
|
|
lm->type = ev.type;
|
2019-05-12 14:17:17 +00:00
|
|
|
lm->isContended = false;
|
2019-03-16 01:09:50 +00:00
|
|
|
it = m_data.lockMap.emplace( ev.id, lm ).first;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
auto lev = ev.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
|
|
|
|
lev->time = TscTime( ev.time );
|
|
|
|
lev->type = LockEvent::Type::Wait;
|
|
|
|
lev->srcloc = 0;
|
|
|
|
|
2019-03-16 01:09:50 +00:00
|
|
|
InsertLockEvent( *it->second, lev, ev.thread );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessLockObtain( const QueueLockObtain& ev )
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
auto it = m_data.lockMap.find( ev.id );
|
|
|
|
assert( it != m_data.lockMap.end() );
|
|
|
|
auto& lock = *it->second;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
auto lev = lock.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
|
|
|
|
lev->time = TscTime( ev.time );
|
|
|
|
lev->type = LockEvent::Type::Obtain;
|
|
|
|
lev->srcloc = 0;
|
|
|
|
|
|
|
|
InsertLockEvent( lock, lev, ev.thread );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessLockRelease( const QueueLockRelease& ev )
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
auto it = m_data.lockMap.find( ev.id );
|
|
|
|
assert( it != m_data.lockMap.end() );
|
|
|
|
auto& lock = *it->second;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
auto lev = lock.type == LockType::Lockable ? m_slab.Alloc<LockEvent>() : m_slab.Alloc<LockEventShared>();
|
|
|
|
lev->time = TscTime( ev.time );
|
|
|
|
lev->type = LockEvent::Type::Release;
|
|
|
|
lev->srcloc = 0;
|
|
|
|
|
|
|
|
InsertLockEvent( lock, lev, ev.thread );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessLockSharedWait( const QueueLockWait& ev )
|
|
|
|
{
|
|
|
|
auto it = m_data.lockMap.find( ev.id );
|
|
|
|
if( it == m_data.lockMap.end() )
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
auto lm = m_slab.AllocInit<LockMap>();
|
|
|
|
lm->valid = false;
|
|
|
|
lm->type = ev.type;
|
2019-05-12 14:17:17 +00:00
|
|
|
lm->isContended = false;
|
2019-03-16 01:09:50 +00:00
|
|
|
it = m_data.lockMap.emplace( ev.id, lm ).first;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
assert( ev.type == LockType::SharedLockable );
|
|
|
|
auto lev = m_slab.Alloc<LockEventShared>();
|
|
|
|
lev->time = TscTime( ev.time );
|
|
|
|
lev->type = LockEvent::Type::WaitShared;
|
|
|
|
lev->srcloc = 0;
|
|
|
|
|
2019-03-16 01:09:50 +00:00
|
|
|
InsertLockEvent( *it->second, lev, ev.thread );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessLockSharedObtain( const QueueLockObtain& ev )
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
auto it = m_data.lockMap.find( ev.id );
|
|
|
|
assert( it != m_data.lockMap.end() );
|
|
|
|
auto& lock = *it->second;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
assert( lock.type == LockType::SharedLockable );
|
|
|
|
auto lev = m_slab.Alloc<LockEventShared>();
|
|
|
|
lev->time = TscTime( ev.time );
|
|
|
|
lev->type = LockEvent::Type::ObtainShared;
|
|
|
|
lev->srcloc = 0;
|
|
|
|
|
|
|
|
InsertLockEvent( lock, lev, ev.thread );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessLockSharedRelease( const QueueLockRelease& ev )
|
|
|
|
{
|
2019-03-16 01:09:50 +00:00
|
|
|
auto it = m_data.lockMap.find( ev.id );
|
|
|
|
assert( it != m_data.lockMap.end() );
|
|
|
|
auto& lock = *it->second;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
assert( lock.type == LockType::SharedLockable );
|
|
|
|
auto lev = m_slab.Alloc<LockEventShared>();
|
|
|
|
lev->time = TscTime( ev.time );
|
|
|
|
lev->type = LockEvent::Type::ReleaseShared;
|
|
|
|
lev->srcloc = 0;
|
|
|
|
|
|
|
|
InsertLockEvent( lock, lev, ev.thread );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessLockMark( const QueueLockMark& ev )
|
|
|
|
{
|
|
|
|
CheckSourceLocation( ev.srcloc );
|
|
|
|
auto lit = m_data.lockMap.find( ev.id );
|
|
|
|
assert( lit != m_data.lockMap.end() );
|
2019-03-16 01:09:50 +00:00
|
|
|
auto& lockmap = *lit->second;
|
2018-02-13 13:57:47 +00:00
|
|
|
auto tid = lockmap.threadMap.find( ev.thread );
|
|
|
|
assert( tid != lockmap.threadMap.end() );
|
|
|
|
const auto thread = tid->second;
|
|
|
|
auto it = lockmap.timeline.end();
|
|
|
|
for(;;)
|
|
|
|
{
|
|
|
|
--it;
|
2019-03-16 13:18:43 +00:00
|
|
|
if( it->ptr->thread == thread )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2019-03-16 13:18:43 +00:00
|
|
|
switch( it->ptr->type )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
case LockEvent::Type::Obtain:
|
|
|
|
case LockEvent::Type::ObtainShared:
|
|
|
|
case LockEvent::Type::Wait:
|
|
|
|
case LockEvent::Type::WaitShared:
|
2019-03-16 13:18:43 +00:00
|
|
|
it->ptr->srcloc = ShrinkSourceLocation( ev.srcloc );
|
2018-02-13 13:57:47 +00:00
|
|
|
return;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessPlotData( const QueuePlotData& ev )
|
|
|
|
{
|
2018-08-04 14:33:03 +00:00
|
|
|
PlotData* plot = m_data.plots.Retrieve( ev.name, [this] ( uint64_t name ) {
|
|
|
|
auto plot = m_slab.AllocInit<PlotData>();
|
|
|
|
plot->name = name;
|
|
|
|
plot->type = PlotType::User;
|
|
|
|
return plot;
|
|
|
|
}, [this]( uint64_t name ) {
|
2019-04-01 16:52:32 +00:00
|
|
|
Query( ServerQueryPlotName, name );
|
2018-08-04 14:33:03 +00:00
|
|
|
} );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
const auto time = TscTime( ev.time );
|
|
|
|
m_data.lastTime = std::max( m_data.lastTime, time );
|
|
|
|
switch( ev.type )
|
|
|
|
{
|
|
|
|
case PlotDataType::Double:
|
|
|
|
InsertPlot( plot, time, ev.data.d );
|
|
|
|
break;
|
|
|
|
case PlotDataType::Float:
|
|
|
|
InsertPlot( plot, time, (double)ev.data.f );
|
|
|
|
break;
|
|
|
|
case PlotDataType::Int:
|
|
|
|
InsertPlot( plot, time, (double)ev.data.i );
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessMessage( const QueueMessage& ev )
|
|
|
|
{
|
|
|
|
auto it = m_pendingCustomStrings.find( ev.text );
|
|
|
|
assert( it != m_pendingCustomStrings.end() );
|
|
|
|
auto msg = m_slab.Alloc<MessageData>();
|
|
|
|
msg->time = TscTime( ev.time );
|
|
|
|
msg->ref = StringRef( StringRef::Type::Idx, it->second.idx );
|
2018-05-25 19:10:22 +00:00
|
|
|
msg->thread = ev.thread;
|
2019-05-10 18:21:35 +00:00
|
|
|
msg->color = 0xFFFFFFFF;
|
2018-02-13 13:57:47 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, msg->time );
|
|
|
|
InsertMessageData( msg, ev.thread );
|
|
|
|
m_pendingCustomStrings.erase( it );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessMessageLiteral( const QueueMessage& ev )
|
|
|
|
{
|
|
|
|
CheckString( ev.text );
|
|
|
|
auto msg = m_slab.Alloc<MessageData>();
|
|
|
|
msg->time = TscTime( ev.time );
|
|
|
|
msg->ref = StringRef( StringRef::Type::Ptr, ev.text );
|
2018-05-25 19:10:22 +00:00
|
|
|
msg->thread = ev.thread;
|
2019-05-10 18:21:35 +00:00
|
|
|
msg->color = 0xFFFFFFFF;
|
2018-02-13 13:57:47 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, msg->time );
|
|
|
|
InsertMessageData( msg, ev.thread );
|
|
|
|
}
|
|
|
|
|
2019-05-10 18:17:44 +00:00
|
|
|
void Worker::ProcessMessageColor( const QueueMessageColor& ev )
|
|
|
|
{
|
|
|
|
auto it = m_pendingCustomStrings.find( ev.text );
|
|
|
|
assert( it != m_pendingCustomStrings.end() );
|
|
|
|
auto msg = m_slab.Alloc<MessageData>();
|
|
|
|
msg->time = TscTime( ev.time );
|
|
|
|
msg->ref = StringRef( StringRef::Type::Idx, it->second.idx );
|
|
|
|
msg->thread = ev.thread;
|
2019-05-10 18:21:35 +00:00
|
|
|
msg->color = 0xFF000000 | ( ev.r << 16 ) | ( ev.g << 8 ) | ev.b;
|
2019-05-10 18:17:44 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, msg->time );
|
|
|
|
InsertMessageData( msg, ev.thread );
|
|
|
|
m_pendingCustomStrings.erase( it );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessMessageLiteralColor( const QueueMessageColor& ev )
|
|
|
|
{
|
|
|
|
CheckString( ev.text );
|
|
|
|
auto msg = m_slab.Alloc<MessageData>();
|
|
|
|
msg->time = TscTime( ev.time );
|
|
|
|
msg->ref = StringRef( StringRef::Type::Ptr, ev.text );
|
|
|
|
msg->thread = ev.thread;
|
2019-05-10 18:21:35 +00:00
|
|
|
msg->color = 0xFF000000 | ( ev.r << 16 ) | ( ev.g << 8 ) | ev.b;
|
2019-05-10 18:17:44 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, msg->time );
|
|
|
|
InsertMessageData( msg, ev.thread );
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::ProcessGpuNewContext( const QueueGpuNewContext& ev )
|
|
|
|
{
|
2018-06-22 13:14:44 +00:00
|
|
|
assert( !m_gpuCtxMap[ev.context] );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-06-17 16:49:56 +00:00
|
|
|
int64_t gpuTime;
|
|
|
|
if( ev.period == 1.f )
|
|
|
|
{
|
|
|
|
gpuTime = ev.gpuTime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gpuTime = int64_t( double( ev.period ) * ev.gpuTime ); // precision loss
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
auto gpu = m_slab.AllocInit<GpuCtxData>();
|
2018-06-22 14:37:54 +00:00
|
|
|
memset( gpu->query, 0, sizeof( gpu->query ) );
|
2018-06-17 16:49:56 +00:00
|
|
|
gpu->timeDiff = TscTime( ev.cpuTime ) - gpuTime;
|
2018-02-13 13:57:47 +00:00
|
|
|
gpu->thread = ev.thread;
|
|
|
|
gpu->accuracyBits = ev.accuracyBits;
|
2018-06-17 16:27:16 +00:00
|
|
|
gpu->period = ev.period;
|
2018-02-13 13:57:47 +00:00
|
|
|
gpu->count = 0;
|
|
|
|
m_data.gpuData.push_back( gpu );
|
2018-06-22 13:14:44 +00:00
|
|
|
m_gpuCtxMap[ev.context] = gpu;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 23:56:32 +00:00
|
|
|
void Worker::ProcessGpuZoneBeginImpl( GpuEvent* zone, const QueueGpuZoneBegin& ev )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-06-22 13:14:44 +00:00
|
|
|
auto ctx = m_gpuCtxMap[ev.context];
|
|
|
|
assert( ctx );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
CheckSourceLocation( ev.srcloc );
|
|
|
|
|
|
|
|
zone->cpuStart = TscTime( ev.cpuTime );
|
|
|
|
zone->cpuEnd = -1;
|
|
|
|
zone->gpuStart = std::numeric_limits<int64_t>::max();
|
|
|
|
zone->gpuEnd = -1;
|
|
|
|
zone->srcloc = ShrinkSourceLocation( ev.srcloc );
|
2018-06-21 23:56:32 +00:00
|
|
|
zone->callstack = 0;
|
2018-07-22 18:14:55 +00:00
|
|
|
zone->child = -1;
|
2018-06-22 00:12:42 +00:00
|
|
|
|
|
|
|
if( ctx->thread == 0 )
|
|
|
|
{
|
|
|
|
// Vulkan context is not bound to any single thread.
|
|
|
|
zone->thread = CompressThread( ev.thread );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// OpenGL doesn't need per-zone thread id. It still can be sent,
|
|
|
|
// because it may be needed for callstack collection purposes.
|
|
|
|
zone->thread = 0;
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
m_data.lastTime = std::max( m_data.lastTime, zone->cpuStart );
|
|
|
|
|
|
|
|
auto timeline = &ctx->timeline;
|
|
|
|
if( !ctx->stack.empty() )
|
|
|
|
{
|
2018-07-22 17:47:01 +00:00
|
|
|
auto back = ctx->stack.back();
|
|
|
|
if( back->child < 0 )
|
|
|
|
{
|
2019-03-26 20:41:44 +00:00
|
|
|
back->child = int32_t( m_data.gpuChildren.size() );
|
|
|
|
m_data.gpuChildren.push_back( Vector<GpuEvent*>() );
|
2018-07-22 17:47:01 +00:00
|
|
|
}
|
2019-03-26 20:41:44 +00:00
|
|
|
timeline = &m_data.gpuChildren[back->child];
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
timeline->push_back( zone );
|
|
|
|
|
|
|
|
ctx->stack.push_back( zone );
|
2018-06-22 14:37:54 +00:00
|
|
|
|
|
|
|
assert( !ctx->query[ev.queryId] );
|
|
|
|
ctx->query[ev.queryId] = zone;
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 23:56:32 +00:00
|
|
|
void Worker::ProcessGpuZoneBegin( const QueueGpuZoneBegin& ev )
|
|
|
|
{
|
2019-02-15 00:31:58 +00:00
|
|
|
auto zone = m_slab.Alloc<GpuEvent>();
|
2018-06-21 23:56:32 +00:00
|
|
|
ProcessGpuZoneBeginImpl( zone, ev );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessGpuZoneBeginCallstack( const QueueGpuZoneBegin& ev )
|
|
|
|
{
|
2019-02-15 00:31:58 +00:00
|
|
|
auto zone = m_slab.Alloc<GpuEvent>();
|
2018-06-21 23:56:32 +00:00
|
|
|
ProcessGpuZoneBeginImpl( zone, ev );
|
|
|
|
|
|
|
|
auto& next = m_nextCallstack[ev.thread];
|
|
|
|
next.type = NextCallstackType::Gpu;
|
|
|
|
next.gpu = zone;
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::ProcessGpuZoneEnd( const QueueGpuZoneEnd& ev )
|
|
|
|
{
|
2018-06-22 13:14:44 +00:00
|
|
|
auto ctx = m_gpuCtxMap[ev.context];
|
|
|
|
assert( ctx );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
assert( !ctx->stack.empty() );
|
|
|
|
auto zone = ctx->stack.back_and_pop();
|
2018-06-22 14:37:54 +00:00
|
|
|
|
|
|
|
assert( !ctx->query[ev.queryId] );
|
|
|
|
ctx->query[ev.queryId] = zone;
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
zone->cpuEnd = TscTime( ev.cpuTime );
|
|
|
|
m_data.lastTime = std::max( m_data.lastTime, zone->cpuEnd );
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessGpuTime( const QueueGpuTime& ev )
|
|
|
|
{
|
2018-06-22 13:14:44 +00:00
|
|
|
auto ctx = m_gpuCtxMap[ev.context];
|
|
|
|
assert( ctx );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-06-17 16:49:56 +00:00
|
|
|
int64_t gpuTime;
|
|
|
|
if( ctx->period == 1.f )
|
|
|
|
{
|
|
|
|
gpuTime = ev.gpuTime;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gpuTime = int64_t( double( ctx->period ) * ev.gpuTime ); // precision loss
|
|
|
|
}
|
|
|
|
|
2018-06-22 14:37:54 +00:00
|
|
|
auto zone = ctx->query[ev.queryId];
|
|
|
|
assert( zone );
|
|
|
|
ctx->query[ev.queryId] = nullptr;
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
if( zone->gpuStart == std::numeric_limits<int64_t>::max() )
|
|
|
|
{
|
2018-06-17 16:49:56 +00:00
|
|
|
zone->gpuStart = ctx->timeDiff + gpuTime;
|
2018-02-13 13:57:47 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, zone->gpuStart );
|
|
|
|
ctx->count++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-06-17 16:49:56 +00:00
|
|
|
zone->gpuEnd = ctx->timeDiff + gpuTime;
|
2018-02-13 13:57:47 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, zone->gpuEnd );
|
2018-06-22 14:37:54 +00:00
|
|
|
|
|
|
|
if( zone->gpuEnd < zone->gpuStart )
|
|
|
|
{
|
|
|
|
std::swap( zone->gpuEnd, zone->gpuStart );
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-01 00:03:34 +00:00
|
|
|
void Worker::ProcessMemAlloc( const QueueMemAlloc& ev )
|
|
|
|
{
|
|
|
|
const auto time = TscTime( ev.time );
|
2019-02-24 17:10:39 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, time );
|
2018-08-27 23:48:19 +00:00
|
|
|
NoticeThread( ev.thread );
|
2018-04-01 00:03:34 +00:00
|
|
|
|
2018-04-03 12:17:51 +00:00
|
|
|
assert( m_data.memory.active.find( ev.ptr ) == m_data.memory.active.end() );
|
|
|
|
assert( m_data.memory.data.empty() || m_data.memory.data.back().timeAlloc <= time );
|
2018-04-01 00:03:34 +00:00
|
|
|
|
2018-04-03 12:17:51 +00:00
|
|
|
m_data.memory.active.emplace( ev.ptr, m_data.memory.data.size() );
|
2018-04-01 00:03:34 +00:00
|
|
|
|
2018-04-10 14:06:01 +00:00
|
|
|
const auto ptr = ev.ptr;
|
|
|
|
uint32_t lo;
|
|
|
|
uint16_t hi;
|
|
|
|
memcpy( &lo, ev.size, 4 );
|
|
|
|
memcpy( &hi, ev.size+4, 2 );
|
|
|
|
const uint64_t size = lo | ( uint64_t( hi ) << 32 );
|
|
|
|
|
2018-04-03 12:17:51 +00:00
|
|
|
auto& mem = m_data.memory.data.push_next();
|
2018-04-10 14:06:01 +00:00
|
|
|
mem.ptr = ptr;
|
|
|
|
mem.size = size;
|
2018-04-03 12:17:51 +00:00
|
|
|
mem.timeAlloc = time;
|
|
|
|
mem.threadAlloc = CompressThread( ev.thread );
|
|
|
|
mem.timeFree = -1;
|
|
|
|
mem.threadFree = 0;
|
2018-06-19 20:08:47 +00:00
|
|
|
mem.csAlloc = 0;
|
|
|
|
mem.csFree = 0;
|
2018-04-01 00:03:34 +00:00
|
|
|
|
2018-04-10 14:06:01 +00:00
|
|
|
const auto low = m_data.memory.low;
|
|
|
|
const auto high = m_data.memory.high;
|
|
|
|
const auto ptrend = ptr + size;
|
|
|
|
|
|
|
|
m_data.memory.low = std::min( low, ptr );
|
|
|
|
m_data.memory.high = std::max( high, ptrend );
|
|
|
|
m_data.memory.usage += size;
|
2018-04-28 13:49:12 +00:00
|
|
|
|
|
|
|
MemAllocChanged( time );
|
2018-04-01 00:03:34 +00:00
|
|
|
}
|
|
|
|
|
2018-07-11 23:35:32 +00:00
|
|
|
bool Worker::ProcessMemFree( const QueueMemFree& ev )
|
2018-04-01 00:03:34 +00:00
|
|
|
{
|
2018-12-20 16:03:09 +00:00
|
|
|
if( ev.ptr == 0 ) return false;
|
|
|
|
|
2018-04-01 00:03:34 +00:00
|
|
|
auto it = m_data.memory.active.find( ev.ptr );
|
2018-07-11 23:35:32 +00:00
|
|
|
if( it == m_data.memory.active.end() )
|
|
|
|
{
|
2019-01-15 17:56:26 +00:00
|
|
|
if( !m_onDemand )
|
|
|
|
{
|
|
|
|
MemFreeFailure( ev.thread );
|
|
|
|
}
|
2018-07-11 23:35:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-08-27 23:48:19 +00:00
|
|
|
const auto time = TscTime( ev.time );
|
2019-02-24 17:10:39 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, time );
|
2018-08-27 23:48:19 +00:00
|
|
|
NoticeThread( ev.thread );
|
|
|
|
|
2018-05-02 15:59:50 +00:00
|
|
|
m_data.memory.frees.push_back( it->second );
|
2018-04-03 12:17:51 +00:00
|
|
|
auto& mem = m_data.memory.data[it->second];
|
2018-04-28 13:49:12 +00:00
|
|
|
mem.timeFree = time;
|
2018-04-03 12:17:51 +00:00
|
|
|
mem.threadFree = CompressThread( ev.thread );
|
|
|
|
m_data.memory.usage -= mem.size;
|
2018-04-01 18:13:01 +00:00
|
|
|
m_data.memory.active.erase( it );
|
2018-04-28 13:49:12 +00:00
|
|
|
|
|
|
|
MemAllocChanged( time );
|
2018-07-11 23:35:32 +00:00
|
|
|
return true;
|
2018-04-28 13:49:12 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 16:52:45 +00:00
|
|
|
void Worker::ProcessMemAllocCallstack( const QueueMemAlloc& ev )
|
|
|
|
{
|
|
|
|
m_lastMemActionCallstack = m_data.memory.data.size();
|
|
|
|
ProcessMemAlloc( ev );
|
2018-06-19 20:08:47 +00:00
|
|
|
m_lastMemActionWasAlloc = true;
|
2018-06-19 16:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessMemFreeCallstack( const QueueMemFree& ev )
|
|
|
|
{
|
2018-07-11 23:35:32 +00:00
|
|
|
if( ProcessMemFree( ev ) )
|
|
|
|
{
|
|
|
|
m_lastMemActionCallstack = m_data.memory.frees.back();
|
|
|
|
m_lastMemActionWasAlloc = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_lastMemActionCallstack = std::numeric_limits<uint64_t>::max();
|
|
|
|
}
|
2018-06-19 16:52:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessCallstackMemory( const QueueCallstackMemory& ev )
|
|
|
|
{
|
2019-03-05 18:30:17 +00:00
|
|
|
assert( m_pendingCallstackPtr == ev.ptr );
|
|
|
|
m_pendingCallstackPtr = 0;
|
2018-06-19 19:34:36 +00:00
|
|
|
|
2018-07-11 23:35:32 +00:00
|
|
|
if( m_lastMemActionCallstack != std::numeric_limits<uint64_t>::max() )
|
2018-06-19 20:08:47 +00:00
|
|
|
{
|
2018-07-11 23:35:32 +00:00
|
|
|
auto& mem = m_data.memory.data[m_lastMemActionCallstack];
|
|
|
|
if( m_lastMemActionWasAlloc )
|
|
|
|
{
|
2019-03-05 18:30:17 +00:00
|
|
|
mem.csAlloc = m_pendingCallstackId;
|
2018-07-11 23:35:32 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-05 18:30:17 +00:00
|
|
|
mem.csFree = m_pendingCallstackId;
|
2018-07-11 23:35:32 +00:00
|
|
|
}
|
2018-06-19 20:08:47 +00:00
|
|
|
}
|
2018-06-19 16:52:45 +00:00
|
|
|
}
|
|
|
|
|
2018-06-21 23:15:49 +00:00
|
|
|
void Worker::ProcessCallstack( const QueueCallstack& ev )
|
|
|
|
{
|
2019-03-05 18:30:17 +00:00
|
|
|
assert( m_pendingCallstackPtr == ev.ptr );
|
|
|
|
m_pendingCallstackPtr = 0;
|
2018-06-21 23:15:49 +00:00
|
|
|
|
|
|
|
auto nit = m_nextCallstack.find( ev.thread );
|
|
|
|
assert( nit != m_nextCallstack.end() );
|
|
|
|
auto& next = nit->second;
|
|
|
|
|
|
|
|
switch( next.type )
|
|
|
|
{
|
|
|
|
case NextCallstackType::Zone:
|
2019-03-05 18:30:17 +00:00
|
|
|
next.zone->callstack = m_pendingCallstackId;
|
2018-06-21 23:15:49 +00:00
|
|
|
break;
|
2018-06-21 23:56:32 +00:00
|
|
|
case NextCallstackType::Gpu:
|
2019-03-05 18:30:17 +00:00
|
|
|
next.gpu->callstack = m_pendingCallstackId;
|
2018-06-21 23:56:32 +00:00
|
|
|
break;
|
2018-08-20 00:07:31 +00:00
|
|
|
case NextCallstackType::Crash:
|
2019-03-26 20:41:44 +00:00
|
|
|
m_data.crashEvent.callstack = m_pendingCallstackId;
|
2018-08-20 00:07:31 +00:00
|
|
|
break;
|
2018-06-21 23:15:49 +00:00
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-05 01:04:45 +00:00
|
|
|
void Worker::ProcessCallstackAlloc( const QueueCallstackAlloc& ev )
|
|
|
|
{
|
2019-03-05 18:43:44 +00:00
|
|
|
assert( m_pendingCallstackPtr == ev.ptr );
|
2019-03-05 18:30:17 +00:00
|
|
|
m_pendingCallstackPtr = 0;
|
2019-03-05 01:04:45 +00:00
|
|
|
|
|
|
|
auto nit = m_nextCallstack.find( ev.thread );
|
|
|
|
assert( nit != m_nextCallstack.end() );
|
|
|
|
auto& next = nit->second;
|
|
|
|
|
|
|
|
switch( next.type )
|
|
|
|
{
|
|
|
|
case NextCallstackType::Zone:
|
2019-03-05 18:30:17 +00:00
|
|
|
next.zone->callstack = m_pendingCallstackId;
|
2019-03-05 01:04:45 +00:00
|
|
|
break;
|
|
|
|
case NextCallstackType::Gpu:
|
2019-03-05 18:30:17 +00:00
|
|
|
next.gpu->callstack = m_pendingCallstackId;
|
2019-03-05 01:04:45 +00:00
|
|
|
break;
|
|
|
|
case NextCallstackType::Crash:
|
2019-03-26 20:41:44 +00:00
|
|
|
m_data.crashEvent.callstack = m_pendingCallstackId;
|
2019-03-05 01:04:45 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
assert( false );
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-20 18:11:48 +00:00
|
|
|
void Worker::ProcessCallstackFrameSize( const QueueCallstackFrameSize& ev )
|
2018-06-19 23:07:09 +00:00
|
|
|
{
|
2019-01-20 18:11:48 +00:00
|
|
|
assert( !m_callstackFrameStaging );
|
|
|
|
assert( m_pendingCallstackSubframes == 0 );
|
2018-06-20 21:42:00 +00:00
|
|
|
assert( m_pendingCallstackFrames > 0 );
|
|
|
|
m_pendingCallstackFrames--;
|
2019-01-20 18:11:48 +00:00
|
|
|
m_pendingCallstackSubframes = ev.size;
|
2018-06-20 12:57:48 +00:00
|
|
|
|
2019-01-20 18:11:48 +00:00
|
|
|
// Frames may be duplicated due to recursion
|
2019-03-03 15:50:18 +00:00
|
|
|
auto fmit = m_data.callstackFrameMap.find( PackPointer( ev.ptr ) );
|
2019-01-20 18:11:48 +00:00
|
|
|
if( fmit == m_data.callstackFrameMap.end() )
|
|
|
|
{
|
|
|
|
m_callstackFrameStaging = m_slab.Alloc<CallstackFrameData>();
|
|
|
|
m_callstackFrameStaging->size = ev.size;
|
|
|
|
m_callstackFrameStaging->data = m_slab.Alloc<CallstackFrame>( ev.size );
|
|
|
|
|
|
|
|
m_callstackFrameStagingPtr = ev.ptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::ProcessCallstackFrame( const QueueCallstackFrame& ev )
|
|
|
|
{
|
|
|
|
assert( m_pendingCallstackSubframes > 0 );
|
|
|
|
|
2018-06-19 23:26:05 +00:00
|
|
|
auto nit = m_pendingCustomStrings.find( ev.name );
|
|
|
|
assert( nit != m_pendingCustomStrings.end() );
|
|
|
|
auto fit = m_pendingCustomStrings.find( ev.file );
|
|
|
|
assert( fit != m_pendingCustomStrings.end() );
|
2018-06-19 23:07:09 +00:00
|
|
|
|
2019-01-20 18:11:48 +00:00
|
|
|
if( m_callstackFrameStaging )
|
2018-06-19 23:07:09 +00:00
|
|
|
{
|
2019-01-20 18:11:48 +00:00
|
|
|
const auto idx = m_callstackFrameStaging->size - m_pendingCallstackSubframes;
|
2018-06-19 23:07:09 +00:00
|
|
|
|
2019-01-20 18:11:48 +00:00
|
|
|
m_callstackFrameStaging->data[idx].name = StringIdx( nit->second.idx );
|
|
|
|
m_callstackFrameStaging->data[idx].file = StringIdx( fit->second.idx );
|
|
|
|
m_callstackFrameStaging->data[idx].line = ev.line;
|
2018-06-19 23:07:09 +00:00
|
|
|
|
2019-01-20 18:11:48 +00:00
|
|
|
if( --m_pendingCallstackSubframes == 0 )
|
|
|
|
{
|
2019-03-03 15:50:18 +00:00
|
|
|
assert( m_data.callstackFrameMap.find( PackPointer( m_callstackFrameStagingPtr ) ) == m_data.callstackFrameMap.end() );
|
|
|
|
m_data.callstackFrameMap.emplace( PackPointer( m_callstackFrameStagingPtr ), m_callstackFrameStaging );
|
2019-01-20 18:11:48 +00:00
|
|
|
m_callstackFrameStaging = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_pendingCallstackSubframes--;
|
2018-06-19 23:07:09 +00:00
|
|
|
}
|
|
|
|
|
2018-06-19 23:26:05 +00:00
|
|
|
m_pendingCustomStrings.erase( nit );
|
|
|
|
m_pendingCustomStrings.erase( m_pendingCustomStrings.find( ev.file ) );
|
2018-06-19 23:07:09 +00:00
|
|
|
}
|
|
|
|
|
2018-08-20 00:07:31 +00:00
|
|
|
void Worker::ProcessCrashReport( const QueueCrashReport& ev )
|
|
|
|
{
|
|
|
|
CheckString( ev.text );
|
|
|
|
|
|
|
|
auto& next = m_nextCallstack[ev.thread];
|
|
|
|
next.type = NextCallstackType::Crash;
|
|
|
|
|
2019-03-26 20:41:44 +00:00
|
|
|
m_data.crashEvent.thread = ev.thread;
|
|
|
|
m_data.crashEvent.time = TscTime( ev.time );
|
|
|
|
m_data.crashEvent.message = ev.text;
|
|
|
|
m_data.crashEvent.callstack = 0;
|
2018-08-20 00:07:31 +00:00
|
|
|
}
|
|
|
|
|
2019-02-21 21:45:39 +00:00
|
|
|
void Worker::ProcessSysTime( const QueueSysTime& ev )
|
|
|
|
{
|
|
|
|
const auto time = TscTime( ev.time );
|
2019-02-24 17:10:39 +00:00
|
|
|
m_data.lastTime = std::max( m_data.lastTime, time );
|
2019-02-21 21:45:39 +00:00
|
|
|
const auto val = ev.sysTime;
|
|
|
|
if( !m_sysTimePlot )
|
|
|
|
{
|
|
|
|
m_sysTimePlot = m_slab.AllocInit<PlotData>();
|
|
|
|
m_sysTimePlot->name = 0;
|
|
|
|
m_sysTimePlot->type = PlotType::SysTime;
|
|
|
|
m_sysTimePlot->min = val;
|
|
|
|
m_sysTimePlot->max = val;
|
|
|
|
m_sysTimePlot->data.push_back( { time, val } );
|
|
|
|
m_data.plots.Data().push_back( m_sysTimePlot );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert( !m_sysTimePlot->data.empty() );
|
|
|
|
assert( m_sysTimePlot->data.back().time <= time );
|
|
|
|
if( m_sysTimePlot->min > val ) m_sysTimePlot->min = val;
|
|
|
|
else if( m_sysTimePlot->max < val ) m_sysTimePlot->max = val;
|
|
|
|
m_sysTimePlot->data.push_back_non_empty( { time, val } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-04-28 13:49:12 +00:00
|
|
|
void Worker::MemAllocChanged( int64_t time )
|
|
|
|
{
|
|
|
|
const auto val = (double)m_data.memory.usage;
|
|
|
|
if( !m_data.memory.plot )
|
|
|
|
{
|
|
|
|
CreateMemAllocPlot();
|
|
|
|
m_data.memory.plot->min = val;
|
|
|
|
m_data.memory.plot->max = val;
|
|
|
|
m_data.memory.plot->data.push_back( { time, val } );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
assert( !m_data.memory.plot->data.empty() );
|
|
|
|
assert( m_data.memory.plot->data.back().time <= time );
|
|
|
|
if( m_data.memory.plot->min > val ) m_data.memory.plot->min = val;
|
|
|
|
else if( m_data.memory.plot->max < val ) m_data.memory.plot->max = val;
|
|
|
|
m_data.memory.plot->data.push_back_non_empty( { time, val } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Worker::CreateMemAllocPlot()
|
|
|
|
{
|
|
|
|
assert( !m_data.memory.plot );
|
|
|
|
m_data.memory.plot = m_slab.AllocInit<PlotData>();
|
|
|
|
m_data.memory.plot->name = 0;
|
|
|
|
m_data.memory.plot->type = PlotType::Memory;
|
2018-08-04 17:47:09 +00:00
|
|
|
m_data.memory.plot->data.push_back( { GetFrameBegin( *m_data.framesBase, 0 ), 0. } );
|
2018-08-04 14:33:03 +00:00
|
|
|
m_data.plots.Data().push_back( m_data.memory.plot );
|
2018-04-01 00:03:34 +00:00
|
|
|
}
|
|
|
|
|
2018-04-29 11:40:04 +00:00
|
|
|
void Worker::ReconstructMemAllocPlot()
|
|
|
|
{
|
2018-05-02 15:59:50 +00:00
|
|
|
auto& mem = m_data.memory;
|
2018-05-12 20:41:18 +00:00
|
|
|
#ifdef MY_LIBCPP_SUCKS
|
|
|
|
pdqsort_branchless( mem.frees.begin(), mem.frees.end(), [&mem] ( const auto& lhs, const auto& rhs ) { return mem.data[lhs].timeFree < mem.data[rhs].timeFree; } );
|
|
|
|
#else
|
2018-05-07 23:40:22 +00:00
|
|
|
std::sort( std::execution::par_unseq, mem.frees.begin(), mem.frees.end(), [&mem] ( const auto& lhs, const auto& rhs ) { return mem.data[lhs].timeFree < mem.data[rhs].timeFree; } );
|
2018-05-12 20:41:18 +00:00
|
|
|
#endif
|
2018-04-29 11:40:04 +00:00
|
|
|
|
2018-05-02 15:59:50 +00:00
|
|
|
const auto psz = mem.data.size() + mem.frees.size() + 1;
|
2018-04-29 11:40:04 +00:00
|
|
|
|
|
|
|
PlotData* plot;
|
|
|
|
{
|
2019-05-28 17:21:53 +00:00
|
|
|
std::lock_guard<std::shared_mutex> lock( m_data.lock );
|
2018-04-29 11:40:04 +00:00
|
|
|
plot = m_slab.AllocInit<PlotData>();
|
|
|
|
}
|
|
|
|
|
|
|
|
plot->name = 0;
|
|
|
|
plot->type = PlotType::Memory;
|
2019-02-15 00:58:23 +00:00
|
|
|
plot->data.reserve_exact( psz, m_slab );
|
2018-04-29 11:40:04 +00:00
|
|
|
|
2018-05-02 15:59:50 +00:00
|
|
|
auto aptr = mem.data.begin();
|
|
|
|
auto aend = mem.data.end();
|
|
|
|
auto fptr = mem.frees.begin();
|
|
|
|
auto fend = mem.frees.end();
|
2018-04-29 11:40:04 +00:00
|
|
|
|
|
|
|
double max = 0;
|
|
|
|
double usage = 0;
|
|
|
|
|
|
|
|
auto ptr = plot->data.data();
|
2018-08-04 17:47:09 +00:00
|
|
|
ptr->time = GetFrameBegin( *m_data.framesBase, 0 );
|
2018-04-29 11:40:04 +00:00
|
|
|
ptr->val = 0;
|
|
|
|
ptr++;
|
|
|
|
|
2018-04-30 11:44:44 +00:00
|
|
|
if( aptr != aend && fptr != fend )
|
2018-04-29 11:40:04 +00:00
|
|
|
{
|
2018-04-30 11:44:44 +00:00
|
|
|
auto atime = aptr->timeAlloc;
|
2019-01-31 17:37:59 +00:00
|
|
|
auto ftime = mem.data[*fptr].timeFree;
|
2018-04-30 11:44:44 +00:00
|
|
|
|
|
|
|
for(;;)
|
2018-04-29 11:40:04 +00:00
|
|
|
{
|
2018-04-30 11:44:44 +00:00
|
|
|
if( atime < ftime )
|
|
|
|
{
|
|
|
|
usage += int64_t( aptr->size );
|
|
|
|
assert( usage >= 0 );
|
|
|
|
if( max < usage ) max = usage;
|
|
|
|
ptr->time = atime;
|
|
|
|
ptr->val = usage;
|
|
|
|
ptr++;
|
|
|
|
aptr++;
|
|
|
|
if( aptr == aend ) break;
|
|
|
|
atime = aptr->timeAlloc;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-31 17:37:59 +00:00
|
|
|
usage -= int64_t( mem.data[*fptr].size );
|
2018-04-30 11:44:44 +00:00
|
|
|
assert( usage >= 0 );
|
|
|
|
if( max < usage ) max = usage;
|
|
|
|
ptr->time = ftime;
|
|
|
|
ptr->val = usage;
|
|
|
|
ptr++;
|
|
|
|
fptr++;
|
|
|
|
if( fptr == fend ) break;
|
2019-01-31 17:37:59 +00:00
|
|
|
ftime = mem.data[*fptr].timeFree;
|
2018-04-30 11:44:44 +00:00
|
|
|
}
|
2018-04-29 11:40:04 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-30 11:44:44 +00:00
|
|
|
|
2018-04-29 11:40:04 +00:00
|
|
|
while( aptr != aend )
|
|
|
|
{
|
|
|
|
assert( aptr->timeFree < 0 );
|
|
|
|
int64_t time = aptr->timeAlloc;
|
|
|
|
usage += int64_t( aptr->size );
|
|
|
|
assert( usage >= 0 );
|
|
|
|
if( max < usage ) max = usage;
|
|
|
|
ptr->time = time;
|
|
|
|
ptr->val = usage;
|
|
|
|
ptr++;
|
|
|
|
aptr++;
|
|
|
|
}
|
|
|
|
while( fptr != fend )
|
|
|
|
{
|
2019-01-29 21:10:14 +00:00
|
|
|
const auto& memData = mem.data[*fptr];
|
|
|
|
int64_t time = memData.timeFree;
|
|
|
|
usage -= int64_t( memData.size );
|
2018-04-29 11:40:04 +00:00
|
|
|
assert( usage >= 0 );
|
|
|
|
assert( max >= usage );
|
|
|
|
ptr->time = time;
|
|
|
|
ptr->val = usage;
|
|
|
|
ptr++;
|
|
|
|
fptr++;
|
|
|
|
}
|
|
|
|
|
|
|
|
plot->min = 0;
|
|
|
|
plot->max = max;
|
|
|
|
|
2019-05-28 17:21:53 +00:00
|
|
|
std::lock_guard<std::shared_mutex> lock( m_data.lock );
|
2018-08-04 14:33:03 +00:00
|
|
|
m_data.plots.Data().insert( m_data.plots.Data().begin(), plot );
|
2018-05-02 15:18:52 +00:00
|
|
|
m_data.memory.plot = plot;
|
2018-04-29 11:40:04 +00:00
|
|
|
}
|
|
|
|
|
2018-12-30 22:06:03 +00:00
|
|
|
void Worker::ReadTimeline( FileRead& f, ZoneEvent* zone, uint16_t thread, int64_t& refTime )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
uint64_t sz;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-07-22 14:05:50 +00:00
|
|
|
if( sz == 0 )
|
|
|
|
{
|
|
|
|
zone->child = -1;
|
|
|
|
}
|
|
|
|
else
|
2018-03-15 21:54:10 +00:00
|
|
|
{
|
2019-03-26 20:41:44 +00:00
|
|
|
zone->child = m_data.zoneChildren.size();
|
2018-07-22 14:05:50 +00:00
|
|
|
// Put placeholder to have proper size of zone children in nested calls
|
2019-03-26 20:41:44 +00:00
|
|
|
m_data.zoneChildren.push_back( Vector<ZoneEvent*>() );
|
2018-07-22 14:05:50 +00:00
|
|
|
// Real data buffer. Can't use placeholder, as the vector can be reallocated
|
|
|
|
// and the buffer address will change, but the reference won't.
|
|
|
|
Vector<ZoneEvent*> tmp;
|
2018-12-30 22:06:03 +00:00
|
|
|
ReadTimeline( f, tmp, thread, sz, refTime );
|
2019-03-26 20:41:44 +00:00
|
|
|
m_data.zoneChildren[zone->child] = std::move( tmp );
|
2018-03-15 21:54:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2018-12-30 22:06:03 +00:00
|
|
|
void Worker::ReadTimelinePre042( FileRead& f, ZoneEvent* zone, uint16_t thread, int fileVer )
|
2018-06-21 23:30:08 +00:00
|
|
|
{
|
|
|
|
uint64_t sz;
|
|
|
|
f.Read( sz );
|
2018-07-22 14:05:50 +00:00
|
|
|
if( sz == 0 )
|
|
|
|
{
|
|
|
|
zone->child = -1;
|
|
|
|
}
|
|
|
|
else
|
2018-06-21 23:30:08 +00:00
|
|
|
{
|
2019-03-26 20:41:44 +00:00
|
|
|
zone->child = m_data.zoneChildren.size();
|
|
|
|
m_data.zoneChildren.push_back( Vector<ZoneEvent*>() );
|
2018-07-22 14:05:50 +00:00
|
|
|
Vector<ZoneEvent*> tmp;
|
2018-12-30 22:06:03 +00:00
|
|
|
ReadTimelinePre042( f, tmp, thread, sz, fileVer );
|
2019-03-26 20:41:44 +00:00
|
|
|
m_data.zoneChildren[zone->child] = std::move( tmp );
|
2018-06-21 23:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 19:09:45 +00:00
|
|
|
void Worker::ReadTimeline( FileRead& f, GpuEvent* zone, int64_t& refTime, int64_t& refGpuTime )
|
2018-03-15 21:54:10 +00:00
|
|
|
{
|
|
|
|
uint64_t sz;
|
2018-04-30 23:47:56 +00:00
|
|
|
f.Read( sz );
|
2018-07-22 17:47:01 +00:00
|
|
|
if( sz == 0 )
|
2018-03-15 21:54:10 +00:00
|
|
|
{
|
2018-07-22 17:47:01 +00:00
|
|
|
zone->child = -1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-03-26 20:41:44 +00:00
|
|
|
zone->child = m_data.gpuChildren.size();
|
|
|
|
m_data.gpuChildren.push_back( Vector<GpuEvent*>() );
|
2018-07-22 17:47:01 +00:00
|
|
|
Vector<GpuEvent*> tmp;
|
2019-01-03 19:09:45 +00:00
|
|
|
ReadTimeline( f, tmp, sz, refTime, refGpuTime );
|
2019-03-26 20:41:44 +00:00
|
|
|
m_data.gpuChildren[zone->child] = std::move( tmp );
|
2018-03-15 21:54:10 +00:00
|
|
|
}
|
|
|
|
}
|
2018-03-15 20:27:36 +00:00
|
|
|
|
2019-02-16 22:04:34 +00:00
|
|
|
void Worker::ReadTimelinePre044( FileRead& f, GpuEvent* zone, int64_t& refTime, int64_t& refGpuTime, int fileVer )
|
2018-06-17 17:05:22 +00:00
|
|
|
{
|
|
|
|
uint64_t sz;
|
|
|
|
f.Read( sz );
|
2018-07-22 17:47:01 +00:00
|
|
|
if( sz == 0 )
|
|
|
|
{
|
|
|
|
zone->child = -1;
|
|
|
|
}
|
|
|
|
else
|
2018-06-17 17:05:22 +00:00
|
|
|
{
|
2019-03-26 20:41:44 +00:00
|
|
|
zone->child = m_data.gpuChildren.size();
|
|
|
|
m_data.gpuChildren.push_back( Vector<GpuEvent*>() );
|
2018-07-22 17:47:01 +00:00
|
|
|
Vector<GpuEvent*> tmp;
|
2019-02-16 22:04:34 +00:00
|
|
|
ReadTimelinePre044( f, tmp, sz, refTime, refGpuTime, fileVer );
|
2019-03-26 20:41:44 +00:00
|
|
|
m_data.gpuChildren[zone->child] = std::move( tmp );
|
2018-06-17 17:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-21 23:30:08 +00:00
|
|
|
void Worker::ReadTimelineUpdateStatistics( ZoneEvent* zone, uint16_t thread )
|
|
|
|
{
|
|
|
|
#ifndef TRACY_NO_STATISTICS
|
|
|
|
auto it = m_data.sourceLocationZones.find( zone->srcloc );
|
|
|
|
assert( it != m_data.sourceLocationZones.end() );
|
2019-01-29 20:59:52 +00:00
|
|
|
auto& slz = it->second;
|
|
|
|
auto& ztd = slz.zones.push_next();
|
2018-06-21 23:30:08 +00:00
|
|
|
ztd.zone = zone;
|
|
|
|
ztd.thread = thread;
|
|
|
|
|
|
|
|
if( zone->end >= 0 )
|
|
|
|
{
|
|
|
|
auto timeSpan = zone->end - zone->start;
|
|
|
|
if( timeSpan > 0 )
|
|
|
|
{
|
2019-01-29 20:59:52 +00:00
|
|
|
slz.min = std::min( slz.min, timeSpan );
|
|
|
|
slz.max = std::max( slz.max, timeSpan );
|
|
|
|
slz.total += timeSpan;
|
2019-03-14 00:23:37 +00:00
|
|
|
slz.sumSq += double( timeSpan ) * timeSpan;
|
2018-07-22 14:05:50 +00:00
|
|
|
if( zone->child >= 0 )
|
2018-06-21 23:30:08 +00:00
|
|
|
{
|
2018-07-22 14:05:50 +00:00
|
|
|
for( auto& v : GetZoneChildren( zone->child ) )
|
|
|
|
{
|
|
|
|
const auto childSpan = std::max( int64_t( 0 ), v->end - v->start );
|
|
|
|
timeSpan -= childSpan;
|
|
|
|
}
|
2018-06-21 23:30:08 +00:00
|
|
|
}
|
2019-01-29 20:59:52 +00:00
|
|
|
slz.selfMin = std::min( slz.selfMin, timeSpan );
|
|
|
|
slz.selfMax = std::max( slz.selfMax, timeSpan );
|
|
|
|
slz.selfTotal += timeSpan;
|
2018-06-21 23:30:08 +00:00
|
|
|
}
|
|
|
|
}
|
2018-07-29 12:16:13 +00:00
|
|
|
#else
|
|
|
|
auto it = m_data.sourceLocationZonesCnt.find( zone->srcloc );
|
|
|
|
assert( it != m_data.sourceLocationZonesCnt.end() );
|
|
|
|
it->second++;
|
2018-06-21 23:30:08 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2018-12-30 22:06:03 +00:00
|
|
|
void Worker::ReadTimeline( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size, int64_t& refTime )
|
2018-03-15 21:54:10 +00:00
|
|
|
{
|
|
|
|
assert( size != 0 );
|
2019-02-15 00:58:23 +00:00
|
|
|
vec.reserve_exact( size, m_slab );
|
2018-03-15 21:54:10 +00:00
|
|
|
m_data.zonesCnt += size;
|
2019-02-16 19:53:07 +00:00
|
|
|
auto zone = (ZoneEvent*)m_slab.AllocBig( sizeof( ZoneEvent ) * size );
|
|
|
|
auto zptr = zone;
|
|
|
|
auto vptr = vec.data();
|
2018-03-15 21:54:10 +00:00
|
|
|
for( uint64_t i=0; i<size; i++ )
|
2019-02-16 19:53:07 +00:00
|
|
|
{
|
|
|
|
*vptr++ = zptr++;
|
|
|
|
}
|
|
|
|
do
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-07-28 17:22:28 +00:00
|
|
|
s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed );
|
2019-02-15 01:46:25 +00:00
|
|
|
// Use zone->end as scratch buffer for zone start time offset.
|
|
|
|
f.Read( &zone->end, sizeof( zone->end ) + sizeof( zone->srcloc ) + sizeof( zone->cpu_start ) + sizeof( zone->cpu_end ) + sizeof( zone->text ) + sizeof( zone->callstack ) + sizeof( zone->name ) );
|
|
|
|
refTime += zone->end;
|
|
|
|
zone->start = refTime;
|
2018-12-30 22:06:03 +00:00
|
|
|
ReadTimeline( f, zone, thread, refTime );
|
|
|
|
zone->end = ReadTimeOffset( f, refTime );
|
2019-03-13 00:46:05 +00:00
|
|
|
#ifdef TRACY_NO_STATISTICS
|
2018-06-21 23:30:08 +00:00
|
|
|
ReadTimelineUpdateStatistics( zone, thread );
|
2019-03-13 00:46:05 +00:00
|
|
|
#endif
|
2018-06-21 23:30:08 +00:00
|
|
|
}
|
2019-02-16 19:53:07 +00:00
|
|
|
while( ++zone != zptr );
|
2018-06-21 23:30:08 +00:00
|
|
|
}
|
2018-03-18 22:37:07 +00:00
|
|
|
|
2018-12-30 22:06:03 +00:00
|
|
|
void Worker::ReadTimelinePre042( FileRead& f, Vector<ZoneEvent*>& vec, uint16_t thread, uint64_t size, int fileVer )
|
2018-06-21 23:30:08 +00:00
|
|
|
{
|
|
|
|
assert( size != 0 );
|
2019-02-15 00:58:23 +00:00
|
|
|
vec.reserve_exact( size, m_slab );
|
2018-06-21 23:30:08 +00:00
|
|
|
m_data.zonesCnt += size;
|
2018-03-18 19:15:45 +00:00
|
|
|
|
2018-06-21 23:30:08 +00:00
|
|
|
for( uint64_t i=0; i<size; i++ )
|
|
|
|
{
|
2018-07-28 17:22:28 +00:00
|
|
|
s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed );
|
2018-06-21 23:30:08 +00:00
|
|
|
auto zone = m_slab.Alloc<ZoneEvent>();
|
2018-08-09 17:37:37 +00:00
|
|
|
vec[i] = zone;
|
2018-06-21 23:30:08 +00:00
|
|
|
|
2018-06-29 14:12:17 +00:00
|
|
|
if( fileVer <= FileVersion( 0, 3, 1 ) )
|
|
|
|
{
|
|
|
|
f.Read( zone, 26 );
|
|
|
|
zone->callstack = 0;
|
|
|
|
zone->name.__data = 0;
|
|
|
|
}
|
2018-12-30 22:06:03 +00:00
|
|
|
else if( fileVer <= FileVersion( 0, 3, 2 ) )
|
2018-06-29 14:12:17 +00:00
|
|
|
{
|
|
|
|
f.Read( zone, 30 );
|
|
|
|
zone->name.__data = 0;
|
|
|
|
}
|
2018-12-30 22:06:03 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
assert( fileVer <= FileVersion( 0, 4, 1 ) );
|
|
|
|
f.Read( zone, sizeof( ZoneEvent ) - sizeof( ZoneEvent::child ) );
|
|
|
|
}
|
|
|
|
ReadTimelinePre042( f, zone, thread, fileVer );
|
2019-03-13 00:46:05 +00:00
|
|
|
#ifdef TRACY_NO_STATISTICS
|
2018-06-21 23:30:08 +00:00
|
|
|
ReadTimelineUpdateStatistics( zone, thread );
|
2019-03-13 00:46:05 +00:00
|
|
|
#endif
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 19:09:45 +00:00
|
|
|
void Worker::ReadTimeline( FileRead& f, Vector<GpuEvent*>& vec, uint64_t size, int64_t& refTime, int64_t& refGpuTime )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-03-15 21:54:10 +00:00
|
|
|
assert( size != 0 );
|
2019-02-15 00:58:23 +00:00
|
|
|
vec.reserve_exact( size, m_slab );
|
2019-02-16 19:53:07 +00:00
|
|
|
auto zone = (GpuEvent*)m_slab.AllocBig( sizeof( GpuEvent ) * size );
|
|
|
|
auto zptr = zone;
|
|
|
|
auto vptr = vec.data();
|
2018-03-15 21:54:10 +00:00
|
|
|
for( uint64_t i=0; i<size; i++ )
|
2019-02-16 19:53:07 +00:00
|
|
|
{
|
|
|
|
*vptr++ = zptr++;
|
|
|
|
}
|
|
|
|
do
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2018-07-28 17:22:28 +00:00
|
|
|
s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
2019-02-15 01:46:25 +00:00
|
|
|
// Use zone->gpuStart as scratch buffer for CPU zone start time offset.
|
|
|
|
// Use zone->gpuEnd as scratch buffer for GPU zone start time offset.
|
2019-02-16 22:04:34 +00:00
|
|
|
f.Read( &zone->gpuStart, sizeof( zone->gpuStart ) + sizeof( zone->gpuEnd ) + sizeof( zone->srcloc ) + sizeof( zone->callstack ) + sizeof( zone->thread ) );
|
2019-02-15 01:46:25 +00:00
|
|
|
refTime += zone->gpuStart;
|
|
|
|
refGpuTime += zone->gpuEnd;
|
|
|
|
zone->cpuStart = refTime;
|
|
|
|
zone->gpuStart = refGpuTime;
|
2018-12-30 22:06:03 +00:00
|
|
|
|
2019-01-03 19:09:45 +00:00
|
|
|
ReadTimeline( f, zone, refTime, refGpuTime );
|
2018-12-30 22:06:03 +00:00
|
|
|
|
|
|
|
zone->cpuEnd = ReadTimeOffset( f, refTime );
|
2019-01-03 19:09:45 +00:00
|
|
|
zone->gpuEnd = ReadTimeOffset( f, refGpuTime );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2019-02-16 19:53:07 +00:00
|
|
|
while( ++zone != zptr );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2019-02-16 22:04:34 +00:00
|
|
|
void Worker::ReadTimelinePre044( FileRead& f, Vector<GpuEvent*>& vec, uint64_t size, int64_t& refTime, int64_t& refGpuTime, int fileVer )
|
2018-06-17 17:05:22 +00:00
|
|
|
{
|
|
|
|
assert( size != 0 );
|
2019-02-15 00:58:23 +00:00
|
|
|
vec.reserve_exact( size, m_slab );
|
2018-06-17 17:05:22 +00:00
|
|
|
|
|
|
|
for( uint64_t i=0; i<size; i++ )
|
|
|
|
{
|
2018-07-28 17:22:28 +00:00
|
|
|
s_loadProgress.subProgress.fetch_add( 1, std::memory_order_relaxed );
|
2019-02-15 00:31:58 +00:00
|
|
|
auto zone = m_slab.Alloc<GpuEvent>();
|
2018-08-09 17:37:37 +00:00
|
|
|
vec[i] = zone;
|
2018-06-17 17:05:22 +00:00
|
|
|
|
2018-12-30 22:06:03 +00:00
|
|
|
if( fileVer <= FileVersion( 0, 3, 1 ) )
|
|
|
|
{
|
|
|
|
f.Read( zone, 36 );
|
|
|
|
zone->thread = 0;
|
|
|
|
zone->callstack = 0;
|
|
|
|
}
|
2019-02-16 22:04:34 +00:00
|
|
|
else if( fileVer <= FileVersion( 0, 4, 1 ) )
|
2018-12-30 22:06:03 +00:00
|
|
|
{
|
|
|
|
f.Read( zone, sizeof( GpuEvent::cpuStart ) + sizeof( GpuEvent::cpuEnd ) + sizeof( GpuEvent::gpuStart ) + sizeof( GpuEvent::gpuEnd ) + sizeof( GpuEvent::srcloc ) + sizeof( GpuEvent::callstack ) );
|
|
|
|
uint64_t thread;
|
|
|
|
f.Read( thread );
|
|
|
|
if( thread == 0 )
|
|
|
|
{
|
|
|
|
zone->thread = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone->thread = CompressThread( thread );
|
|
|
|
}
|
|
|
|
}
|
2019-02-16 22:04:34 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
assert( fileVer <= FileVersion( 0, 4, 3 ) );
|
|
|
|
|
|
|
|
f.Read( &zone->gpuStart, sizeof( zone->gpuStart ) + sizeof( zone->gpuEnd ) + sizeof( zone->srcloc ) + sizeof( zone->callstack ) );
|
|
|
|
refTime += zone->gpuStart;
|
|
|
|
refGpuTime += zone->gpuEnd;
|
|
|
|
zone->cpuStart = refTime;
|
|
|
|
zone->gpuStart = refGpuTime;
|
|
|
|
|
|
|
|
uint64_t thread;
|
|
|
|
f.Read( thread );
|
|
|
|
if( thread == 0 )
|
|
|
|
{
|
|
|
|
zone->thread = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
zone->thread = CompressThread( thread );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ReadTimelinePre044( f, zone, refTime, refGpuTime, fileVer );
|
|
|
|
if( fileVer > FileVersion( 0, 4, 1 ) )
|
|
|
|
{
|
|
|
|
assert( fileVer <= FileVersion( 0, 4, 3 ) );
|
|
|
|
zone->cpuEnd = ReadTimeOffset( f, refTime );
|
|
|
|
zone->gpuEnd = ReadTimeOffset( f, refGpuTime );
|
|
|
|
}
|
2018-06-17 17:05:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
void Worker::Write( FileWrite& f )
|
|
|
|
{
|
2018-04-21 11:45:48 +00:00
|
|
|
f.Write( FileHeader, sizeof( FileHeader ) );
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
f.Write( &m_delay, sizeof( m_delay ) );
|
|
|
|
f.Write( &m_resolution, sizeof( m_resolution ) );
|
|
|
|
f.Write( &m_timerMul, sizeof( m_timerMul ) );
|
|
|
|
f.Write( &m_data.lastTime, sizeof( m_data.lastTime ) );
|
2018-07-10 20:56:41 +00:00
|
|
|
f.Write( &m_data.frameOffset, sizeof( m_data.frameOffset ) );
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
uint64_t sz = m_captureName.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
f.Write( m_captureName.c_str(), sz );
|
|
|
|
|
2018-08-28 22:57:11 +00:00
|
|
|
sz = m_captureProgram.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
f.Write( m_captureProgram.c_str(), sz );
|
|
|
|
|
|
|
|
f.Write( &m_captureTime, sizeof( m_captureTime ) );
|
|
|
|
|
2018-08-19 16:28:48 +00:00
|
|
|
sz = m_hostInfo.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
f.Write( m_hostInfo.c_str(), sz );
|
|
|
|
|
2019-03-26 20:41:44 +00:00
|
|
|
f.Write( &m_data.crashEvent, sizeof( m_data.crashEvent ) );
|
2018-08-20 00:27:24 +00:00
|
|
|
|
2018-08-04 17:47:09 +00:00
|
|
|
sz = m_data.frames.Data().size();
|
2018-02-13 13:57:47 +00:00
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2018-08-04 17:47:09 +00:00
|
|
|
for( auto& fd : m_data.frames.Data() )
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
2018-08-04 17:47:09 +00:00
|
|
|
f.Write( &fd->name, sizeof( fd->name ) );
|
2018-08-05 00:09:59 +00:00
|
|
|
f.Write( &fd->continuous, sizeof( fd->continuous ) );
|
2018-08-04 17:47:09 +00:00
|
|
|
sz = fd->frames.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2018-08-05 00:09:59 +00:00
|
|
|
if( fd->continuous )
|
|
|
|
{
|
|
|
|
for( auto& fe : fd->frames )
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
WriteTimeOffset( f, refTime, fe.start );
|
2019-06-06 21:08:19 +00:00
|
|
|
f.Write( &fe.frameImage, sizeof( fe.frameImage ) );
|
2018-08-05 00:09:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
for( auto& fe : fd->frames )
|
|
|
|
{
|
|
|
|
WriteTimeOffset( f, refTime, fe.start );
|
|
|
|
WriteTimeOffset( f, refTime, fe.end );
|
2019-06-06 21:08:19 +00:00
|
|
|
f.Write( &fe.frameImage, sizeof( fe.frameImage ) );
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
2018-08-05 00:09:59 +00:00
|
|
|
}
|
2018-08-04 17:47:09 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
|
|
|
|
sz = m_data.stringData.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.stringData )
|
|
|
|
{
|
|
|
|
uint64_t ptr = (uint64_t)v;
|
|
|
|
f.Write( &ptr, sizeof( ptr ) );
|
|
|
|
sz = strlen( v );
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
f.Write( v, sz );
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = m_data.strings.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.strings )
|
|
|
|
{
|
|
|
|
f.Write( &v.first, sizeof( v.first ) );
|
|
|
|
uint64_t ptr = (uint64_t)v.second;
|
|
|
|
f.Write( &ptr, sizeof( ptr ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = m_data.threadNames.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.threadNames )
|
|
|
|
{
|
|
|
|
f.Write( &v.first, sizeof( v.first ) );
|
|
|
|
uint64_t ptr = (uint64_t)v.second;
|
|
|
|
f.Write( &ptr, sizeof( ptr ) );
|
|
|
|
}
|
|
|
|
|
2018-07-29 13:19:44 +00:00
|
|
|
sz = m_data.threadExpand.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2019-02-16 21:48:29 +00:00
|
|
|
f.Write( m_data.threadExpand.data(), sz * sizeof( uint64_t ) );
|
2018-07-29 13:19:44 +00:00
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
sz = m_data.sourceLocation.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.sourceLocation )
|
|
|
|
{
|
|
|
|
f.Write( &v.first, sizeof( v.first ) );
|
|
|
|
f.Write( &v.second, sizeof( v.second ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = m_data.sourceLocationExpand.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.sourceLocationExpand )
|
|
|
|
{
|
|
|
|
f.Write( &v, sizeof( v ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
sz = m_data.sourceLocationPayload.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.sourceLocationPayload )
|
|
|
|
{
|
|
|
|
f.Write( v, sizeof( *v ) );
|
|
|
|
}
|
|
|
|
|
2018-07-29 12:58:01 +00:00
|
|
|
#ifndef TRACY_NO_STATISTICS
|
|
|
|
sz = m_data.sourceLocationZones.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.sourceLocationZones )
|
|
|
|
{
|
|
|
|
int32_t id = v.first;
|
|
|
|
uint64_t cnt = v.second.zones.size();
|
|
|
|
f.Write( &id, sizeof( id ) );
|
|
|
|
f.Write( &cnt, sizeof( cnt ) );
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
sz = m_data.sourceLocationZonesCnt.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.sourceLocationZonesCnt )
|
|
|
|
{
|
|
|
|
int32_t id = v.first;
|
|
|
|
uint64_t cnt = v.second;
|
|
|
|
f.Write( &id, sizeof( id ) );
|
|
|
|
f.Write( &cnt, sizeof( cnt ) );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
sz = m_data.lockMap.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.lockMap )
|
|
|
|
{
|
|
|
|
f.Write( &v.first, sizeof( v.first ) );
|
2019-03-16 01:09:50 +00:00
|
|
|
f.Write( &v.second->srcloc, sizeof( v.second->srcloc ) );
|
|
|
|
f.Write( &v.second->type, sizeof( v.second->type ) );
|
|
|
|
f.Write( &v.second->valid, sizeof( v.second->valid ) );
|
|
|
|
f.Write( &v.second->timeAnnounce, sizeof( v.second->timeAnnounce ) );
|
|
|
|
f.Write( &v.second->timeTerminate, sizeof( v.second->timeTerminate ) );
|
|
|
|
sz = v.second->threadList.size();
|
2018-02-13 13:57:47 +00:00
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2019-03-16 01:09:50 +00:00
|
|
|
for( auto& t : v.second->threadList )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
f.Write( &t, sizeof( t ) );
|
|
|
|
}
|
2019-03-16 01:09:50 +00:00
|
|
|
int64_t refTime = v.second->timeAnnounce;
|
|
|
|
sz = v.second->timeline.size();
|
2018-02-13 13:57:47 +00:00
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2019-03-16 01:09:50 +00:00
|
|
|
for( auto& lev : v.second->timeline )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2019-03-16 13:18:43 +00:00
|
|
|
WriteTimeOffset( f, refTime, lev.ptr->time );
|
|
|
|
f.Write( &lev.ptr->srcloc, sizeof( lev.ptr->srcloc ) );
|
|
|
|
f.Write( &lev.ptr->thread, sizeof( lev.ptr->thread ) );
|
|
|
|
f.Write( &lev.ptr->type, sizeof( lev.ptr->type ) );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
|
|
|
sz = m_data.messages.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : m_data.messages )
|
|
|
|
{
|
|
|
|
const auto ptr = (uint64_t)v;
|
|
|
|
f.Write( &ptr, sizeof( ptr ) );
|
|
|
|
WriteTimeOffset( f, refTime, v->time );
|
|
|
|
f.Write( &v->ref, sizeof( v->ref ) );
|
2019-05-10 18:32:47 +00:00
|
|
|
f.Write( &v->color, sizeof( v->color ) );
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2019-03-27 00:46:54 +00:00
|
|
|
sz = 0;
|
|
|
|
for( auto& v : m_data.threads ) sz += v->count;
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2018-02-13 13:57:47 +00:00
|
|
|
sz = m_data.threads.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& thread : m_data.threads )
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
2018-02-13 13:57:47 +00:00
|
|
|
f.Write( &thread->id, sizeof( thread->id ) );
|
|
|
|
f.Write( &thread->count, sizeof( thread->count ) );
|
2018-12-30 22:06:03 +00:00
|
|
|
WriteTimeline( f, thread->timeline, refTime );
|
2018-02-13 13:57:47 +00:00
|
|
|
sz = thread->messages.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& v : thread->messages )
|
|
|
|
{
|
|
|
|
auto ptr = uint64_t( v );
|
|
|
|
f.Write( &ptr, sizeof( ptr ) );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-27 00:46:54 +00:00
|
|
|
sz = 0;
|
|
|
|
for( auto& v : m_data.gpuData ) sz += v->count;
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2018-02-13 13:57:47 +00:00
|
|
|
sz = m_data.gpuData.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& ctx : m_data.gpuData )
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
2019-01-03 19:09:45 +00:00
|
|
|
int64_t refGpuTime = 0;
|
2018-02-13 13:57:47 +00:00
|
|
|
f.Write( &ctx->thread, sizeof( ctx->thread ) );
|
|
|
|
f.Write( &ctx->accuracyBits, sizeof( ctx->accuracyBits ) );
|
|
|
|
f.Write( &ctx->count, sizeof( ctx->count ) );
|
2018-06-17 16:27:16 +00:00
|
|
|
f.Write( &ctx->period, sizeof( ctx->period ) );
|
2019-01-03 19:09:45 +00:00
|
|
|
WriteTimeline( f, ctx->timeline, refTime, refGpuTime );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-08-04 14:33:03 +00:00
|
|
|
sz = m_data.plots.Data().size();
|
2019-02-21 21:53:26 +00:00
|
|
|
for( auto& plot : m_data.plots.Data() ) { if( plot->type == PlotType::Memory ) sz--; }
|
2018-02-13 13:57:47 +00:00
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2018-08-04 14:33:03 +00:00
|
|
|
for( auto& plot : m_data.plots.Data() )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
2019-02-21 21:53:26 +00:00
|
|
|
if( plot->type == PlotType::Memory ) continue;
|
|
|
|
f.Write( &plot->type, sizeof( plot->type ) );
|
2018-02-13 13:57:47 +00:00
|
|
|
f.Write( &plot->name, sizeof( plot->name ) );
|
|
|
|
f.Write( &plot->min, sizeof( plot->min ) );
|
|
|
|
f.Write( &plot->max, sizeof( plot->max ) );
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
2018-02-13 13:57:47 +00:00
|
|
|
sz = plot->data.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2018-12-30 22:06:03 +00:00
|
|
|
for( auto& v : plot->data )
|
|
|
|
{
|
|
|
|
WriteTimeOffset( f, refTime, v.time );
|
|
|
|
f.Write( &v.val, sizeof( v.val ) );
|
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
2018-04-02 00:05:16 +00:00
|
|
|
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
int64_t refTime = 0;
|
|
|
|
sz = m_data.memory.data.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
sz = m_data.memory.active.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
sz = m_data.memory.frees.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& mem : m_data.memory.data )
|
|
|
|
{
|
|
|
|
f.Write( &mem.ptr, sizeof( mem.ptr ) );
|
|
|
|
f.Write( &mem.size, sizeof( mem.size ) );
|
|
|
|
WriteTimeOffset( f, refTime, mem.timeAlloc );
|
|
|
|
int64_t freeOffset = mem.timeFree < 0 ? mem.timeFree : mem.timeFree - mem.timeAlloc;
|
|
|
|
f.Write( &freeOffset, sizeof( freeOffset ) );
|
|
|
|
f.Write( &mem.csAlloc, sizeof( mem.csAlloc ) );
|
|
|
|
f.Write( &mem.csFree, sizeof( mem.csFree ) );
|
2019-02-16 22:00:05 +00:00
|
|
|
f.Write( &mem.threadAlloc, sizeof( mem.threadAlloc ) );
|
|
|
|
f.Write( &mem.threadFree, sizeof( mem.threadFree ) );
|
2018-12-30 22:06:03 +00:00
|
|
|
}
|
|
|
|
f.Write( &m_data.memory.high, sizeof( m_data.memory.high ) );
|
|
|
|
f.Write( &m_data.memory.low, sizeof( m_data.memory.low ) );
|
|
|
|
f.Write( &m_data.memory.usage, sizeof( m_data.memory.usage ) );
|
2018-04-02 00:05:16 +00:00
|
|
|
}
|
2018-06-19 19:39:52 +00:00
|
|
|
|
2018-06-19 19:52:54 +00:00
|
|
|
sz = m_data.callstackPayload.size() - 1;
|
2018-06-19 19:39:52 +00:00
|
|
|
f.Write( &sz, sizeof( sz ) );
|
2018-06-19 23:54:27 +00:00
|
|
|
for( size_t i=1; i<=sz; i++ )
|
2018-06-19 19:39:52 +00:00
|
|
|
{
|
2018-06-19 19:52:54 +00:00
|
|
|
auto cs = m_data.callstackPayload[i];
|
2018-06-19 19:39:52 +00:00
|
|
|
uint8_t csz = cs->size();
|
|
|
|
f.Write( &csz, sizeof( csz ) );
|
2019-03-03 15:50:18 +00:00
|
|
|
f.Write( cs->data(), sizeof( CallstackFrameId ) * csz );
|
2018-06-19 19:39:52 +00:00
|
|
|
}
|
2018-06-19 23:59:25 +00:00
|
|
|
|
|
|
|
sz = m_data.callstackFrameMap.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& frame : m_data.callstackFrameMap )
|
|
|
|
{
|
2019-03-03 15:50:18 +00:00
|
|
|
f.Write( &frame.first, sizeof( CallstackFrameId ) );
|
2019-01-20 18:11:48 +00:00
|
|
|
f.Write( &frame.second->size, sizeof( frame.second->size ) );
|
|
|
|
f.Write( frame.second->data, sizeof( CallstackFrame ) * frame.second->size );
|
2018-06-19 23:59:25 +00:00
|
|
|
}
|
2019-06-06 21:08:19 +00:00
|
|
|
|
|
|
|
sz = m_data.frameImage.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
for( auto& fi : m_data.frameImage )
|
|
|
|
{
|
|
|
|
f.Write( &fi->w, sizeof( fi->w ) );
|
|
|
|
f.Write( &fi->h, sizeof( fi->h ) );
|
2019-06-08 10:17:18 +00:00
|
|
|
const auto image = UnpackFrameImage( *fi );
|
|
|
|
f.Write( image, fi->w * fi->h / 2 );
|
2019-06-06 21:08:19 +00:00
|
|
|
}
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
|
2018-12-30 22:06:03 +00:00
|
|
|
void Worker::WriteTimeline( FileWrite& f, const Vector<ZoneEvent*>& vec, int64_t& refTime )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
uint64_t sz = vec.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
|
|
|
|
for( auto& v : vec )
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
WriteTimeOffset( f, refTime, v->start );
|
|
|
|
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->callstack, sizeof( v->callstack ) );
|
|
|
|
f.Write( &v->name, sizeof( v->name ) );
|
|
|
|
|
2018-07-22 14:05:50 +00:00
|
|
|
if( v->child < 0 )
|
|
|
|
{
|
|
|
|
sz = 0;
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
WriteTimeline( f, GetZoneChildren( v->child ), refTime );
|
2018-07-22 14:05:50 +00:00
|
|
|
}
|
2018-12-30 22:06:03 +00:00
|
|
|
|
|
|
|
WriteTimeOffset( f, refTime, v->end );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-03 19:09:45 +00:00
|
|
|
void Worker::WriteTimeline( FileWrite& f, const Vector<GpuEvent*>& vec, int64_t& refTime, int64_t& refGpuTime )
|
2018-02-13 13:57:47 +00:00
|
|
|
{
|
|
|
|
uint64_t sz = vec.size();
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
|
|
|
|
for( auto& v : vec )
|
|
|
|
{
|
2018-12-30 22:06:03 +00:00
|
|
|
WriteTimeOffset( f, refTime, v->cpuStart );
|
2019-01-03 19:09:45 +00:00
|
|
|
WriteTimeOffset( f, refGpuTime, v->gpuStart );
|
2018-12-30 22:06:03 +00:00
|
|
|
f.Write( &v->srcloc, sizeof( v->srcloc ) );
|
|
|
|
f.Write( &v->callstack, sizeof( v->callstack ) );
|
2019-02-16 22:04:34 +00:00
|
|
|
f.Write( &v->thread, sizeof( v->thread ) );
|
2018-12-30 22:06:03 +00:00
|
|
|
|
2018-07-22 17:47:01 +00:00
|
|
|
if( v->child < 0 )
|
|
|
|
{
|
|
|
|
sz = 0;
|
|
|
|
f.Write( &sz, sizeof( sz ) );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 19:09:45 +00:00
|
|
|
WriteTimeline( f, GetGpuChildren( v->child ), refTime, refGpuTime );
|
2018-07-22 17:47:01 +00:00
|
|
|
}
|
2018-12-30 22:06:03 +00:00
|
|
|
|
|
|
|
WriteTimeOffset( f, refTime, v->cpuEnd );
|
2019-01-03 19:09:45 +00:00
|
|
|
WriteTimeOffset( f, refGpuTime, v->gpuEnd );
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 17:42:15 +00:00
|
|
|
static const char* s_failureReasons[] = {
|
|
|
|
"<unknown reason>",
|
2019-01-15 17:56:26 +00:00
|
|
|
"Invalid order of zone begin and end events.",
|
2019-01-15 23:45:48 +00:00
|
|
|
"Received zone end event without a matching zone begin event.",
|
2019-01-16 00:17:01 +00:00
|
|
|
"Zone text transfer destination doesn't match active zone.",
|
|
|
|
"Zone name transfer destination doesn't match active zone.",
|
2019-02-28 18:32:42 +00:00
|
|
|
"Memory free event without a matching allocation.",
|
|
|
|
"Discontinuous frame begin/end mismatch.",
|
2019-06-09 11:44:53 +00:00
|
|
|
"Frame image offset is invalid.",
|
|
|
|
"Multiple frame images were sent for a single frame.",
|
2019-01-15 17:42:15 +00:00
|
|
|
};
|
|
|
|
|
2019-01-15 17:56:17 +00:00
|
|
|
static_assert( sizeof( s_failureReasons ) / sizeof( *s_failureReasons ) == (int)Worker::Failure::NUM_FAILURES, "Missing failure reason description." );
|
|
|
|
|
2019-01-15 17:42:15 +00:00
|
|
|
const char* Worker::GetFailureString( Worker::Failure failure )
|
|
|
|
{
|
|
|
|
return s_failureReasons[(int)failure];
|
|
|
|
}
|
|
|
|
|
2019-06-08 10:17:18 +00:00
|
|
|
const char* Worker::PackFrameImage( const char* image, uint16_t w, uint16_t h, uint32_t& csz )
|
|
|
|
{
|
|
|
|
const auto insz = size_t( w ) * size_t( h ) / 2;
|
|
|
|
const auto maxout = LZ4_COMPRESSBOUND( insz );
|
|
|
|
if( m_frameImageBufferSize < maxout )
|
|
|
|
{
|
|
|
|
m_frameImageBufferSize = maxout;
|
|
|
|
delete[] m_frameImageBuffer;
|
|
|
|
m_frameImageBuffer = new char[maxout];
|
|
|
|
}
|
|
|
|
const auto outsz = LZ4_compress_default( image, m_frameImageBuffer, insz, maxout );
|
|
|
|
csz = uint32_t( outsz );
|
|
|
|
auto ptr = (char*)m_slab.AllocBig( outsz );
|
|
|
|
memcpy( ptr, m_frameImageBuffer, outsz );
|
|
|
|
return ptr;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* Worker::UnpackFrameImage( const FrameImage& image )
|
|
|
|
{
|
|
|
|
const auto outsz = size_t( image.w ) * size_t( image.h ) / 2;
|
|
|
|
if( m_frameImageBufferSize < outsz )
|
|
|
|
{
|
|
|
|
m_frameImageBufferSize = outsz;
|
|
|
|
delete[] m_frameImageBuffer;
|
|
|
|
m_frameImageBuffer = new char[outsz];
|
|
|
|
}
|
|
|
|
LZ4_decompress_safe( image.ptr, m_frameImageBuffer, image.csz, outsz );
|
|
|
|
return m_frameImageBuffer;
|
|
|
|
}
|
|
|
|
|
2018-02-13 13:57:47 +00:00
|
|
|
}
|