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

Side by Side Diff: tools/cygprofile/mergetraces.py

Issue 319053004: Fix bug in mergetraces.py. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 #!/usr/bin/python 1 #!/usr/bin/python
2 # Copyright 2013 The Chromium Authors. All rights reserved. 2 # Copyright 2013 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 # Use: ../mergetraces.py `ls cyglog.* -Sr` > merged_cyglog 6 # Use: ../mergetraces.py `ls cyglog.* -Sr` > merged_cyglog
7 7
8 """"Merge multiple logs files from different processes into a single log. 8 """"Merge multiple logs files from different processes into a single log.
9 9
10 Given two log files of execution traces, merge the traces into a single trace. 10 Given two log files of execution traces, merge the traces into a single trace.
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 tracemap[call] = trace_entry 136 tracemap[call] = trace_entry
137 137
138 def GroupByProcessAndThreadId(input_trace): 138 def GroupByProcessAndThreadId(input_trace):
139 """Returns an array of traces grouped by pid and tid. 139 """Returns an array of traces grouped by pid and tid.
140 140
141 This is used to make the order of functions not depend on thread scheduling 141 This is used to make the order of functions not depend on thread scheduling
142 which can be greatly impacted when profiling is done with cygprofile. As a 142 which can be greatly impacted when profiling is done with cygprofile. As a
143 result each thread has its own contiguous segment of code (ordered by 143 result each thread has its own contiguous segment of code (ordered by
144 timestamp) and processes also have their code isolated (i.e. not interleaved). 144 timestamp) and processes also have their code isolated (i.e. not interleaved).
145 """ 145 """
146 def MakeTimestamp(usec, sec): 146 def MakeTimestamp(sec, usec):
147 return usec * 1000000 + sec 147 return sec * 1000000 + usec
148 148
149 def PidAndTidFromString(pid_and_tid): 149 def PidAndTidFromString(pid_and_tid):
150 strings = pid_and_tid.split(':') 150 strings = pid_and_tid.split(':')
151 return (int(strings[0]), int(strings[1])) 151 return (int(strings[0]), int(strings[1]))
152 152
153 pid_first_seen = {} 153 pid_first_seen = {}
154 tid_first_seen = {} 154 tid_first_seen = {}
155 for (sec, usec, pid_and_tid, _) in input_trace: 155 for (sec, usec, pid_and_tid, _) in input_trace:
156 (pid, tid) = PidAndTidFromString(pid_and_tid) 156 (pid, tid) = PidAndTidFromString(pid_and_tid)
157 if not pid in pid_first_seen: 157 if not pid in pid_first_seen:
158 pid_first_seen[pid] = MakeTimestamp(usec, sec) 158 pid_first_seen[pid] = MakeTimestamp(sec, usec)
159 if not tid in tid_first_seen: 159 if not tid in tid_first_seen:
160 tid_first_seen[tid] = MakeTimestamp(usec, sec) 160 tid_first_seen[tid] = MakeTimestamp(sec, usec)
161 161
162 def CompareEvents(event1, event2): 162 def CompareEvents(event1, event2):
163 (sec1, usec1, pid_and_tid, _) = event1 163 (sec1, usec1, pid_and_tid, _) = event1
164 (pid1, tid1) = PidAndTidFromString(pid_and_tid) 164 (pid1, tid1) = PidAndTidFromString(pid_and_tid)
165 (sec2, usec2, pid_and_tid, _) = event2 165 (sec2, usec2, pid_and_tid, _) = event2
166 (pid2, tid2) = PidAndTidFromString(pid_and_tid) 166 (pid2, tid2) = PidAndTidFromString(pid_and_tid)
167 167
168 pid_cmp = cmp(pid_first_seen[pid1], pid_first_seen[pid2]) 168 pid_cmp = cmp(pid_first_seen[pid1], pid_first_seen[pid2])
169 if pid_cmp != 0: 169 if pid_cmp != 0:
170 return pid_cmp 170 return pid_cmp
171 tid_cmp = cmp(tid_first_seen[tid1], tid_first_seen[tid2]) 171 tid_cmp = cmp(tid_first_seen[tid1], tid_first_seen[tid2])
172 if tid_cmp != 0: 172 if tid_cmp != 0:
173 return tid_cmp 173 return tid_cmp
174 return cmp(MakeTimestamp(usec1, sec1), MakeTimestamp(usec2, sec2)) 174 return cmp(MakeTimestamp(sec1, usec1), MakeTimestamp(sec2, usec2))
175 175
176 return sorted(input_trace, cmp=CompareEvents) 176 return sorted(input_trace, cmp=CompareEvents)
177 177
178 def main(): 178 def main():
179 """Merge two traces for code in specified library and write to stdout. 179 """Merge two traces for code in specified library and write to stdout.
180 180
181 Merges the two traces and coverts the virtual addresses to the offsets in the 181 Merges the two traces and coverts the virtual addresses to the offsets in the
182 library. First line of merged trace has dummy virtual address of 0-ffffffff 182 library. First line of merged trace has dummy virtual address of 0-ffffffff
183 so that symbolizing the addresses uses the addresses in the log, since the 183 so that symbolizing the addresses uses the addresses in the log, since the
184 addresses have already been converted to static offsets. 184 addresses have already been converted to static offsets.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 grouped_trace = GroupByProcessAndThreadId(merged_trace) 220 grouped_trace = GroupByProcessAndThreadId(merged_trace)
221 221
222 print "0-ffffffff r-xp 00000000 xx:00 00000 ./" 222 print "0-ffffffff r-xp 00000000 xx:00 00000 ./"
223 print "secs\tusecs\tpid:threadid\tfunc" 223 print "secs\tusecs\tpid:threadid\tfunc"
224 for call in grouped_trace: 224 for call in grouped_trace:
225 print (str(call[0]) + "\t" + str(call[1]) + "\t" + call[2] + "\t" + 225 print (str(call[0]) + "\t" + str(call[1]) + "\t" + call[2] + "\t" +
226 hex(call[3])) 226 hex(call[3]))
227 227
228 if __name__ == '__main__': 228 if __name__ == '__main__':
229 main() 229 main()
OLDNEW
« no previous file with comments | « no previous file | tools/cygprofile/mergetraces_unittest.py » ('j') | tools/cygprofile/mergetraces_unittest.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698