OLD | NEW |
(Empty) | |
| 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 |
| 3 # found in the LICENSE file. |
| 4 |
| 5 class EventStats(object): |
| 6 def __init__(self, src_event_name, result_name, result_description): |
| 7 self.src_event_name = src_event_name |
| 8 self.result_name = result_name |
| 9 self.result_description = result_description |
| 10 self.thread_duration = 0.0 |
| 11 self.thread_duration_inside_idle = 0.0 |
| 12 |
| 13 @property |
| 14 def thread_duration_outside_idle(self): |
| 15 return self.thread_duration - self.thread_duration_inside_idle |
| 16 |
| 17 |
| 18 def _FindEventStats(event_stats_list, event_name): |
| 19 for event_stats in event_stats_list: |
| 20 if event_stats.src_event_name == event_name: |
| 21 return event_stats |
| 22 return None |
| 23 |
| 24 |
| 25 def _IsDescendentOfIdleNotification(event): |
| 26 parent = event.parent_slice |
| 27 while parent: |
| 28 if parent.name == 'V8.GCIdleNotification': |
| 29 return True |
| 30 parent = parent.parent_slice |
| 31 return False |
| 32 |
| 33 class V8Stats(object): |
| 34 def __init__(self, renderer_thread, interaction_records): |
| 35 self.all_event_stats = [ |
| 36 EventStats('V8.GCIncrementalMarking', |
| 37 'incremental_marking', |
| 38 'total thread duration spent in incremental marking steps'), |
| 39 EventStats('V8.GCScavenger', |
| 40 'scavenger', |
| 41 'total thread duration spent in scavenges'), |
| 42 EventStats('V8.GCCompactor', |
| 43 'mark_compactor', |
| 44 'total thread duration spent in mark-sweep-compactor')] |
| 45 |
| 46 # Find all GC events contained in an interaction record |
| 47 for event in renderer_thread.IterAllSlices(): |
| 48 event_stats = _FindEventStats(self.all_event_stats, event.name) |
| 49 if not event_stats: |
| 50 continue |
| 51 for r in interaction_records: |
| 52 if not r.GetBounds().ContainsInterval(event.start, event.end): |
| 53 continue |
| 54 event_stats.thread_duration += event.thread_duration |
| 55 if _IsDescendentOfIdleNotification(event): |
| 56 event_stats.thread_duration_inside_idle += event.thread_duration |
| 57 |
| 58 @property |
| 59 def total_gc_thread_duration(self): |
| 60 return sum(x.thread_duration for x in self.all_event_stats) |
| 61 |
| 62 @property |
| 63 def total_gc_thread_duration_outside_idle(self): |
| 64 return sum(x.thread_duration_outside_idle for x in self.all_event_stats) |
OLD | NEW |