Commit 8778ff4
Emit real elapsed time from SlowOperation telemetry (single event)
Follow-up to #40269, which introduced SlowOperationWatcher. As noted in that PR's
review, when the threshold timer fires we learn only that an operation was slow,
not *how* slow -- it could have finished at 10.1 s or still be stuck at 60 s -- and
"logging the elapsed time at scope exit could be the most useful" follow-up. This
adds that, while keeping the watcher a passive, telemetry-only observer that emits
**at most one** event.
Behavior (exactly one of):
- Fast path: the operation finishes under SlowThreshold (10 s default) -- the common
case. Nothing is emitted.
- Slow completion: it finishes but took >= SlowThreshold. On scope exit (destructor /
Reset()) one `timedOut=false` SlowOperation event is emitted with the real
`elapsedMs` since construction -- the authoritative total duration.
- Hang backstop: it is still running at MaxDuration (15 min default). A single-shot
timer fires once and emits one `timedOut=true` event (elapsedMs ~= MaxDuration),
then stops -- so an operation that never returns (e.g. an HCS wait that blocks
INFINITE, where the destructor never runs) is still reported exactly once instead
of being invisible. It never repeats.
So SlowThreshold is the "slow enough to report at completion" filter and MaxDuration
is the "give up waiting and report the hang, once" deadline. m_reported (atomic)
guarantees at most one event across the timer callback, Reset(), and the destructor.
The event schema gains `elapsedMs` (Int64) and `completed` (Boolean); the existing
`name`, `thresholdMs`, `file`, `function`, `line` fields are unchanged (additive,
backward compatible).
Compatibility / safety:
- The two new constructor parameters (MaxDuration, OnSlow) are defaulted, so every
existing call site compiles and behaves identically; the fast path emits nothing.
- Only WSL_LOG_TELEMETRY is emitted (which also lands in ETL) -- no second log.
- The threadpool callback dereferences the watcher, but Finish() resets the timer
(cancel + drain in-flight callback) before any member is destroyed, so there is no
use-after-free. The emission path is fully noexcept + CATCH_LOG guarded, so a
telemetry failure can never crash or alter the watched operation.
- No call sites are added or moved; the change is confined to the watcher class.
Tests: adds test/windows/SlowOperationWatcherUnitTests.cpp (TAEF) covering the fast
path, default-constructed fast path, slow completion (one completed=true with real
elapsed), Reset() at-most-once, and the hang backstop (one completed=false at max,
no second event on scope exit) -- via an injected recording sink.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 8f7fab85-2f28-4344-9454-b76e8d2cc4d41 parent 0fe081b commit 8778ff4
4 files changed
Lines changed: 477 additions & 38 deletions
File tree
- src/windows/common
- test/windows
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
17 | 28 | | |
18 | 29 | | |
19 | 30 | | |
| |||
44 | 55 | | |
45 | 56 | | |
46 | 57 | | |
47 | | - | |
48 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
49 | 73 | | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
50 | 86 | | |
51 | | - | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
52 | 96 | | |
53 | | - | |
54 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
55 | 100 | | |
56 | 101 | | |
57 | 102 | | |
58 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
59 | 111 | | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
60 | 139 | | |
61 | 140 | | |
62 | 141 | | |
63 | 142 | | |
64 | 143 | | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
65 | 147 | | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
66 | 154 | | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
67 | 158 | | |
68 | 159 | | |
69 | 160 | | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
75 | 168 | | |
76 | 169 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
12 | | - | |
13 | | - | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
19 | 41 | | |
20 | 42 | | |
21 | 43 | | |
| |||
37 | 59 | | |
38 | 60 | | |
39 | 61 | | |
| 62 | + | |
40 | 63 | | |
41 | 64 | | |
42 | 65 | | |
43 | 66 | | |
44 | 67 | | |
45 | 68 | | |
46 | | - | |
47 | | - | |
48 | | - | |
49 | | - | |
50 | | - | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
51 | 104 | | |
52 | 105 | | |
53 | 106 | | |
54 | | - | |
55 | | - | |
56 | | - | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
57 | 112 | | |
58 | 113 | | |
59 | 114 | | |
60 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
61 | 118 | | |
62 | | - | |
63 | | - | |
64 | | - | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
65 | 124 | | |
66 | 125 | | |
67 | 126 | | |
| |||
70 | 129 | | |
71 | 130 | | |
72 | 131 | | |
73 | | - | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
74 | 140 | | |
75 | 141 | | |
76 | 142 | | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
77 | 153 | | |
78 | | - | |
| 154 | + | |
| 155 | + | |
79 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
80 | 160 | | |
81 | 161 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
0 commit comments