1
0
mirror of https://github.com/wolfpld/tracy synced 2025-04-29 12:23:53 +00:00

Store source locations in a proper data structure.

This commit is contained in:
Bartosz Taudul 2017-11-05 20:54:49 +01:00
parent bc77aa8d26
commit 3d2450fc10
4 changed files with 23 additions and 11 deletions

View File

@ -58,7 +58,7 @@ To begin data collection, tracy requires that you manually instrument your appli
To slice the program's execution recording into frame-sized chunks, put the `FrameMark` macro after you have completed rendering the frame. Ideally that would be right after the swap buffers command. Note that this step is optional, as some applications (for example: a compression utility) do not have the concept of a frame.
To record a zone's execution time add the `ZoneScoped` macro at the beginning of the scope you want to measure. This will automatically record function name, source file name and location. Optionally you may use the `ZoneScopedC( 0xBBGGRR )` macro to set a custom color for the zone. Note that the color value will be constant in the recording (don't try to parametrize it). After you have marked the zone, you may further parametrize it.
To record a zone's execution time add the `ZoneScoped` macro at the beginning of the scope you want to measure. This will automatically record function name, source file name and location. Optionally you may use the `ZoneScopedC( 0xRRGGBB )` macro to set a custom color for the zone. Note that the color value will be constant in the recording (don't try to parametrize it). After you have marked the zone, you may further parametrize it.
Use the `ZoneName( const char* name )` macro to set a custom name for the zone, which will be displayed instead of the function's name in the timeline view. The indented usage is to provide a string literal. (The text string that you provide **must** be accessible indefinitely at the given address. Tracy does not guarantee at which point in time it will be sent to the server and there is no notification when it happens.)

View File

@ -16,6 +16,17 @@ struct TextData
#pragma pack( 1 )
struct SourceLocation
{
uint64_t function; // ptr
uint64_t file; // ptr
uint32_t line;
uint32_t color;
};
enum { SourceLocationSize = sizeof( SourceLocation ) };
struct ZoneEvent
{
int64_t start;

View File

@ -252,7 +252,7 @@ View::View( FileRead& f )
{
uint64_t ptr;
f.Read( &ptr, sizeof( ptr ) );
QueueSourceLocation srcloc;
SourceLocation srcloc;
f.Read( &srcloc, sizeof( srcloc ) );
m_sourceLocation.emplace( ptr, srcloc );
}
@ -981,8 +981,9 @@ void View::AddSourceLocation( const QueueSourceLocation& srcloc )
m_pendingSourceLocation.erase( it );
CheckString( srcloc.file );
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, srcloc );
m_sourceLocation.emplace( srcloc.ptr, SourceLocation { srcloc.function, srcloc.file, srcloc.line, color } );
}
void View::AddSourceLocationPayload( uint64_t ptr, const char* data, size_t sz )
@ -1366,9 +1367,9 @@ const char* View::GetThreadString( uint64_t id ) const
}
}
const QueueSourceLocation& View::GetSourceLocation( uint32_t srcloc ) const
const SourceLocation& View::GetSourceLocation( uint32_t srcloc ) const
{
static const QueueSourceLocation empty = {};
static const SourceLocation empty = {};
const auto it = m_sourceLocation.find( m_sourceLocationExpand[srcloc] );
if( it == m_sourceLocation.end() ) return empty;
return it->second;
@ -2089,7 +2090,7 @@ int View::DrawZoneLevel( const Vector<ZoneEvent*>& vec, bool hover, double pxns,
++it;
if( it == zitend ) break;
auto& srcloc2 = GetSourceLocation( (*it)->srcloc );
if( srcloc.r != srcloc2.r || srcloc.g != srcloc2.g || srcloc.b != srcloc2.b ) break;
if( srcloc.color != srcloc2.color ) break;
const auto nend = GetZoneEnd( **it );
const auto pxnext = ( nend - m_zvStart ) * pxns;
if( pxnext - px1 >= MinVisSize * 2 ) break;
@ -3043,9 +3044,9 @@ uint32_t View::GetZoneColor( const ZoneEvent& ev )
return GetZoneColor( GetSourceLocation( ev.srcloc ) );
}
uint32_t View::GetZoneColor( const QueueSourceLocation& srcloc )
uint32_t View::GetZoneColor( const SourceLocation& srcloc )
{
const auto color = srcloc.r | ( srcloc.g << 8 ) | ( srcloc.b << 16 );
const auto color = srcloc.color;
return color != 0 ? ( color | 0xFF000000 ) : 0xFFCC5555;
}

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 QueueSourceLocation& GetSourceLocation( uint32_t srcloc ) const;
const SourceLocation& GetSourceLocation( uint32_t srcloc ) const;
const char* ShortenNamespace( const char* name ) const;
@ -196,7 +196,7 @@ private:
void HandleZoneViewMouse( int64_t timespan, const ImVec2& wpos, float w, double& pxns );
uint32_t GetZoneColor( const ZoneEvent& ev );
uint32_t GetZoneColor( const QueueSourceLocation& srcloc );
uint32_t GetZoneColor( const SourceLocation& srcloc );
uint32_t GetZoneHighlight( const ZoneEvent& ev, bool migration );
float GetZoneThickness( const ZoneEvent& ev );
@ -230,7 +230,7 @@ private:
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;
std::unordered_map<uint64_t, QueueSourceLocation> m_sourceLocation;
std::unordered_map<uint64_t, SourceLocation> m_sourceLocation;
std::vector<uint64_t> m_sourceLocationExpand;
std::map<uint32_t, LockMap> m_lockMap;
uint64_t m_zonesCnt;