Skip to content

Commit 48fc01c

Browse files
committed
fix: react ui Timeline view may show large negative durations
This can happen when the trace prematurely exits, leaving `end_nanos: 0` for some blocks Signed-off-by: Nick Mitchell <[email protected]>
1 parent bf291dd commit 48fc01c

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pdl-live-react/src/view/timeline/Timeline.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,16 @@ type Props = {
1010
}
1111

1212
export default function Timeline({ block }: Props) {
13-
const [model, min, max] = useMemo(() => {
13+
const [model, minStart, maxEnd] = useMemo(() => {
1414
const model = computeModel(block)
15-
const [min, max] = model.reduce(
16-
([min, max], row) => [
17-
Math.min(min, row.block.start_nanos),
18-
Math.max(max, row.block.end_nanos),
15+
const [minStart, maxEnd] = model.reduce(
16+
([minStart, maxEnd], row) => [
17+
Math.min(minStart, row.block.start_nanos),
18+
Math.max(maxEnd, row.block.end_nanos),
1919
],
2020
[Number.MAX_VALUE, Number.MIN_VALUE],
2121
)
22-
return [model, min, max]
22+
return [model, minStart, maxEnd]
2323
}, [block])
2424

2525
const pushPops = useMemo(() => pushPopsFor(model), [model])
@@ -30,8 +30,8 @@ export default function Timeline({ block }: Props) {
3030
<TimelineRow
3131
key={idx}
3232
{...row}
33-
min={min}
34-
max={max}
33+
min={minStart}
34+
max={maxEnd}
3535
{...pushPops[idx]}
3636
/>
3737
))}

pdl-live-react/src/view/timeline/TimelineRow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export default function TimelineRow(row: Props) {
2121
</span>
2222

2323
<span className="pdl-timeline-cell pdl-duration" data-cell="duration">
24-
{prettyMs((row.block.end_nanos - row.block.start_nanos) / 1000000)}
24+
{prettyMs(
25+
((row.block.end_nanos || row.max) - row.block.start_nanos) / 1000000,
26+
)}
2527
</span>
2628
</div>
2729
)

0 commit comments

Comments
 (0)