From 8cc15b79d1da03fc1b295eca3e932f7a0b3ec48d Mon Sep 17 00:00:00 2001 From: Martin Ridgers Date: Tue, 26 Nov 2024 09:39:29 +0100 Subject: Flush CPU scope trace buffers when scope depth reaches zero (#235) --- thirdparty/trace/trace.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/thirdparty/trace/trace.h b/thirdparty/trace/trace.h index 612173ce1..28fe6a66e 100644 --- a/thirdparty/trace/trace.h +++ b/thirdparty/trace/trace.h @@ -5879,6 +5879,7 @@ private: uint64 PrevTimestamp = 0; uint8* Cursor = Buffer; uint32 ThreadIdOverride = 0; + uint16 Depth = 0; uint8 Buffer[BufferSize]; }; @@ -5890,7 +5891,7 @@ void ScopeBuffer::Flush(bool Force) if (Cursor == Buffer) return; - if (!Force && (Cursor <= (Buffer + BufferSize - Overflow))) + if (Depth > 0 && !Force && (Cursor <= (Buffer + BufferSize - Overflow))) return; if (ThreadIdOverride) @@ -5911,6 +5912,7 @@ void ScopeBuffer::Enter(uint64 Timestamp, uint32 ScopeId, int32 Flags) PrevTimestamp += Timestamp; Cursor += encode64_7bit((Timestamp) << 1 | EnterLsb, Cursor); Cursor += encode32_7bit(ScopeId, Cursor); + Depth++; bool ShouldFlush = (Flags & CpuScopeFlags::CpuFlush); Flush(ShouldFlush); @@ -5922,6 +5924,7 @@ void ScopeBuffer::Leave(uint64 Timestamp) Timestamp -= PrevTimestamp; PrevTimestamp += Timestamp; Cursor += encode64_7bit((Timestamp << 1) | LeaveLsb, Cursor); + Depth--; Flush(false); } -- cgit v1.2.3