mirror of
https://github.com/logos-storage/nim-chronos.git
synced 2026-01-26 01:03:16 +00:00
add accessor to exec time + children, type aliases, minor refactor
This commit is contained in:
parent
d80fa15233
commit
128531cd83
@ -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:
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user