Skip to content

Commit fcbe7a0

Browse files
committed
fix(skills): improve task dump recipe with idle period correlation
1 parent 3c066cf commit fcbe7a0

1 file changed

Lines changed: 20 additions & 3 deletions

File tree

  • dial9-viewer/skills/dial9-trace-recipes

dial9-viewer/skills/dial9-trace-recipes/SKILL.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,15 +366,32 @@ Task dumps capture async backtraces at yield points. Use them to see what future
366366
367367
```javascript
368368
const { parseTrace, symbolizeChain, formatFrame } = require('./trace_parser.js');
369+
const { buildWorkerSpans } = require('./trace_analysis.js');
369370

370371
for await (const trace of parseTrace('/path/to/traces/')) {
372+
const workerIds = [...new Set(trace.events.filter(e => e.workerId !== undefined).map(e => e.workerId))].sort((a,b)=>a-b);
373+
const spans = buildWorkerSpans(trace.events, workerIds, trace.maxTs);
374+
371375
for (const [taskId, dumps] of trace.taskDumps) {
376+
const taskPolls = [];
377+
for (const w of workerIds) {
378+
for (const p of spans.workerSpans[w].polls) {
379+
if (p.taskId === taskId) taskPolls.push(p);
380+
}
381+
}
382+
taskPolls.sort((a, b) => a.start - b.start);
383+
372384
const loc = trace.taskSpawnLocs?.get(taskId) || '(unknown)';
373-
console.log(`Task ${taskId} (${loc}): ${dumps.length} task dumps`);
374385
for (const dump of dumps) {
386+
// dump.timestamp matches the pollStart of the following poll;
387+
// the idle period is the gap between the preceding poll's end and this timestamp
388+
const pollIdx = taskPolls.findIndex(p => p.start === dump.timestamp);
389+
const idleStart = pollIdx > 0 ? taskPolls[pollIdx - 1].end : trace.minTs;
390+
const idleDur = (dump.timestamp - idleStart) / 1e6;
391+
375392
const frames = symbolizeChain(dump.callchain, trace.callframeSymbols);
376-
const readable = frames.map(f => formatFrame(f).text).join('\n ');
377-
console.log(` at +${((dump.timestamp - trace.minTs) / 1e6).toFixed(1)}ms:\n ${readable}`);
393+
const leaf = frames[0] ? formatFrame(frames[0]).text : '(unknown)';
394+
console.log(`Task ${taskId} (${loc}) idle ${idleDur.toFixed(1)}ms awaiting: ${leaf}`);
378395
}
379396
}
380397
}

0 commit comments

Comments
 (0)