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

Side by Side Diff: tools/telemetry/telemetry/timeline/trace_event_importer.py

Issue 1553183002: [telemetry] Add support for composable process dumps in memory-infra (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: adding test Created 4 years, 11 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
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be 2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file. 3 # found in the LICENSE file.
4 """TraceEventImporter imports TraceEvent-formatted data 4 """TraceEventImporter imports TraceEvent-formatted data
5 into the provided model. 5 into the provided model.
6 This is a port of the trace event importer from 6 This is a port of the trace event importer from
7 https://code.google.com/p/trace-viewer/ 7 https://code.google.com/p/trace-viewer/
8 """ 8 """
9 9
10 import collections 10 import collections
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 event['ts'] / 1000.0, 187 event['ts'] / 1000.0,
188 event.get('args')) 188 event.get('args'))
189 189
190 def _ProcessFlowEvent(self, event): 190 def _ProcessFlowEvent(self, event):
191 thread = (self._GetOrCreateProcess(event['pid']) 191 thread = (self._GetOrCreateProcess(event['pid'])
192 .GetOrCreateThread(event['tid'])) 192 .GetOrCreateThread(event['tid']))
193 self._all_flow_events.append({ 193 self._all_flow_events.append({
194 'event': event, 194 'event': event,
195 'thread': thread}) 195 'thread': thread})
196 196
197 def _ProcessMemoryDumpEvent(self, event): 197 def _ProcessMemoryDumpEvents(self, events):
198 process = self._GetOrCreateProcess(event['pid']) 198 # Dictionary to order dumps by id and process.
199 memory_dump = memory_dump_event.ProcessMemoryDumpEvent(process, event) 199 global_dumps = collections.defaultdict(dict)
200 process.AddMemoryDumpEvent(memory_dump) 200 for event in events:
201 self._all_memory_dumps_by_dump_id[memory_dump.dump_id].append(memory_dump) 201 process = self._GetOrCreateProcess(event['pid'])
202 if process not in global_dumps[event['id']]:
203 global_dumps[event['id']][
petrcermak 2016/01/07 18:59:29 this might look a bit better as follows: global_d
204 process] = memory_dump_event.ProcessMemoryDumpEvent(
205 process, event['id'], event['ts'])
206 global_dumps[event['id']][process].AddRawEvent(event)
207 for dump_id, global_dump in global_dumps.iteritems():
208 for process, process_dump in global_dump.iteritems():
209 process_dump.ProcessAllocatorDumps()
210 process.AddMemoryDumpEvent(process_dump)
211 self._all_memory_dumps_by_dump_id[dump_id].append(process_dump)
202 212
203 def ImportEvents(self): 213 def ImportEvents(self):
204 """Walks through the events_ list and outputs the structures discovered to 214 """Walks through the events_ list and outputs the structures discovered to
205 model_. 215 model_.
206 """ 216 """
217 memory_dump_events = []
207 for event in self._events: 218 for event in self._events:
208 phase = event.get('ph', None) 219 phase = event.get('ph', None)
209 if phase == 'B' or phase == 'E': 220 if phase == 'B' or phase == 'E':
210 self._ProcessDurationEvent(event) 221 self._ProcessDurationEvent(event)
211 elif phase == 'X': 222 elif phase == 'X':
212 self._ProcessCompleteEvent(event) 223 self._ProcessCompleteEvent(event)
213 # Note, S, F, T are deprecated and replaced by 'b' and 'e'. For 224 # Note, S, F, T are deprecated and replaced by 'b' and 'e'. For
214 # backwards compatibility continue to support them here. 225 # backwards compatibility continue to support them here.
215 elif phase == 'S' or phase == 'F' or phase == 'T': 226 elif phase == 'S' or phase == 'F' or phase == 'T':
216 self._ProcessAsyncEvent(event) 227 self._ProcessAsyncEvent(event)
217 elif phase == 'b' or phase == 'e': 228 elif phase == 'b' or phase == 'e':
218 self._ProcessAsyncEvent(event) 229 self._ProcessAsyncEvent(event)
219 # Note, I is historic. The instant event marker got changed, but we 230 # Note, I is historic. The instant event marker got changed, but we
220 # want to support loading old trace files so we have both I and i. 231 # want to support loading old trace files so we have both I and i.
221 elif phase == 'I' or phase == 'i': 232 elif phase == 'I' or phase == 'i':
222 self._ProcessInstantEvent(event) 233 self._ProcessInstantEvent(event)
223 elif phase == 'P': 234 elif phase == 'P':
224 self._ProcessSampleEvent(event) 235 self._ProcessSampleEvent(event)
225 elif phase == 'C': 236 elif phase == 'C':
226 self._ProcessCounterEvent(event) 237 self._ProcessCounterEvent(event)
227 elif phase == 'M': 238 elif phase == 'M':
228 self._ProcessMetadataEvent(event) 239 self._ProcessMetadataEvent(event)
229 elif phase == 'N' or phase == 'D' or phase == 'O': 240 elif phase == 'N' or phase == 'D' or phase == 'O':
230 self._ProcessObjectEvent(event) 241 self._ProcessObjectEvent(event)
231 elif phase == 's' or phase == 't' or phase == 'f': 242 elif phase == 's' or phase == 't' or phase == 'f':
232 self._ProcessFlowEvent(event) 243 self._ProcessFlowEvent(event)
233 elif phase == 'v': 244 elif phase == 'v':
234 self._ProcessMemoryDumpEvent(event) 245 memory_dump_events.append(event)
235 elif phase == 'R': 246 elif phase == 'R':
236 self._ProcessMarkEvent(event) 247 self._ProcessMarkEvent(event)
237 else: 248 else:
238 self._model.import_errors.append('Unrecognized event phase: ' + 249 self._model.import_errors.append('Unrecognized event phase: ' +
239 phase + '(' + event['name'] + ')') 250 phase + '(' + event['name'] + ')')
240 251
252 # Memory dumps of a process with the same dump id need to be merged before
253 # processing. So, memory dump events are processed all at once.
254 self._ProcessMemoryDumpEvents(memory_dump_events)
241 return self._model 255 return self._model
242 256
243 def FinalizeImport(self): 257 def FinalizeImport(self):
244 """Called by the Model after all other importers have imported their 258 """Called by the Model after all other importers have imported their
245 events.""" 259 events."""
246 self._model.UpdateBounds() 260 self._model.UpdateBounds()
247 261
248 # We need to reupdate the bounds in case the minimum start time changes 262 # We need to reupdate the bounds in case the minimum start time changes
249 self._model.UpdateBounds() 263 self._model.UpdateBounds()
250 self._CreateAsyncSlices() 264 self._CreateAsyncSlices()
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
426 440
427 def _SetBrowserProcess(self): 441 def _SetBrowserProcess(self):
428 for thread in self._model.GetAllThreads(): 442 for thread in self._model.GetAllThreads():
429 if thread.name == 'CrBrowserMain': 443 if thread.name == 'CrBrowserMain':
430 self._model.browser_process = thread.parent 444 self._model.browser_process = thread.parent
431 445
432 def _SetGpuProcess(self): 446 def _SetGpuProcess(self):
433 for thread in self._model.GetAllThreads(): 447 for thread in self._model.GetAllThreads():
434 if thread.name == 'CrGpuMain': 448 if thread.name == 'CrGpuMain':
435 self._model.gpu_process = thread.parent 449 self._model.gpu_process = thread.parent
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698