Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/wolfpld/tracy.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/public
diff options
context:
space:
mode:
authorBartosz Taudul <wolf@nereid.pl>2022-08-18 14:59:56 +0300
committerBartosz Taudul <wolf@nereid.pl>2022-08-18 14:59:56 +0300
commit197007ab479d08087e8b4803f7eb21b4f5cf0f7b (patch)
tree29ea094e08f0718d5252ef81308f550d5e23db0e /public
parent940f32c1a892dd194c3c6d66bb3550149de919fc (diff)
Keep a list of buffers left to handle.
Previously a bitmap of buffers was repeatedly scanned to see which buffers still contain data. This process was needlessly wasting cycles (seen as a hotspot when profiled) and worse yet, the workload increased with the number of CPU cores (=> buffers used) to handle. The new implementation instead maintains a list of buffer indices that have to be handled. This list does not contain empty buffers, so each loop iteration performs some work, instead of just spinning in search for buffers to handle.
Diffstat (limited to 'public')
-rw-r--r--public/client/TracySysTrace.cpp27
1 files changed, 15 insertions, 12 deletions
diff --git a/public/client/TracySysTrace.cpp b/public/client/TracySysTrace.cpp
index 87fe2086..ee62547d 100644
--- a/public/client/TracySysTrace.cpp
+++ b/public/client/TracySysTrace.cpp
@@ -1285,7 +1285,7 @@ void SysTraceWorker( void* ptr )
const auto ctxBufNum = numBuffers - ctxBufferIdx;
int activeNum = 0;
- bool active[512];
+ uint16_t active[512];
uint32_t end[512];
uint32_t pos[512];
for( int i=0; i<ctxBufNum; i++ )
@@ -1295,9 +1295,9 @@ void SysTraceWorker( void* ptr )
const auto rbTail = ringArray[rbIdx].GetTail();
const auto rbActive = rbHead != rbTail;
- active[i] = rbActive;
if( rbActive )
{
+ active[activeNum] = (uint16_t)i;
activeNum++;
end[i] = rbHead - rbTail;
pos[i] = 0;
@@ -1313,13 +1313,14 @@ void SysTraceWorker( void* ptr )
while( activeNum > 0 )
{
int sel = -1;
+ int selPos;
int64_t t0 = std::numeric_limits<int64_t>::max();
- for( int i=0; i<ctxBufNum; i++ )
+ for( int i=0; i<activeNum; i++ )
{
- if( !active[i] ) continue;
- auto rbPos = pos[i];
- assert( rbPos < end[i] );
- const auto rbIdx = ctxBufferIdx + i;
+ auto idx = active[i];
+ auto rbPos = pos[idx];
+ assert( rbPos < end[idx] );
+ const auto rbIdx = ctxBufferIdx + idx;
perf_event_header hdr;
ringArray[rbIdx].Read( &hdr, rbPos, sizeof( perf_event_header ) );
if( hdr.type == PERF_RECORD_SAMPLE )
@@ -1329,20 +1330,22 @@ void SysTraceWorker( void* ptr )
if( rbTime < t0 )
{
t0 = rbTime;
- sel = i;
+ sel = idx;
+ selPos = i;
}
}
else
{
rbPos += hdr.size;
- if( rbPos == end[i] )
+ if( rbPos == end[idx] )
{
- active[i] = false;
+ memmove( active+i, active+i+1, sizeof(*active) * ( activeNum - i - 1 ) );
activeNum--;
+ i--;
}
else
{
- pos[i] = rbPos;
+ pos[idx] = rbPos;
}
}
}
@@ -1488,7 +1491,7 @@ void SysTraceWorker( void* ptr )
rbPos += hdr.size;
if( rbPos == end[sel] )
{
- active[sel] = false;
+ memmove( active+selPos, active+selPos+1, sizeof(*active) * ( activeNum - selPos - 1 ) );
activeNum--;
}
else