diff --git a/server/TracyEvent.hpp b/server/TracyEvent.hpp index c7cee48a..2d411662 100755 --- a/server/TracyEvent.hpp +++ b/server/TracyEvent.hpp @@ -10,6 +10,7 @@ struct Event { int64_t start; int64_t end; + uint32_t srcloc; Vector child; }; diff --git a/server/TracySourceLocation.hpp b/server/TracySourceLocation.hpp new file mode 100755 index 00000000..a583b9fc --- /dev/null +++ b/server/TracySourceLocation.hpp @@ -0,0 +1,37 @@ +#ifndef __TRACYSOURCELOCATION_HPP__ +#define __TRACYSOURCELOCATION_HPP__ + +#include +#include +#include + +namespace tracy +{ + +struct SourceLocation +{ + uint64_t filename; + uint64_t function; + uint32_t line; + + struct Hasher + { + size_t operator()( const SourceLocation& v ) const + { + const static std::hash hash; + return hash( v.filename ) ^ hash( v.function ) ^ hash( v.line ); + } + }; + + struct Comparator + { + bool operator()( const SourceLocation& lhs, const SourceLocation& rhs ) const + { + return memcmp( &lhs, &rhs, sizeof( SourceLocation ) ) == 0; + } + }; +}; + +} + +#endif diff --git a/server/TracyView.cpp b/server/TracyView.cpp index 99e5ca9d..c8fea1c3 100755 --- a/server/TracyView.cpp +++ b/server/TracyView.cpp @@ -209,10 +209,27 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev ) { auto it = m_pendingEndZone.find( id ); auto zone = m_slab.Alloc(); + CheckString( ev.filename ); CheckString( ev.function ); zone->start = ev.time; + + SourceLocation srcloc { ev.filename, ev.function, ev.line }; + auto lit = m_locationRef.find( srcloc ); + std::unique_lock lock( m_lock ); + if( lit == m_locationRef.end() ) + { + const auto ref = uint32_t( m_srcFile.size() ); + zone->srcloc = ref; + m_locationRef.emplace( srcloc, ref ); + m_srcFile.push_back( srcloc ); + } + else + { + zone->srcloc = lit->second; + } + if( it == m_pendingEndZone.end() ) { zone->end = -1; diff --git a/server/TracyView.hpp b/server/TracyView.hpp index 22ad7cdd..395a6772 100755 --- a/server/TracyView.hpp +++ b/server/TracyView.hpp @@ -14,6 +14,7 @@ #include "../common/TracyQueue.hpp" #include "TracyEvent.hpp" #include "TracySlab.hpp" +#include "TracySourceLocation.hpp" #include "TracyVector.hpp" namespace tracy @@ -71,6 +72,7 @@ private: std::mutex m_lock; Vector m_timeline; Vector m_frames; + Vector m_srcFile; std::unordered_map m_strings; std::mutex m_mbpslock; @@ -80,6 +82,7 @@ private: std::unordered_map m_pendingEndZone; std::unordered_map m_openZones; std::unordered_set m_pendingStrings; + std::unordered_map m_locationRef; Slab m_slab;