Store source location payloads.

No saving yet. No detection of duplicate entries.
This commit is contained in:
Bartosz Taudul 2017-11-05 21:24:50 +01:00
parent 4aa93f6285
commit c6a7bcb086
3 changed files with 45 additions and 14 deletions

View File

@ -21,7 +21,8 @@ struct SourceLocation
uint64_t function; // ptr
uint64_t file; // ptr
uint32_t line;
uint32_t color;
uint32_t color : 31;
uint32_t stringsAllocated : 1;
};
enum { SourceLocationSize = sizeof( SourceLocation ) };
@ -31,7 +32,7 @@ struct ZoneEvent
{
int64_t start;
int64_t end;
uint32_t srcloc;
int32_t srcloc;
int8_t cpu_start;
int8_t cpu_end;
@ -52,7 +53,7 @@ struct LockEvent
};
int64_t time;
uint32_t srcloc;
int32_t srcloc;
uint64_t waitList;
uint16_t thread : 6;
uint16_t lockingThread : 6;

View File

@ -983,7 +983,7 @@ void View::AddSourceLocation( const QueueSourceLocation& srcloc )
CheckString( srcloc.function );
uint32_t color = ( srcloc.r << 16 ) | ( srcloc.g << 8 ) | srcloc.b;
std::lock_guard<std::mutex> lock( m_lock );
m_sourceLocation.emplace( srcloc.ptr, SourceLocation { srcloc.function, srcloc.file, srcloc.line, color } );
m_sourceLocation.emplace( srcloc.ptr, SourceLocation { srcloc.function, srcloc.file, srcloc.line, color, 0 } );
}
void View::AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz )
@ -1007,10 +1007,18 @@ void View::AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz )
memcpy( source, end, ssz );
source[ssz] = '\0';
std::unique_lock<std::mutex> lock( m_lock );
auto srcloc = m_slab.Alloc<SourceLocation>();
srcloc->function = (uint64_t)func;
srcloc->file = (uint64_t)source;
srcloc->line = line;
srcloc->color = color;
srcloc->stringsAllocated = 1;
std::unique_lock<std::mutex> lock( m_lock );
pit->second->srcloc = -int32_t( m_sourceLocationPayload.size() + 1 );
m_sourceLocationPayload.push_back( srcloc );
lock.unlock();
m_pendingSourceLocationPayload.erase( ptr );
m_pendingSourceLocationPayload.erase( pit );
}
void View::AddMessageData( uint64_t ptr, const char* str, size_t sz )
@ -1367,12 +1375,19 @@ const char* View::GetThreadString( uint64_t id ) const
}
}
const SourceLocation& View::GetSourceLocation( uint32_t srcloc ) const
const SourceLocation& View::GetSourceLocation( int32_t srcloc ) const
{
static const SourceLocation empty = {};
const auto it = m_sourceLocation.find( m_sourceLocationExpand[srcloc] );
if( it == m_sourceLocation.end() ) return empty;
return it->second;
if( srcloc < 0 )
{
return *m_sourceLocationPayload[-srcloc-1];
}
else
{
static const SourceLocation empty = {};
const auto it = m_sourceLocation.find( m_sourceLocationExpand[srcloc] );
if( it == m_sourceLocation.end() ) return empty;
return it->second;
}
}
const char* View::ShortenNamespace( const char* name ) const
@ -3041,12 +3056,26 @@ void View::DrawMessages()
const char* View::GetSrcLocFunction( const SourceLocation& srcloc )
{
return GetString( srcloc.function );
if( srcloc.stringsAllocated )
{
return (const char*)srcloc.function;
}
else
{
return GetString( srcloc.function );
}
}
const char* View::GetSrcLocFile( const SourceLocation& srcloc )
{
return GetString( srcloc.file );
if( srcloc.stringsAllocated )
{
return (const char*)srcloc.file;
}
else
{
return GetString( srcloc.file );
}
}
uint32_t View::GetZoneColor( const ZoneEvent& ev )

View File

@ -176,7 +176,7 @@ private:
int64_t GetZoneEnd( const ZoneEvent& ev ) const;
const char* GetString( uint64_t ptr ) const;
const char* GetThreadString( uint64_t id ) const;
const SourceLocation& GetSourceLocation( uint32_t srcloc ) const;
const SourceLocation& GetSourceLocation( int32_t srcloc ) const;
const char* ShortenNamespace( const char* name ) const;
@ -230,6 +230,7 @@ private:
Vector<PlotData*> m_plots;
Vector<MessageData*> m_messages;
Vector<TextData*> m_textData;
Vector<SourceLocation*> m_sourceLocationPayload;
std::unordered_map<uint64_t, std::string> m_strings;
std::unordered_map<uint64_t, std::string> m_threadNames;
std::unordered_set<const char*, charutil::Hasher, charutil::Comparator> m_customStrings;