Review at

log: Use sys._getframe() to avoid stat(2) calls

The Osmo MS driver is launching many many processes and I would
like to use the logging framework for the code as well.
Unfortunately the inspect/traceback code will use a linecache which
will execute stat(2) on one or more python files.

Change-Id: I8f6bacadcf74d3aa25db1e1f41644f64aa19cf92
M src/osmo_gsm_tester/
1 file changed, 8 insertions(+), 2 deletions(-)

  git pull ssh:// refs/changes/77/6377/1

diff --git a/src/osmo_gsm_tester/ b/src/osmo_gsm_tester/
index a9f16c2..698d819 100644
--- a/src/osmo_gsm_tester/
+++ b/src/osmo_gsm_tester/
@@ -275,8 +275,14 @@
         target.large_separator(*msgs, sublevel=sublevel, 
 def get_src_from_caller(levels_up=1):
-    caller = getframeinfo(stack()[levels_up][0])
-    return '%s:%d' % (os.path.basename(caller.filename), caller.lineno)
+    # Poke into internal to avoid hitting the linecache which will make one or
+    # more calls to stat(2).
+    frame = sys._getframe()
+    for i in range(0, levels_up):
+        frame = frame.f_back
+        if not frame:
+            return "<unknown:unknown>"
+    return '%s:%d' % (os.path.basename(frame.f_code.co_filename), 
 def get_src_from_exc_info(exc_info=None, levels_up=1):
     if exc_info is None:

To view, visit
To unsubscribe, visit

Gerrit-MessageType: newchange
Gerrit-Change-Id: I8f6bacadcf74d3aa25db1e1f41644f64aa19cf92
Gerrit-PatchSet: 1
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <>

Reply via email to