From 1d5d02cfa41e22d3beebff287c89d5b5422147c9 Mon Sep 17 00:00:00 2001 From: gmega Date: Tue, 28 Nov 2023 09:17:58 -0300 Subject: [PATCH] add location info to assertions to make them easier to trace --- chronos/profiler/metrics.nim | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/chronos/profiler/metrics.nim b/chronos/profiler/metrics.nim index 38f5276..4c22bd1 100644 --- a/chronos/profiler/metrics.nim +++ b/chronos/profiler/metrics.nim @@ -45,8 +45,11 @@ proc pop(self: var seq[uint]): uint = proc peek(self: var seq[uint]): Option[uint] = if self.len == 0: none(uint) else: self[^1].some +proc `$`(location: SrcLoc): string = + $location.procedure & "[" & $location.file & ":" & $location.line & "]" + proc futureCreated(self: var ProfilerMetrics, event: Event): void = - assert not self.partials.hasKey(event.futureId) + assert not self.partials.hasKey(event.futureId), $event.location self.partials[event.futureId] = RunningFuture( created: event.timestamp, @@ -63,10 +66,11 @@ proc bindParent(self: var ProfilerMetrics, metrics: ptr RunningFuture): void = metrics.parent = current proc futureRunning(self: var ProfilerMetrics, event: Event): void = - assert self.partials.hasKey(event.futureId) + assert self.partials.hasKey(event.futureId), $event.location self.partials.withValue(event.futureId, metrics): - assert metrics.state == Pending or metrics.state == Paused + assert metrics.state == Pending or metrics.state == Paused, + $event.location self.bindParent(metrics) self.callStack.push(event.futureId) @@ -75,11 +79,11 @@ proc futureRunning(self: var ProfilerMetrics, event: Event): void = metrics.state = Running proc futurePaused(self: var ProfilerMetrics, event: Event): void = - assert self.partials.hasKey(event.futureId) - assert event.futureId == self.callStack.pop() + assert self.partials.hasKey(event.futureId), $event.location + assert event.futureId == self.callStack.pop(), $event.location self.partials.withValue(event.futureId, metrics): - assert metrics.state == Running + assert metrics.state == Running, $event.location let segmentExecTime = event.timestamp - metrics.lastStarted