summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mini-scalene.py24
1 files changed, 18 insertions, 6 deletions
diff --git a/mini-scalene.py b/mini-scalene.py
index 4883cff..2fa5b59 100644
--- a/mini-scalene.py
+++ b/mini-scalene.py
@@ -1,10 +1,11 @@
import sys
-import os
import threading
import traceback
import runpy
import atexit
import signal
+from typing import cast
+from types import FrameType
from collections import defaultdict
@@ -66,9 +67,19 @@ class mini_scalene:
# to look back into the outer frame in order to check
# the co_filename.
fname = frame.f_back.f_code.co_filename
- if not mini_scalene.should_trace(fname):
- continue
- new_frames.append(frame)
+ while not mini_scalene.should_trace(fname):
+ # Walk the stack backwards until we hit a frame that
+ # IS one we should trace (if there is one). i.e., if
+ # it's in the code being profiled, and it is just
+ # calling stuff deep in libraries.
+ if frame:
+ frame = cast(FrameType, frame.f_back)
+ else:
+ break
+ if frame:
+ fname = frame.f_code.co_filename
+ if frame:
+ new_frames.append(frame)
return new_frames
@staticmethod
@@ -81,10 +92,11 @@ class mini_scalene:
@staticmethod
def should_trace(filename):
- # Don't trace the profiler itself.
+ # We're assuming Guix System. That makes it easy.
+ if '/gnu/store' in filename:
+ return False
if 'mini-scalene.py' in filename:
return False
- # Don't trace Python builtins.
if '<frozen importlib._bootstrap>' in filename:
return False
if '<frozen importlib._bootstrap_external>' in filename: