From 128531cd830feb1473286654b4d975c5dc36d824 Mon Sep 17 00:00:00 2001 From: gmega Date: Mon, 27 Nov 2023 18:08:08 -0300 Subject: [PATCH] add accessor to exec time + children, type aliases, minor refactor --- chronos.nimble | 2 +- chronos/profiler/metrics.nim | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/chronos.nimble b/chronos.nimble index fd83e7f..a68190c 100644 --- a/chronos.nimble +++ b/chronos.nimble @@ -51,7 +51,7 @@ task test_libbacktrace, "test with libbacktrace": task test_profiler, "test with profiler instrumentation": var allArgs = @[ - "-d:release -d:chronosProfiling", + "-d:release -d:chronosFutureId -d:chronosProfiling", ] for args in allArgs: diff --git a/chronos/profiler/metrics.nim b/chronos/profiler/metrics.nim index aedb33f..38f5276 100644 --- a/chronos/profiler/metrics.nim +++ b/chronos/profiler/metrics.nim @@ -25,10 +25,15 @@ type parent*: Option[uint] pauses*: uint + MetricsTotals* = Table[SrcLoc, AggregateFutureMetrics] + ProfilerMetrics* = object - running: seq[uint] + callStack: seq[uint] partials: Table[uint, RunningFuture] - totals*: Table[SrcLoc, AggregateFutureMetrics] + totals*: MetricsTotals + +proc `execTimeWithChildren`*(self: AggregateFutureMetrics): Duration = + self.execTime + self.childrenExecTime proc push(self: var seq[uint], value: uint): void = self.add(value) @@ -49,7 +54,7 @@ proc futureCreated(self: var ProfilerMetrics, event: Event): void = ) proc bindParent(self: var ProfilerMetrics, metrics: ptr RunningFuture): void = - let current = self.running.peek() + let current = self.callStack.peek() if current.isNone: return @@ -64,14 +69,14 @@ proc futureRunning(self: var ProfilerMetrics, event: Event): void = assert metrics.state == Pending or metrics.state == Paused self.bindParent(metrics) - self.running.push(event.futureId) + self.callStack.push(event.futureId) metrics.lastStarted = event.timestamp metrics.state = Running proc futurePaused(self: var ProfilerMetrics, event: Event): void = assert self.partials.hasKey(event.futureId) - assert event.futureId == self.running.pop() + assert event.futureId == self.callStack.pop() self.partials.withValue(event.futureId, metrics): assert metrics.state == Running