summary refs log tree commit diff stats
path: root/lib/system
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2012-09-17 00:31:41 +0200
committerAraq <rumpf_a@web.de>2012-09-17 00:31:41 +0200
commit75abf7250325d90a74189ea7e4852d36c3fdd67c (patch)
tree8f58e79a9330420722f6712fb27eeae59ef4fc4b /lib/system
parentad6ee9e85723a742fe76e6903a63f2796136fe98 (diff)
downloadNim-75abf7250325d90a74189ea7e4852d36c3fdd67c.tar.gz
profiler improvements
Diffstat (limited to 'lib/system')
-rwxr-xr-xlib/system/ecmasys.nim2
-rwxr-xr-xlib/system/gc.nim4
-rwxr-xr-xlib/system/profiler.nim42
-rwxr-xr-xlib/system/sysio.nim2
4 files changed, 17 insertions, 33 deletions
diff --git a/lib/system/ecmasys.nim b/lib/system/ecmasys.nim
index 0c9db2206..e6a7d7057 100755
--- a/lib/system/ecmasys.nim
+++ b/lib/system/ecmasys.nim
@@ -33,7 +33,7 @@ var
     # list of exception handlers
     # a global variable for the root of all try blocks
 
-{.push stacktrace: off.}
+{.push stacktrace: off, profiler:off.}
 proc nimBoolToStr(x: bool): string {.compilerproc.} =
   if x: result = "true"
   else: result = "false"
diff --git a/lib/system/gc.nim b/lib/system/gc.nim
index a5937efe5..a95319e51 100755
--- a/lib/system/gc.nim
+++ b/lib/system/gc.nim
@@ -78,11 +78,11 @@ var
 when not defined(useNimRtl):
   InstantiateForRegion(gch.region)
 
-proc acquire(gch: var TGcHeap) {.inline.} = 
+template acquire(gch: TGcHeap) = 
   when hasThreadSupport and hasSharedHeap:
     AcquireSys(HeapLock)
 
-proc release(gch: var TGcHeap) {.inline.} = 
+template release(gch: TGcHeap) = 
   when hasThreadSupport and hasSharedHeap:
     releaseSys(HeapLock)
 
diff --git a/lib/system/profiler.nim b/lib/system/profiler.nim
index b7b8d8375..28edeff7a 100755
--- a/lib/system/profiler.nim
+++ b/lib/system/profiler.nim
@@ -18,9 +18,6 @@
 
 {.push profiler: off.}
 
-when not defined(getTicks):
-  include "system/timers"
-
 const
   MaxTraceLen = 20 # tracking the last 20 calls is enough
 
@@ -36,7 +33,7 @@ proc captureStackTrace(f: PFrame, st: var TStackTrace) =
     i = 0
     total = 0
   while it != nil and i <= high(st)-(firstCalls-1):
-    # the (-1) is for a nil entry that marks where the '...' should occur
+    # the (-1) is for the "..." entry
     st[i] = it.procname
     inc(i)
     inc(total)
@@ -55,14 +52,14 @@ proc captureStackTrace(f: PFrame, st: var TStackTrace) =
     inc(i)
     b = b.prev
 
+const
+  SamplingInterval = 50_000
+    # set this to change the default sampling interval
 var
   profilerHook*: TProfilerHook
     ## set this variable to provide a procedure that implements a profiler in
     ## user space. See the `nimprof` module for a reference implementation.
-  SamplingInterval = 50_000
-    # set this to change the default sampling interval
-  gTicker = SamplingInterval
-  interval: TNanos = 5_000_000 # 5ms
+  gTicker {.threadvar.}: int
 
 proc callProfilerHook(hook: TProfilerHook) {.noinline.} =
   # 'noinline' so that 'nimProfile' does not perform the stack allocation
@@ -71,31 +68,18 @@ proc callProfilerHook(hook: TProfilerHook) {.noinline.} =
   captureStackTrace(framePtr, st)
   hook(st)
 
-proc setProfilingInterval*(intervalInUs: int): TNanos =
-  ## set this to change the sampling interval. Default value is 5ms.
-  interval = intervalInUs * 1000
-
-var t0: TTicks
-
 proc nimProfile() =
   ## This is invoked by the compiler in every loop and on every proc entry!
-  dec gTicker
   if gTicker == 0:
     gTicker = -1
-    let t1 = getticks()
-    if getticks() - t0 > interval:
-      if not isNil(profilerHook):
-        # disable recursive calls: XXX should use try..finally,
-        # but that's too expensive!
-        let oldHook = profilerHook
-        profilerHook = nil
-        callProfilerHook(oldHook)
-        profilerHook = oldHook
-      t0 = getticks()
+    if not isNil(profilerHook):
+      # disable recursive calls: XXX should use try..finally,
+      # but that's too expensive!
+      let oldHook = profilerHook
+      profilerHook = nil
+      callProfilerHook(oldHook)
+      profilerHook = oldHook
     gTicker = SamplingInterval
-
-proc stopProfiling*() =
-  ## call this to stop profiling; should be called by the client profiler.
-  profilerHook = nil
+  dec gTicker
 
 {.pop.}
diff --git a/lib/system/sysio.nim b/lib/system/sysio.nim
index 9f7866fdc..02a5893d3 100755
--- a/lib/system/sysio.nim
+++ b/lib/system/sysio.nim
@@ -224,7 +224,7 @@ proc ReadBytes(f: TFile, a: var openarray[int8], start, len: int): int =
 proc ReadChars(f: TFile, a: var openarray[char], start, len: int): int =
   result = readBuffer(f, addr(a[start]), len)
 
-{.push stackTrace:off.}
+{.push stackTrace:off, profiler:off.}
 proc writeBytes(f: TFile, a: openarray[int8], start, len: int): int =
   var x = cast[ptr array[0..1000_000_000, int8]](a)
   result = writeBuffer(f, addr(x[start]), len)