summary refs log tree commit diff stats
path: root/lib
diff options
context:
space:
mode:
authorNick Greenfield <nick.greenfield@gmail.com>2014-05-20 17:07:20 -0400
committerNick Greenfield <nick.greenfield@gmail.com>2014-05-20 17:07:20 -0400
commit35e603b89c11c41094119d7013fb5a64f0a58791 (patch)
tree152f10b7b81d6fcbc41488b132229e487ef21e7d /lib
parent88cb4850cea651f78612a12e3fd3ba704109b0b7 (diff)
downloadNim-35e603b89c11c41094119d7013fb5a64f0a58791.tar.gz
Fix nimprof import error when --threads:on.
Diffstat (limited to 'lib')
-rw-r--r--lib/pure/nimprof.nim13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/pure/nimprof.nim b/lib/pure/nimprof.nim
index 3d0cc2154..ab7cd1944 100644
--- a/lib/pure/nimprof.nim
+++ b/lib/pure/nimprof.nim
@@ -58,8 +58,9 @@ when not defined(memProfiler):
     ## instruction count measure instead then.
     if intervalInUs <= 0: interval = 0
     else: interval = intervalInUs * 1000 - tickCountCorrection
-  
+
 when withThreads:
+  import locks
   var
     profilingLock: TLock
 
@@ -72,7 +73,7 @@ proc hookAux(st: TStackTrace, costs: int) =
   var last = high(st)
   while last > 0 and isNil(st[last]): dec last
   var h = hash(pointer(st[last])) and high(profileData)
-  
+
   # we use probing for maxChainLen entries and replace the encountered entry
   # with the minimal 'total' value:
   if emptySlots == 0:
@@ -133,7 +134,7 @@ else:
       hookAux(st, 1)
     elif getticks() - t0 > interval:
       hookAux(st, 1)
-      t0 = getticks()  
+      t0 = getticks()
 
 proc getTotal(x: ptr TProfileEntry): int =
   result = if isNil(x): 0 else: x.total
@@ -145,7 +146,7 @@ proc `//`(a, b: int): string =
   result = format("$1/$2 = $3%", a, b, formatFloat(a / b * 100.0, ffDefault, 2))
 
 proc writeProfile() {.noconv.} =
-  when defined(system.TStackTrace): 
+  when defined(system.TStackTrace):
     system.profilerHook = nil
   const filename = "profile_results.txt"
   echo "writing " & filename & "..."
@@ -156,7 +157,7 @@ proc writeProfile() {.noconv.} =
     var entries = 0
     for i in 0..high(profileData):
       if profileData[i] != nil: inc entries
-    
+
     var perProc = initCountTable[string]()
     for i in 0..entries-1:
       var dups = initSet[string]()
@@ -166,7 +167,7 @@ proc writeProfile() {.noconv.} =
         let p = $procname
         if not containsOrIncl(dups, p):
           perProc.inc(p, profileData[i].total)
-    
+
     var sum = 0
     # only write the first 100 entries:
     for i in 0..min(100, entries-1):