From 1c56347f1d8008b0a68445a0a1cfce4c0305b915 Mon Sep 17 00:00:00 2001 From: Bartosz Taudul Date: Fri, 15 Sep 2017 19:56:55 +0200 Subject: [PATCH] Use slab allocator to store event data. --- server/TracyEvent.hpp | 2 +- server/TracyView.cpp | 37 ++++++++++++++++++------------------- server/TracyView.hpp | 12 +++++++----- 3 files changed, 26 insertions(+), 25 deletions(-) diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index f325077a..a153a07e 100755 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -11,7 +11,7 @@ struct Event int64_t start; int64_t end; - std::vector child; + std::vector child; }; enum { EventSize = sizeof( Event ) }; diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 476f75e0..2a007b08 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -175,22 +175,23 @@ void View::Process( const QueueItem& ev ) void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev ) { auto it = m_pendingEndZone.find( id ); - const auto idx = m_data.size(); + auto zone = m_slab.Alloc(); CheckString( ev.filename ); CheckString( ev.function ); + zone->start = ev.time; std::unique_lock lock( m_lock ); if( it == m_pendingEndZone.end() ) { - m_data.emplace_back( Event { ev.time, -1 } ); - NewZone( idx ); + zone->end = -1; + NewZone( zone ); lock.unlock(); - m_openZones.emplace( id, idx ); + m_openZones.emplace( id, zone ); } else { assert( ev.time <= it->second.time ); - m_data.emplace_back( Event { ev.time, it->second.time } ); - NewZone( idx ); + zone->end = it->second.time; + NewZone( zone ); lock.unlock(); m_pendingEndZone.erase( it ); } @@ -205,11 +206,11 @@ void View::ProcessZoneEnd( uint64_t id, const QueueZoneEnd& ev ) } else { - const auto idx = it->second; + auto zone = it->second; std::unique_lock lock( m_lock ); - assert( ev.time >= m_data[idx].start ); - m_data[idx].end = ev.time; - UpdateZone( idx ); + assert( ev.time >= zone->start ); + zone->end = ev.time; + UpdateZone( zone ); lock.unlock(); m_openZones.erase( it ); } @@ -234,15 +235,14 @@ void View::AddString( uint64_t ptr, std::string&& str ) m_strings.emplace( ptr, std::move( str ) ); } -void View::NewZone( uint64_t idx ) +void View::NewZone( Event* zone ) { if( !m_timeline.empty() ) { - auto& zone = m_data[idx]; - const auto lastend = m_data[m_timeline.back()].end; - if( lastend != -1 && lastend < zone.start ) + const auto lastend = m_timeline.back()->end; + if( lastend != -1 && lastend < zone->start ) { - m_timeline.emplace_back( idx ); + m_timeline.emplace_back( zone ); } else { @@ -251,14 +251,13 @@ void View::NewZone( uint64_t idx ) } else { - m_timeline.emplace_back( idx ); + m_timeline.emplace_back( zone ); } } -void View::UpdateZone( uint64_t idx ) +void View::UpdateZone( Event* zone ) { - auto& zone = m_data[idx++]; - assert( zone.end != -1 ); + assert( zone->end != -1 ); } void View::Draw() diff --git a/server/TracyView.hpp b/server/TracyView.hpp index e4642073..7f914699 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -12,6 +12,7 @@ #include "../common/TracySocket.hpp" #include "../common/TracyQueue.hpp" #include "TracyEvent.hpp" +#include "TracySlab.hpp" namespace tracy { @@ -41,8 +42,8 @@ private: void CheckString( uint64_t ptr ); void AddString( uint64_t ptr, std::string&& str ); - void NewZone( uint64_t idx ); - void UpdateZone( uint64_t idx ); + void NewZone( Event* zone ); + void UpdateZone( Event* zone ); void DrawImpl(); @@ -57,14 +58,15 @@ private: // this block must be locked std::mutex m_lock; std::vector m_mbps; - std::vector m_data; - std::vector m_timeline; + std::vector m_timeline; std::unordered_map m_strings; // not used for vis - no need to lock std::unordered_map m_pendingEndZone; - std::unordered_map m_openZones; + std::unordered_map m_openZones; std::unordered_set m_pendingStrings; + + Slab m_slab; }; }