summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-09-15 01:27:53 +0200
committerAraq <rumpf_a@web.de>2012-09-15 01:27:53 +0200
commitad6ee9e85723a742fe76e6903a63f2796136fe98 (patch)
treeffe3388a25992cc2a74868d6206a8355be0fe1d5 /lib
parent04e4aa328bd84004294f8fd96255c7855392e70c (diff)
downloadNim-ad6ee9e85723a742fe76e6903a63f2796136fe98.tar.gz
profiler documentation
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/nimprof.nim7
-rwxr-xr-xlib/system/profiler.nim6
2 files changed, 5 insertions, 8 deletions
diff --git a/lib/pure/nimprof.nim b/lib/pure/nimprof.nim
index 99af71f90..1d3c57ed0 100644
--- a/lib/pure/nimprof.nim
+++ b/lib/pure/nimprof.nim
@@ -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
diff --git a/lib/system/profiler.nim b/lib/system/profiler.nim
index aef75d39d..b7b8d8375 100755
--- a/lib/system/profiler.nim
+++ b/lib/system/profiler.nim
@@ -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*() =