Prevent source location payload duplication.

This commit is contained in:
Bartosz Taudul 2017-11-11 02:31:51 +01:00
parent 24084cbcd2
commit ca4483ecf5
4 changed files with 53 additions and 12 deletions

View File

@ -23,6 +23,21 @@ static inline uint32_t hash( const char* str )
return hash;
}
static inline uint32_t hash( const char* str, size_t sz )
{
uint32_t hash = 5381;
int c;
while( sz > 0 )
{
c = *str++;
hash = ( ( hash << 5 ) + hash ) ^ c;
sz--;
}
return hash;
}
struct Hasher
{
size_t operator()( const char* key ) const

View File

@ -20,7 +20,7 @@ struct StringRef
{
if( isidx )
{
stridx = (uint32_t)data;
stridx = data;
}
else
{
@ -31,7 +31,7 @@ struct StringRef
union
{
uint64_t strptr;
uint32_t stridx;
uint64_t stridx;
};
bool isidx;
};

View File

@ -952,16 +952,24 @@ void View::AddSourceLocationPayload( uint64_t ptr, char* data, size_t sz )
const auto ssz = sz - ( end - start );
const auto source = StoreString( end, ssz );
auto srcloc = m_slab.Alloc<SourceLocation>();
srcloc->function = StringRef( StringRef::Idx, func.idx );
srcloc->file = StringRef( StringRef::Idx, source.idx );
srcloc->line = line;
srcloc->color = color;
SourceLocation srcloc { StringRef( StringRef::Idx, func.idx ), StringRef( StringRef::Idx, source.idx ), line, color };
auto it = m_sourceLocationPayloadMap.find( &srcloc );
if( it == m_sourceLocationPayloadMap.end() )
{
auto slptr = m_slab.Alloc<SourceLocation>();
memcpy( slptr, &srcloc, sizeof( srcloc ) );
uint32_t idx = m_sourceLocationPayload.size();
m_sourceLocationPayloadMap.emplace( slptr, idx );
std::unique_lock<std::mutex> lock( m_lock );
m_sourceLocationPayload.push_back( slptr );
pit->second->srcloc = -int32_t( idx + 1 );
}
else
{
std::unique_lock<std::mutex> lock( m_lock );
pit->second->srcloc = -int32_t( it->second + 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( pit );
}

View File

@ -109,6 +109,22 @@ private:
uint32_t idx;
};
struct SourceLocationHasher
{
size_t operator()( const SourceLocation* ptr ) const
{
return charutil::hash( (const char*)ptr, sizeof( SourceLocation ) );
}
};
struct SourceLocationComparator
{
bool operator()( const SourceLocation* lhs, const SourceLocation* rhs ) const
{
return memcmp( lhs, rhs, sizeof( SourceLocation ) ) == 0;
}
};
void Worker();
void DispatchProcess( const QueueItem& ev, char*& ptr );
@ -223,7 +239,6 @@ private:
Vector<PlotData*> m_plots;
Vector<MessageData*> m_messages;
Vector<TextData*> m_textData;
Vector<SourceLocation*> m_sourceLocationPayload;
std::unordered_map<uint64_t, const char*> m_strings;
std::unordered_map<uint64_t, const char*> m_threadNames;
std::unordered_map<uint64_t, SourceLocation> m_sourceLocation;
@ -234,6 +249,9 @@ private:
Vector<const char*> m_stringData;
std::unordered_map<const char*, uint32_t, charutil::Hasher, charutil::Comparator> m_stringMap;
Vector<SourceLocation*> m_sourceLocationPayload;
std::unordered_map<SourceLocation*, uint32_t, SourceLocationHasher, SourceLocationComparator> m_sourceLocationPayloadMap;
std::mutex m_mbpslock;
std::vector<float> m_mbps;