summary refs log tree commit diff stats
path: root/lib/system/profiler.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/system/profiler.nim')
-rw-r--r--lib/system/profiler.nim19
1 files changed, 13 insertions, 6 deletions
diff --git a/lib/system/profiler.nim b/lib/system/profiler.nim
index c00a7d53a..7146500d9 100644
--- a/lib/system/profiler.nim
+++ b/lib/system/profiler.nim
@@ -19,10 +19,14 @@ const
   MaxTraceLen = 20 # tracking the last 20 calls is enough
 
 type
-  StackTrace* = array[0..MaxTraceLen-1, cstring]
+  StackTrace* = object
+    lines*: array[0..MaxTraceLen-1, cstring]
+    files*: array[0..MaxTraceLen-1, cstring]
   ProfilerHook* = proc (st: StackTrace) {.nimcall.}
 {.deprecated: [TStackTrace: StackTrace, TProfilerHook: ProfilerHook].}
 
+proc `[]`*(st: StackTrace, i: int): cstring = st.lines[i]
+
 proc captureStackTrace(f: PFrame, st: var StackTrace) =
   const
     firstCalls = 5
@@ -30,9 +34,10 @@ proc captureStackTrace(f: PFrame, st: var StackTrace) =
     it = f
     i = 0
     total = 0
-  while it != nil and i <= high(st)-(firstCalls-1):
+  while it != nil and i <= high(st.lines)-(firstCalls-1):
     # the (-1) is for the "..." entry
-    st[i] = it.procname
+    st.lines[i] = it.procname
+    st.files[i] = it.filename
     inc(i)
     inc(total)
     it = it.prev
@@ -43,10 +48,12 @@ proc captureStackTrace(f: PFrame, st: var StackTrace) =
   for j in 1..total-i-(firstCalls-1):
     if b != nil: b = b.prev
   if total != i:
-    st[i] = "..."
+    st.lines[i] = "..."
+    st.files[i] = "..."
     inc(i)
-  while b != nil and i <= high(st):
-    st[i] = b.procname
+  while b != nil and i <= high(st.lines):
+    st.lines[i] = b.procname
+    st.files[i] = b.filename
     inc(i)
     b = b.prev