Reconstruct event data.

This commit is contained in:
Bartosz Taudul 2017-09-14 02:00:13 +02:00
parent b1fcf88cf4
commit a159b70d40
3 changed files with 89 additions and 0 deletions

21
server/TracyEvent.hpp Executable file
View File

@ -0,0 +1,21 @@
#ifndef __TRACYEVENT_HPP__
#define __TRACYEVENT_HPP__
#include <vector>
namespace tracy
{
struct Event
{
int64_t start;
int64_t end;
std::vector<uint64_t> child;
};
enum { EventSize = sizeof( Event ) };
}
#endif

View File

@ -101,7 +101,58 @@ close:
void View::Process( const QueueItem& ev )
{
switch( ev.hdr.type )
{
case QueueType::ZoneBegin:
ProcessZoneBegin( ev.hdr.id, ev.zoneBegin );
break;
case QueueType::ZoneEnd:
ProcessZoneEnd( ev.hdr.id, ev.zoneEnd );
break;
default:
assert( false );
break;
}
}
void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
{
auto it = m_pendingEndZone.find( id );
const auto idx = m_data.size();
std::unique_lock<std::mutex> lock( m_lock );
if( it == m_pendingEndZone.end() )
{
m_data.emplace_back( Event { ev.time, -1 } );
lock.unlock();
m_openZones.emplace( id, idx );
}
else
{
assert( ev.time <= it->second.time );
m_data.emplace_back( Event { ev.time, it->second.time } );
lock.unlock();
m_pendingEndZone.erase( it );
}
}
void View::ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev )
{
auto it = m_openZones.find( id );
if( it == m_openZones.end() )
{
m_pendingEndZone.emplace( id, ev );
}
else
{
std::unique_lock<std::mutex> lock( m_lock );
assert( ev.time >= m_data[it->second].start );
m_data[it->second].end = ev.time;
lock.unlock();
m_openZones.erase( it );
}
}
}

View File

@ -2,8 +2,14 @@
#define __TRACYVIEW_HPP__
#include <atomic>
#include <mutex>
#include <string>
#include <thread>
#include <unordered_map>
#include <vector>
#include "../common/TracyQueue.hpp"
#include "TracyEvent.hpp"
namespace tracy
{
@ -23,12 +29,23 @@ private:
void Worker();
void Process( const QueueItem& ev );
void ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev );
void ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev );
std::string m_addr;
std::thread m_thread;
std::atomic<bool> m_shutdown;
int64_t m_timeBegin;
std::mutex m_lock;
std::vector<Event> m_data;
std::vector<uint64_t> m_timeline;
// not used for vis - no need to lock
std::unordered_map<uint64_t, QueueZoneEnd> m_pendingEndZone;
std::unordered_map<uint64_t, uint64_t> m_openZones;
};
}