[PATCH] osmo-gsm-tester[master]: log: Use sys._getframe() to avoid stat(2) calls

Holger Freyther gerrit-no-reply at lists.osmocom.org
Tue Feb 13 09:17:12 UTC 2018

Hello Pau Espin Pedrol, Jenkins Builder,

I'd like you to reexamine a change.  Please visit


to look at the new patch set (#2).

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.

Related: OS#2927
Change-Id: I8f6bacadcf74d3aa25db1e1f41644f64aa19cf92
M src/osmo_gsm_tester/log.py
1 file changed, 4 insertions(+), 2 deletions(-)

  git pull ssh://gerrit.osmocom.org:29418/osmo-gsm-tester refs/changes/77/6377/2

diff --git a/src/osmo_gsm_tester/log.py b/src/osmo_gsm_tester/log.py
index a9f16c2..7c4ae44 100644
--- a/src/osmo_gsm_tester/log.py
+++ b/src/osmo_gsm_tester/log.py
@@ -275,8 +275,10 @@
         target.large_separator(*msgs, sublevel=sublevel, space_above=space_above)
 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(levels_up)
+    return '%s:%d' % (os.path.basename(frame.f_code.co_filename), frame.f_lineno)
 def get_src_from_exc_info(exc_info=None, levels_up=1):
     if exc_info is None:

To view, visit https://gerrit.osmocom.org/6377
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newpatchset
Gerrit-Change-Id: I8f6bacadcf74d3aa25db1e1f41644f64aa19cf92
Gerrit-PatchSet: 2
Gerrit-Project: osmo-gsm-tester
Gerrit-Branch: master
Gerrit-Owner: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Holger Freyther <holger at freyther.de>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: Pau Espin Pedrol <pespin at sysmocom.de>
Gerrit-Reviewer: neels <nhofmeyr at sysmocom.de>

More information about the gerrit-log mailing list