Commit Graph

283 Commits

Author SHA1 Message Date
Bartosz Taudul
e0862e8534 Disallow implicit StringIdx construction. 2026-07-28 22:33:26 +02:00
Bartosz Taudul
b68fe43335 Keep context switch sample vectors sorted.
Context switch samples were appended in arrival order. Samples which
were postponed due to missing context switch data are replayed after
newer samples were already classified, so the vector could become
unordered. Everything that reads it assumes time order: the wait stacks
range filter, the sampling statistics percentage denominator, and the
context switch sample filters in the trace load jobs. In the load jobs
an unordered vector could silently disable the filtering for the rest
of a thread, reintroducing the context switch samples into the symbol
and child sample maps.

Use a SortedVector and restore the ordering at the points where it can
break: after the postponed sample replay and when saving a trace. The
save file version is bumped, so that the sort order check on load is
only performed for traces saved by previous versions.
2026-07-25 23:02:13 +02:00
Bartosz Taudul
c880163f96 Sort child sample vectors lazily.
During live capture, child samples were appended to their per-address
vectors in arrival order. Samples postponed due to missing context
switch data are replayed after newer samples were already processed, so
the vectors could become unordered. All range-limited queries binary
search these vectors by time and would silently return wrong results.
Inserting in sorted order at collection time would require a mid-vector
insertion for every stack frame of every replayed sample, so instead
the vectors are now SortedVector and are sorted lazily when accessed,
following what the inline symbol list already does. This also restores
proper query results for traces with inconsistent sample order.
2026-07-25 19:46:01 +02:00
Bartosz Taudul
1dfcacd802 Collect entry stacks for "was this symbol reached" statistics.
SymbolStats now has two additional entry stack maps, which record the
call stacks below every occurrence of a symbol in a sample, not only
when the symbol was at the top of the stack:

- wasReached counts each occurrence separately. If a symbol re-enters
  itself through recursion, every re-entry adds an entry stack, which
  will itself contain the symbol somewhere below.
- wasReachedNonReentrant counts only the outermost occurrence, so each
  sample contributes exactly once and recursion is ignored. The sum of
  counts in this map equals the symbol's inclusive sample count.

To achieve this, the call stack is walked bottom-up, which makes the
first encountered occurrence of a symbol the outermost one. Symbols at
inline positions get the remaining inline frames of their frame group
as a synthetic frame, mirroring what was already done for the top of
the stack.

The wasExecuting and wasExecutingBase maps are now filled by the same
walk, as its topmost-frame special case. The keys they receive are
identical to what the previous code produced.

Note that there is no "base" variant of the reached maps. A base symbol
is present as the last frame of every frame group that contains its
inline functions, so its wasReached map already covers the whole symbol
at base granularity. Merging in the inline symbols' maps, as done for
wasExecutingBase, would only multi-count the same samples.
2026-07-25 17:02:42 +02:00
Bartosz Taudul
0b2e7dd13c Add StringIdx equality comparison operator. 2026-07-18 12:20:32 +02:00
Bartosz Taudul
50c3c89c16 Rename parents / baseParents maps to wasExecuting / wasExecutingBase.
The current "parents" mode of operation is "was this symbol executing".
The new name for the maps reflects that.

There should also be "was this symbol reached" (both recursive and non-
reentrant) modes.
2026-07-12 16:38:42 +02:00
Bartosz Taudul
1706ac57ac Separate id field is not needed. 2026-06-19 20:37:49 +02:00
Bartosz Taudul
274e453bb6 Process section enter / leave events. 2026-06-17 22:37:31 +02:00
Bartosz Taudul
801a34ea66 Add trigger parameter. 2026-06-17 22:37:31 +02:00
Bartosz Taudul
ec1c2d4267 Display aggregation counts in bottom / up sample trees. 2026-05-24 14:23:59 +02:00
Bartosz Taudul
60247b68d3 Merge pull request #1364 from siliceum/fix/zone-runtime
Fix and refactor zone running time
2026-05-20 19:29:29 +02:00
Clément Grégoire
91c0b1e42b Fix and refactor zone running time
Many of the zones would have a negative running time due to a missing `cs->IsEndValid()` check.
This could end reporting context switches before the zone start, due to `cs->End()` returning -1.

This happened when systrace dropped event, or when using Fibers and `TracyFiberEnter` is called on the new thread once the fiber has been scheduled. (The manual actually does not really hint this is wrong, we should probably fix the manual or the server code.)

In both cases, we assume runtime to be 0 for that context switch. Since we have no actual information. Both options (counting full runtime or no runtime) are wrong, and most of the code handling `!cs->IsEndValid()` uses `Start` instead so that's what I did. This is still a net improvement over displaying negative values. If we want to change this handling, we'd need to review the other places that do `it->IsEndValid() ? it->End() : it->Start()` as well.

It also seems two different concepts were being mixed:
1. Do we have any context switch data at all ? (`it != ctx->v.end()` ie `count != 0`)
2. Do we have complete data for the last context switch (`eit != ctx->v.end()`)

This led to some places of the code not displaying or counting running time at all, notably when hovering a zone.

I think most of the time we wanted 1, as it reports correctly and assumes the last context switch is still running, which is a fair assumption if we didn't see one putting the thread to sleep.

I also fixed a case where we were overcounting runtime when range start was during a sleep.
2026-05-20 12:02:38 +02:00
Bartosz Taudul
b90e44a5f1 Add raw data accessor to StringIdx. 2026-05-14 19:33:21 +02:00
Bartosz Taudul
73694c7a24 Cleanup enums. 2026-01-24 01:50:11 +01:00
Clément Grégoire
1e61dc88de Add source and severity to the server's MessageData + bump minor version for serialization
Note this does not change `sizeof(MessageData)` as there were 5 bytes left due to alignment. (now 3)
2025-12-28 14:50:38 +01:00
Eric Eaton
9caa91f06f Move the annotations data to the GPU context 2025-07-16 16:02:54 -07:00
Eric Eaton
3fce5c1280 Use a map to record counter values
This removes the limitation of 10 counters.
2025-07-11 17:17:05 -07:00
Eric Eaton
a754db16f8 Show counter name in GUI 2025-07-11 17:16:00 -07:00
Eric Eaton
2e49bdf4cb Add counter value collection 2025-07-11 17:16:00 -07:00
Clément Grégoire
296a3bb590 Add a comment about where to find KWAIT_REASON 2025-04-09 17:15:31 +02:00
Clément Grégoire
31859042bd Remove ContextSwitchData SetStartCpu and SetEndReasonState 2025-04-09 17:02:51 +02:00
Clément Grégoire
6486d8147d Fix formating issues 2025-04-08 13:48:50 +02:00
Clément Grégoire
df76b376a7 Thread wakeup visualization
This PR does the following things:
- Allow to lock the highlighted thread using left mouse click or lane popup menu
- Add more descriptions for wait reasons in View::DecodeContextSwitchReason
- Stores the Wakeup CPU so that we may display it in the CPU data view
- `QueueThreadWakeup` now contains cpu and adjust info (currently unused). Fits in the padding, no struct size change.
- `QueueContextSwitch` now also contains thread priorities information (windows+linux) and CState (windows), but currently unused by the profiler. Fits in the padding, no struct size change.
- Fixes Linux `EventWakeup` which tries to remove PERF_SAMPLE_CALLCHAIN on the wrong member. Set the whole `perf_event_attr` explicitely instead.
- Fixes Windows ReadyThread event being dropped if triggered before the thread switches out (this is confirmed to be normal behaviour, probably due to thread being switched out but context switch actually happening later)
- Bumps tracy file version and protocol versions
2025-04-08 11:02:27 +02:00
Bartosz Taudul
84718101fe Use proper name for inline frames in flame graph. 2024-10-27 19:44:40 +01:00
Bartosz Taudul
9d2f874b02 Calculate flame graph begin times. 2024-10-27 11:58:23 +01:00
Bartosz Taudul
346d8a45c6 Cache flame graph. 2024-09-29 00:26:00 +02:00
Bartosz Taudul
717605065a Mark comparators const. 2024-09-26 14:04:20 +02:00
Bartosz Taudul
28a9750f8a Process thread group hints. 2024-08-03 20:10:36 +02:00
Bartosz Taudul
7d69103444 Add plot type "power" and Watt format.
Note that this technically breaks backwards compatibility of trace files
for 0.9.2 builds. But, whatever, as it's not yet released.
2023-03-10 01:25:41 +01:00
Bartosz Taudul
23705fd84c Add a reminder to keep interfaces in sync. 2023-03-10 01:07:06 +01:00
Bartosz Taudul
b481bb367c Switch plot drawing to the timeline items system. 2022-09-03 17:51:33 +02:00
Daniel
dc74b8adfd Using push/pop in all pragma pack pair to avoid potential padding bugs 2022-08-03 18:39:42 +08:00
Bartosz Taudul
b026e09a09 Include custom color in plot configuration. 2022-07-24 13:42:25 +02:00
Bartosz Taudul
b2a94cbfa2 Set plot fill using configuration message. 2022-07-24 13:10:20 +02:00
Bartosz Taudul
16627d7313 Plots may now be drawn as staircases. 2022-07-24 12:37:30 +02:00
Bartosz Taudul
efaf1df8d4 Move LockMap and LockHighlight definitions. 2022-07-23 15:54:48 +02:00
Bartosz Taudul
4d40a9cb53 Track locking thread on server side. 2022-07-18 02:06:19 +02:00
Bartosz Taudul
06c7984a16 Move all client headers and sources to public/ directory. 2022-07-17 15:47:38 +02:00
Bartosz Taudul
d8a611e952 Also calculate sample parents without inlines. 2021-11-27 17:47:09 +01:00
Bartosz Taudul
a02575322f Collect child sample addresses. 2021-11-27 02:03:59 +01:00
Bartosz Taudul
710a488af0 Handle postponed samples with SortedVector. 2021-11-14 23:48:50 +01:00
Bartosz Taudul
ffa8bf4d75 Use table instead of map to track reentrant calls. 2021-11-14 16:42:11 +01:00
Bartosz Taudul
1d7ab70199 Non-memory tree callstacks are not needed. 2021-11-13 22:09:16 +01:00
Bartosz Taudul
4f6e9bbb65 Generic callstack tree builder.
Previously this was exclusive for memory callstacks.
2021-11-13 22:06:04 +01:00
Bartosz Taudul
a2547ccf1d Rename CallstackFrameTree -> MemCallstackFrameTree. 2021-11-13 21:26:28 +01:00
Bartosz Taudul
745b795d50 Detect context switch callstack samples.
Context switch callstack samples are not included in the sampling data
statistics (as these don't represent random sampling), but are rather put into
a separate dedicated data structure.

For this to work, a complete context switch data has to be available for the
callstack timestamp. There is no guarantee it will be present at the time it
is needed, so a second structure is added to allow postponing qualification of
callstacks.
2021-11-13 02:40:32 +01:00
Bartosz Taudul
69e5cf796d Construct faux context switch data from fiber events. 2021-11-06 20:38:16 +01:00
Bartosz Taudul
3ede2a1345 Explicit tracking of fiber state in ThreadData.
This replaces the use of hard-to-track global state with well-defined accessor
functionality.
2021-11-06 18:55:29 +01:00
Bartosz Taudul
8f44f1c68b Store fiber state is ThreadData. 2021-11-02 01:45:01 +01:00
Bartosz Taudul
0bd1364c2f Calculate plot values sum. 2021-10-17 13:04:56 +02:00