Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 | |
| 4 import sys | 5 import sys |
| 5 | 6 |
| 6 from metrics import Metric | 7 from metrics import Metric |
| 8 from metrics import histogram | |
| 9 | |
| 10 _HISTOGRAMS = [ | |
| 11 {'name': 'V8.MemoryExternalFragmentationTotal', 'units': 'percent', | |
| 12 'type': histogram.MEMORY_HISTOGRAM}, | |
| 13 {'name': 'V8.MemoryHeapSampleTotalCommitted', 'units': 'kb', | |
| 14 'type': histogram.MEMORY_HISTOGRAM}, | |
| 15 {'name': 'V8.MemoryHeapSampleTotalUsed', 'units': 'kb', | |
| 16 'type': histogram.MEMORY_HISTOGRAM}, | |
| 17 {'name': 'Memory.RendererUsed', 'units': 'kb', | |
| 18 'type': histogram.MEMORY_HISTOGRAM}, | |
| 19 {'name': 'Memory.BrowserUsed', 'units': 'kb', | |
| 20 'type': histogram.BROWSER_HISTOGRAM}] | |
|
qyearsley
2013/08/08 17:35:52
I also put the histogram type into each list item
| |
| 7 | 21 |
| 8 class MemoryMetric(Metric): | 22 class MemoryMetric(Metric): |
| 9 """MemoryMetric gathers memory statistics from the browser object.""" | 23 """MemoryMetric gathers memory statistics from the browser object. |
| 24 | |
| 25 This includes both per-page histogram stats, most about javascript | |
| 26 memory usage, and overall memory stats from the system for the whole | |
| 27 test run.""" | |
| 10 | 28 |
| 11 def __init__(self, browser): | 29 def __init__(self, browser): |
| 12 super(MemoryMetric, self).__init__() | 30 super(MemoryMetric, self).__init__() |
| 13 self._browser = browser | 31 self._browser = browser |
| 14 self._memory_stats = None | 32 self._start_commit_charge = self._browser.memory_stats['SystemCommitCharge'] |
| 15 self._start_commit_charge = None | 33 self._end_memory_stats = None |
| 34 self._histogram_start_values = dict() | |
| 35 self._histogram_delta_values = dict() | |
| 16 | 36 |
| 17 def Start(self, page=None, tab=None): | 37 def Start(self, page, tab): |
| 18 """Record the initial value of 'SystemCommitCharge'.""" | 38 """Start the per-page preparation for this metric. |
| 19 self._start_commit_charge = self._browser.memory_stats['SystemCommitCharge'] | |
| 20 | 39 |
| 21 def Stop(self, page=None, tab=None): | 40 Here, this consists of recording the start value of all the histograms. |
| 22 """Fetch the browser memory stats.""" | 41 """ |
| 23 assert self._start_commit_charge, 'Must call Start() first' | 42 for h in _HISTOGRAMS: |
| 24 self._memory_stats = self._browser.memory_stats | 43 histogram_data = histogram.GetHistogramData(h['type'], h['name'], tab) |
| 44 if not histogram_data: | |
| 45 continue | |
| 46 self._histogram_start_values[h['name']] = histogram_data | |
| 47 | |
| 48 def Stop(self, page, tab): | |
| 49 """Prepare the results for this page. | |
| 50 | |
| 51 The results are the differences between the current histogram values | |
| 52 and the values when Start() was called. | |
| 53 """ | |
| 54 assert self._histogram_start_values, 'Must call Start() first' | |
| 55 for h in _HISTOGRAMS: | |
| 56 histogram_data = histogram.GetHistogramData(h['type'], h['name'], tab) | |
| 57 self._histogram_delta_values = histogram.SubtractHistogram( | |
| 58 histogram_data, self._histogram_start_values[h['name']]) | |
| 25 | 59 |
| 26 def AddResults(self, tab, results): | 60 def AddResults(self, tab, results): |
| 27 """Add summary results to the results object.""" | 61 """Add results for this page to the results object.""" |
| 28 assert self._memory_stats, 'Must call Stop() first' | 62 assert self._histogram_delta_values, 'Must call Stop() first' |
| 29 if not self._memory_stats['Browser']: | 63 for h in _HISTOGRAMS: |
| 64 histogram_data = self._histogram_delta_values[h['name']] | |
| 65 results.Add(h['name'], h['units'], histogram_data, | |
| 66 data_type='unimportant-histogram') | |
| 67 | |
| 68 def AddSummaryResults(self, results): | |
| 69 """Add summary (overall) results to the results object.""" | |
| 70 self._end_memory_stats = self._browser.memory_stats | |
| 71 if not self._end_memory_stats['Browser']: | |
| 30 return | 72 return |
| 31 | 73 |
| 32 metric = 'resident_set_size' | 74 metric = 'resident_set_size' |
| 33 if sys.platform == 'win32': | 75 if sys.platform == 'win32': |
| 34 metric = 'working_set' | 76 metric = 'working_set' |
| 35 | 77 |
| 36 def AddSummariesForProcessTypes(process_types_memory, process_type_trace): | 78 def AddSummariesForProcessTypes(process_types_memory, process_type_trace): |
| 37 """Add all summaries to the results for a given set of process types. | 79 """Add all summaries to the results for a given set of process types. |
| 38 | 80 |
| 39 Args: | 81 Args: |
| 40 process_types_memory: A list of process types, e.g. Browser, 'Renderer' | 82 process_types_memory: A list of process types, e.g. Browser, 'Renderer' |
| 41 process_type_trace: The name of this set of process types in the output | 83 process_type_trace: The name of this set of process types in the output |
| 42 """ | 84 """ |
| 43 def AddSummary(value_name_memory, value_name_trace): | 85 def AddSummary(value_name_memory, value_name_trace): |
| 44 """Add a summary to the results for a given statistic. | 86 """Add a summary to the results for a given statistic. |
| 45 | 87 |
| 46 Args: | 88 Args: |
| 47 value_name_memory: Name of some statistic, e.g. VM, WorkingSetSize | 89 value_name_memory: Name of some statistic, e.g. VM, WorkingSetSize |
| 48 value_name_trace: Name of this statistic to be used in the output | 90 value_name_trace: Name of this statistic to be used in the output |
| 49 """ | 91 """ |
| 50 if len(process_types_memory) > 1 and value_name_memory.endswith('Peak'): | 92 if len(process_types_memory) > 1 and value_name_memory.endswith('Peak'): |
| 51 return | 93 return |
| 52 values = [] | 94 values = [] |
| 53 for process_type_memory in process_types_memory: | 95 for process_type_memory in process_types_memory: |
| 54 stats = self._memory_stats[process_type_memory] | 96 stats = self._end_memory_stats[process_type_memory] |
| 55 if value_name_memory in stats: | 97 if value_name_memory in stats: |
| 56 values.append(stats[value_name_memory]) | 98 values.append(stats[value_name_memory]) |
| 57 if values: | 99 if values: |
| 58 results.AddSummary(value_name_trace + process_type_trace, | 100 results.AddSummary(value_name_trace + process_type_trace, |
| 59 'bytes', sum(values), data_type='unimportant') | 101 'bytes', sum(values), data_type='unimportant') |
| 60 | 102 |
| 61 AddSummary('VM', 'vm_final_size_') | 103 AddSummary('VM', 'vm_final_size_') |
| 62 AddSummary('WorkingSetSize', 'vm_%s_final_size_' % metric) | 104 AddSummary('WorkingSetSize', 'vm_%s_final_size_' % metric) |
| 63 AddSummary('PrivateDirty', 'vm_private_dirty_final_') | 105 AddSummary('PrivateDirty', 'vm_private_dirty_final_') |
| 64 AddSummary('ProportionalSetSize', 'vm_proportional_set_size_final_') | 106 AddSummary('ProportionalSetSize', 'vm_proportional_set_size_final_') |
| 65 AddSummary('VMPeak', 'vm_peak_size_') | 107 AddSummary('VMPeak', 'vm_peak_size_') |
| 66 AddSummary('WorkingSetSizePeak', '%s_peak_size_' % metric) | 108 AddSummary('WorkingSetSizePeak', '%s_peak_size_' % metric) |
| 67 | 109 |
| 68 AddSummariesForProcessTypes(['Browser'], 'browser') | 110 AddSummariesForProcessTypes(['Browser'], 'browser') |
| 69 AddSummariesForProcessTypes(['Renderer'], 'renderer') | 111 AddSummariesForProcessTypes(['Renderer'], 'renderer') |
| 70 AddSummariesForProcessTypes(['Gpu'], 'gpu') | 112 AddSummariesForProcessTypes(['Gpu'], 'gpu') |
| 71 AddSummariesForProcessTypes(['Browser', 'Renderer', 'Gpu'], 'total') | 113 AddSummariesForProcessTypes(['Browser', 'Renderer', 'Gpu'], 'total') |
| 72 | 114 |
| 73 end_commit_charge = self._memory_stats['SystemCommitCharge'] | 115 end_commit_charge = self._end_memory_stats['SystemCommitCharge'] |
| 74 commit_charge_difference = end_commit_charge - self._start_commit_charge | 116 commit_charge_difference = end_commit_charge - self._start_commit_charge |
| 75 results.AddSummary('commit_charge', 'kb', commit_charge_difference, | 117 results.AddSummary('commit_charge', 'kb', commit_charge_difference, |
| 76 data_type='unimportant') | 118 data_type='unimportant') |
| 77 results.AddSummary('processes', 'count', self._memory_stats['ProcessCount'], | 119 results.AddSummary('processes', 'count', self._memory_stats['ProcessCount'], |
| 78 data_type='unimportant') | 120 data_type='unimportant') |
| 79 | 121 |
| OLD | NEW |