aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-24 11:40:55 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-07-24 11:52:14 +0100
commit7be76d8f79ea92fd4bd36146eb9a4b86551b526d (patch)
tree9ae687936c7421e7cbe32471af4fbc8bd81d3364
parent90fdd69cca951f8bd2ff634f3b42fccd4fc03095 (diff)
downloadbitbake-7be76d8f79ea92fd4bd36146eb9a4b86551b526d.tar.gz
data_smart: Improve performance of infer_caller_details()
As things stand now, bitbake -e (which turns on all the caller tracking) of OE-Core generates around 9.5 million stat calls which is slow and the largest single thing on the profile data. This is because infer_caller_details() calls traceback.extract_stack() which adds line contents to the traceback. This in turn calls python's internal linecache code which calls stat on every file for every callback. We don't even use that info. We only even want a single frame of the stack. Instead, open code for the pieces of information we need. Also, only obtain the stack once for both halves of the infer_caller_details() code. This reduces the number of stat calls to around 0.5 million and significantly improves parsing with bitbake -e. Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
-rw-r--r--lib/bb/data_smart.py25
1 files changed, 17 insertions, 8 deletions
diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
index a7cae77d3..f0187b7a1 100644
--- a/lib/bb/data_smart.py
+++ b/lib/bb/data_smart.py
@@ -54,27 +54,36 @@ def infer_caller_details(loginfo, parent = False, varval = True):
return
# Infer caller's likely values for variable (var) and value (value),
# to reduce clutter in the rest of the code.
- if varval and ('variable' not in loginfo or 'detail' not in loginfo):
+ above = None
+ def set_above():
try:
raise Exception
except Exception:
tb = sys.exc_info()[2]
if parent:
- above = tb.tb_frame.f_back.f_back
+ return tb.tb_frame.f_back.f_back.f_back
else:
- above = tb.tb_frame.f_back
- lcls = above.f_locals.items()
+ return tb.tb_frame.f_back.f_back
+
+ if varval and ('variable' not in loginfo or 'detail' not in loginfo):
+ if not above:
+ above = set_above()
+ lcls = above.f_locals.items()
for k, v in lcls:
if k == 'value' and 'detail' not in loginfo:
loginfo['detail'] = v
if k == 'var' and 'variable' not in loginfo:
loginfo['variable'] = v
# Infer file/line/function from traceback
+ # Don't use traceback.extract_stack() since it fills the line contents which
+ # we don't need and that hits stat syscalls
if 'file' not in loginfo:
- depth = 3
- if parent:
- depth = 4
- file, line, func, text = traceback.extract_stack(limit = depth)[0]
+ if not above:
+ above = set_above()
+ f = above.f_back
+ line = f.f_lineno
+ file = f.f_code.co_filename
+ func = f.f_code.co_name
loginfo['file'] = file
loginfo['line'] = line
if func not in loginfo: