Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Unified Diff: tools/cygprofile/mergetraces.py

Issue 319053004: Fix bug in mergetraces.py. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address Egor's comments Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/cygprofile/mergetraces_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/cygprofile/mergetraces.py
diff --git a/tools/cygprofile/mergetraces.py b/tools/cygprofile/mergetraces.py
index f349ad3b885374cada16b86b1cc2c2ed2018f4da..671646491cee427b1277413ba051da218032c02f 100755
--- a/tools/cygprofile/mergetraces.py
+++ b/tools/cygprofile/mergetraces.py
@@ -14,6 +14,7 @@ create a single log that is an ordered trace of calls by both processes.
import optparse
import string
+import sets
import sys
def ParseLogLines(lines):
@@ -143,21 +144,30 @@ def GroupByProcessAndThreadId(input_trace):
result each thread has its own contiguous segment of code (ordered by
timestamp) and processes also have their code isolated (i.e. not interleaved).
"""
- def MakeTimestamp(usec, sec):
- return usec * 1000000 + sec
+ def MakeTimestamp(sec, usec):
+ return sec * 1000000 + usec
def PidAndTidFromString(pid_and_tid):
strings = pid_and_tid.split(':')
return (int(strings[0]), int(strings[1]))
+ tid_to_pids_map = {}
pid_first_seen = {}
tid_first_seen = {}
+
for (sec, usec, pid_and_tid, _) in input_trace:
(pid, tid) = PidAndTidFromString(pid_and_tid)
+
+ # Make sure that thread IDs are unique since this a property we rely on.
pasko 2014/06/06 09:41:44 s/this/this is/
Philippe 2014/06/06 09:50:23 Done.
Philippe 2014/06/06 09:50:23 Done.
+ pids_for_tid = tid_to_pids_map.setdefault(tid, sets.Set())
+ pids_for_tid.add(pid)
+ if len(pids_for_tid) > 1:
+ raise Exception('Thread IDs should be unique.')
pasko 2014/06/06 09:41:44 in this context we actually have the tid and two p
Philippe 2014/06/06 09:50:23 Yeah :) I haven't slept much last night :)
+
if not pid in pid_first_seen:
- pid_first_seen[pid] = MakeTimestamp(usec, sec)
+ pid_first_seen[pid] = MakeTimestamp(sec, usec)
if not tid in tid_first_seen:
- tid_first_seen[tid] = MakeTimestamp(usec, sec)
+ tid_first_seen[tid] = MakeTimestamp(sec, usec)
def CompareEvents(event1, event2):
(sec1, usec1, pid_and_tid, _) = event1
@@ -171,7 +181,7 @@ def GroupByProcessAndThreadId(input_trace):
tid_cmp = cmp(tid_first_seen[tid1], tid_first_seen[tid2])
if tid_cmp != 0:
return tid_cmp
- return cmp(MakeTimestamp(usec1, sec1), MakeTimestamp(usec2, sec2))
+ return cmp(MakeTimestamp(sec1, usec1), MakeTimestamp(sec2, usec2))
return sorted(input_trace, cmp=CompareEvents)
« no previous file with comments | « no previous file | tools/cygprofile/mergetraces_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698