profiler documentation
This commit is contained in:
parent
04e4aa328b
commit
ad6ee9e857
6 changed files with 191 additions and 9 deletions
|
|
@ -87,6 +87,9 @@ proc getTotal(x: ref TProfileEntry): int =
|
|||
proc cmpEntries(a, b: ref TProfileEntry): 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))
|
||||
|
||||
proc writeProfile() {.noconv.} =
|
||||
stopProfiling()
|
||||
const filename = "profile_results"
|
||||
|
|
@ -110,8 +113,8 @@ proc writeProfile() {.noconv.} =
|
|||
if profileData[i] != nil and profileData[i].total > 1:
|
||||
inc sum, profileData[i].total
|
||||
writeln(f, "Entry: ", i, "/", entries, " Calls: ",
|
||||
profileData[i].total, "/", totalCalls, " [sum: ", sum, "; ",
|
||||
formatFloat(sum / totalCalls * 100.0, ffDefault, 2), "%]")
|
||||
profileData[i].total // totalCalls, " [sum: ", sum, "; ",
|
||||
sum // totalCalls, "]")
|
||||
for ii in 0..high(TStackTrace):
|
||||
let procname = profileData[i].st[ii]
|
||||
if isNil(procname): break
|
||||
|
|
|
|||
|
|
@ -77,9 +77,6 @@ proc setProfilingInterval*(intervalInUs: int): TNanos =
|
|||
|
||||
var t0: TTicks
|
||||
|
||||
var usefulCall* = 0
|
||||
var uselessCall* = 0
|
||||
|
||||
proc nimProfile() =
|
||||
## This is invoked by the compiler in every loop and on every proc entry!
|
||||
dec gTicker
|
||||
|
|
@ -87,7 +84,6 @@ proc nimProfile() =
|
|||
gTicker = -1
|
||||
let t1 = getticks()
|
||||
if getticks() - t0 > interval:
|
||||
inc usefulCall
|
||||
if not isNil(profilerHook):
|
||||
# disable recursive calls: XXX should use try..finally,
|
||||
# but that's too expensive!
|
||||
|
|
@ -96,8 +92,6 @@ proc nimProfile() =
|
|||
callProfilerHook(oldHook)
|
||||
profilerHook = oldHook
|
||||
t0 = getticks()
|
||||
else:
|
||||
inc uselessCall
|
||||
gTicker = SamplingInterval
|
||||
|
||||
proc stopProfiling*() =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue