modified the integrated profiler to hopefully produce more reliable results
This commit is contained in:
parent
1386592aab
commit
f75d11193a
2 changed files with 35 additions and 28 deletions
|
|
@ -1,7 +1,7 @@
|
|||
#
|
||||
#
|
||||
# Nim's Runtime Library
|
||||
# (c) Copyright 2012 Andreas Rumpf
|
||||
# (c) Copyright 2015 Andreas Rumpf
|
||||
#
|
||||
# See the file "copying.txt", included in this
|
||||
# distribution, for details about the copyright.
|
||||
|
|
@ -117,24 +117,38 @@ when defined(memProfiler):
|
|||
var
|
||||
gTicker {.threadvar.}: int
|
||||
|
||||
proc hook(st: StackTrace, size: int) {.nimcall.} =
|
||||
proc requestedHook(): bool {.nimcall.} =
|
||||
if gTicker == 0:
|
||||
gTicker = -1
|
||||
when defined(ignoreAllocationSize):
|
||||
hookAux(st, 1)
|
||||
else:
|
||||
hookAux(st, size)
|
||||
gTicker = SamplingInterval
|
||||
result = true
|
||||
dec gTicker
|
||||
|
||||
proc hook(st: StackTrace, size: int) {.nimcall.} =
|
||||
when defined(ignoreAllocationSize):
|
||||
hookAux(st, 1)
|
||||
else:
|
||||
hookAux(st, size)
|
||||
|
||||
else:
|
||||
var
|
||||
t0 {.threadvar.}: Ticks
|
||||
gTicker: int # we use an additional counter to
|
||||
# avoid calling 'getTicks' too frequently
|
||||
|
||||
proc requestedHook(): bool {.nimcall.} =
|
||||
if interval == 0: result = true
|
||||
elif gTicker == 0:
|
||||
gTicker = 500
|
||||
if getTicks() - t0 > interval:
|
||||
result = true
|
||||
else:
|
||||
dec gTicker
|
||||
|
||||
proc hook(st: StackTrace) {.nimcall.} =
|
||||
#echo "profiling! ", interval
|
||||
if interval == 0:
|
||||
hookAux(st, 1)
|
||||
elif int64(t0) == 0 or getTicks() - t0 > interval:
|
||||
else:
|
||||
hookAux(st, 1)
|
||||
t0 = getTicks()
|
||||
|
||||
|
|
@ -145,9 +159,10 @@ proc cmpEntries(a, b: ptr ProfileEntry): int =
|
|||
result = b.getTotal - a.getTotal
|
||||
|
||||
proc `//`(a, b: int): string =
|
||||
result = format("$1/$2 = $3%", a, b, formatFloat(a / b * 100.0, ffDefault, 2))
|
||||
result = format("$1/$2 = $3%", a, b, formatFloat(a / b * 100.0, ffDecimal, 2))
|
||||
|
||||
proc writeProfile() {.noconv.} =
|
||||
system.profilingRequestedHook = nil
|
||||
when declared(system.StackTrace):
|
||||
system.profilerHook = nil
|
||||
const filename = "profile_results.txt"
|
||||
|
|
@ -193,12 +208,12 @@ var
|
|||
proc disableProfiling*() =
|
||||
when declared(system.StackTrace):
|
||||
atomicDec disabled
|
||||
system.profilerHook = nil
|
||||
system.profilingRequestedHook = nil
|
||||
|
||||
proc enableProfiling*() =
|
||||
when declared(system.StackTrace):
|
||||
if atomicInc(disabled) >= 0:
|
||||
system.profilerHook = hook
|
||||
system.profilingRequestedHook = requestedHook
|
||||
|
||||
when declared(system.StackTrace):
|
||||
system.profilerHook = hook
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue