Store zone source location.

This commit is contained in:
Bartosz Taudul 2017-09-21 21:57:40 +02:00
parent 7446e27e60
commit 5065743bf0
4 changed files with 58 additions and 0 deletions

View File

@ -10,6 +10,7 @@ struct Event
{
int64_t start;
int64_t end;
uint32_t srcloc;
Vector<Event*> child;
};

37
server/TracySourceLocation.hpp Executable file
View File

@ -0,0 +1,37 @@
#ifndef __TRACYSOURCELOCATION_HPP__
#define __TRACYSOURCELOCATION_HPP__
#include <functional>
#include <stdint.h>
#include <string.h>
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<uint64_t> 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

View File

@ -209,10 +209,27 @@ void View::ProcessZoneBegin( uint64_t id, const QueueZoneBegin& ev )
{
auto it = m_pendingEndZone.find( id );
auto zone = m_slab.Alloc<Event>();
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<std::mutex> 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;

View File

@ -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<Event*> m_timeline;
Vector<uint64_t> m_frames;
Vector<SourceLocation> m_srcFile;
std::unordered_map<uint64_t, std::string> m_strings;
std::mutex m_mbpslock;
@ -80,6 +82,7 @@ private:
std::unordered_map<uint64_t, QueueZoneEnd> m_pendingEndZone;
std::unordered_map<uint64_t, Event*> m_openZones;
std::unordered_set<uint64_t> m_pendingStrings;
std::unordered_map<SourceLocation, uint32_t, SourceLocation::Hasher, SourceLocation::Comparator> m_locationRef;
Slab<EventSize*1024*1024> m_slab;