aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/profile_analyzer/profile_analyzer.py
diff options
context:
space:
mode:
authorGravatar David Garcia Quintas <dgq@google.com>2015-05-06 15:30:08 -0700
committerGravatar David Garcia Quintas <dgq@google.com>2015-05-06 17:11:54 -0700
commit7cff3ee2058f63052e6c53c33fc3490d020e81d3 (patch)
tree9a40733868ddf8f408d3c349d2f6a6eabfdbb5fb /tools/profile_analyzer/profile_analyzer.py
parent975efdc915fb165b0cfa650a9e718d9382193b31 (diff)
Handling of ! tags across threads & performance.
Fixed an important bug whereby thread info wasn't being taken into account for ! marks. Also dramatically improved performance by getting rid of a silly O(n^2) loop.
Diffstat (limited to 'tools/profile_analyzer/profile_analyzer.py')
-rwxr-xr-xtools/profile_analyzer/profile_analyzer.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/tools/profile_analyzer/profile_analyzer.py b/tools/profile_analyzer/profile_analyzer.py
index 632aeffd3c..bd3181b4ee 100755
--- a/tools/profile_analyzer/profile_analyzer.py
+++ b/tools/profile_analyzer/profile_analyzer.py
@@ -65,9 +65,9 @@ class ImportantMark(object):
def entry(self):
return self._entry
- def append_post_entry(self, entry):
- if self._n > 0:
- self._post_stack.append(entry)
+ def append_post_entry(self, post_entry):
+ if self._n > 0 and post_entry.thread == self._entry.thread:
+ self._post_stack.append(post_entry)
self._n -= 1
def get_deltas(self):
@@ -112,25 +112,29 @@ def entries():
threads = collections.defaultdict(lambda: collections.defaultdict(list))
times = collections.defaultdict(list)
important_marks = collections.defaultdict(list)
+stack_depth = 0
for entry in entries():
thread = threads[entry.thread]
if entry.type == '{':
thread[entry.tag].append(entry)
+ stack_depth += 1
if entry.type == '!':
# Save a snapshot of the current stack inside a new ImportantMark instance.
- # Get all entries with type '{' from "thread".
- stack = [e for entries_for_tag in thread.values()
- for e in entries_for_tag if e.type == '{']
- imark_group_key = '{tag}@{file}:{line}'.format(**entry._asdict())
+ # Get all entries _for any tag in the thread_.
+ stack = [e for entries_for_tag in thread.itervalues()
+ for e in entries_for_tag]
+ imark_group_key = '{tag}/{thread}@{file}:{line}'.format(**entry._asdict())
important_marks[imark_group_key].append(ImportantMark(entry, stack))
elif entry.type == '}':
last = thread[entry.tag].pop()
times[entry.tag].append(entry.time - last.time)
# Update accounting for important marks.
for imarks_group in important_marks.itervalues():
- for imark in imarks_group:
+ # only access the last "stack_depth" imarks.
+ for imark in imarks_group[-stack_depth:]:
imark.append_post_entry(entry)
+ stack_depth -= 1
def percentile(vals, percent):
""" Calculates the interpolated percentile given a sorted sequence and a