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 |
5 import sys | 5 import sys |
6 | 6 |
7 from metrics import histogram_util | 7 from metrics import histogram_util |
8 from metrics import Metric | 8 from metrics import Metric |
9 | 9 |
10 _HISTOGRAMS = [ | 10 _HISTOGRAMS = [ |
(...skipping 20 matching lines...) Expand all Loading... |
31 self._browser = browser | 31 self._browser = browser |
32 self._start_commit_charge = self._browser.memory_stats['SystemCommitCharge'] | 32 self._start_commit_charge = self._browser.memory_stats['SystemCommitCharge'] |
33 self._memory_stats = None | 33 self._memory_stats = None |
34 self._histogram_start = dict() | 34 self._histogram_start = dict() |
35 self._histogram_delta = dict() | 35 self._histogram_delta = dict() |
36 | 36 |
37 @classmethod | 37 @classmethod |
38 def CustomizeBrowserOptions(cls, options): | 38 def CustomizeBrowserOptions(cls, options): |
39 options.AppendExtraBrowserArgs([ | 39 options.AppendExtraBrowserArgs([ |
40 '--enable-stats-collection-bindings', | 40 '--enable-stats-collection-bindings', |
41 '--enable-memory-benchmarking', | |
42 # For a hard-coded set of Google pages (such as GMail), we produce | 41 # For a hard-coded set of Google pages (such as GMail), we produce |
43 # custom memory histograms (V8.Something_gmail) instead of the generic | 42 # custom memory histograms (V8.Something_gmail) instead of the generic |
44 # histograms (V8.Something), if we detect that a renderer is only | 43 # histograms (V8.Something), if we detect that a renderer is only |
45 # rendering this page and no other pages. For this test, we need to | 44 # rendering this page and no other pages. For this test, we need to |
46 # disable histogram customizing, so that we get the same generic | 45 # disable histogram customizing, so that we get the same generic |
47 # histograms produced for all pages. | 46 # histograms produced for all pages. |
48 '--disable-histogram-customizer' | 47 '--disable-histogram-customizer' |
49 ]) | 48 ]) |
50 | 49 |
51 def Start(self, page, tab): | 50 def Start(self, page, tab): |
(...skipping 18 matching lines...) Expand all Loading... |
70 assert self._histogram_start, 'Must call Start() first' | 69 assert self._histogram_start, 'Must call Start() first' |
71 for h in _HISTOGRAMS: | 70 for h in _HISTOGRAMS: |
72 # Histogram data may not be available | 71 # Histogram data may not be available |
73 if h['name'] not in self._histogram_start: | 72 if h['name'] not in self._histogram_start: |
74 continue | 73 continue |
75 histogram_data = histogram_util.GetHistogram( | 74 histogram_data = histogram_util.GetHistogram( |
76 h['type'], h['name'], tab) | 75 h['type'], h['name'], tab) |
77 self._histogram_delta[h['name']] = histogram_util.SubtractHistogram( | 76 self._histogram_delta[h['name']] = histogram_util.SubtractHistogram( |
78 histogram_data, self._histogram_start[h['name']]) | 77 histogram_data, self._histogram_start[h['name']]) |
79 | 78 |
80 def AddResults(self, tab, results): | 79 # Optional argument trace_name is not in base class Metric. |
| 80 # pylint: disable=W0221 |
| 81 def AddResults(self, tab, results, trace_name=None): |
81 """Add results for this page to the results object.""" | 82 """Add results for this page to the results object.""" |
82 assert self._histogram_delta, 'Must call Stop() first' | 83 assert self._histogram_delta, 'Must call Stop() first' |
83 for h in _HISTOGRAMS: | 84 for h in _HISTOGRAMS: |
84 # Histogram data may not be available | 85 # Histogram data may not be available |
85 if h['name'] not in self._histogram_start: | 86 if h['name'] not in self._histogram_start: |
86 continue | 87 continue |
87 results.Add(h['name'], h['units'], self._histogram_delta[h['name']], | 88 results.Add(h['name'], h['units'], self._histogram_delta[h['name']], |
88 data_type='unimportant-histogram') | 89 data_type='unimportant-histogram') |
89 | |
90 def AddSummaryResults(self, results, trace_name=None): | |
91 """Add summary (overall) results to the results object.""" | |
92 self._memory_stats = self._browser.memory_stats | 90 self._memory_stats = self._browser.memory_stats |
93 if not self._memory_stats['Browser']: | 91 if not self._memory_stats['Browser']: |
94 return | 92 return |
95 | 93 |
96 metric = 'resident_set_size' | 94 metric = 'resident_set_size' |
97 if sys.platform == 'win32': | 95 if sys.platform == 'win32': |
98 metric = 'working_set' | 96 metric = 'working_set' |
99 | 97 |
100 def AddSummariesForProcessTypes(process_types_memory, process_type_trace): | 98 def AddResultsForProcessTypes(process_types_memory, process_type_trace): |
101 """Add all summaries to the results for a given set of process types. | 99 """Add all results for a given set of process types. |
102 | 100 |
103 Args: | 101 Args: |
104 process_types_memory: A list of process types, e.g. Browser, 'Renderer' | 102 process_types_memory: A list of process types, e.g. Browser, 'Renderer' |
105 process_type_trace: The name of this set of process types in the output | 103 process_type_trace: The name of this set of process types in the output |
106 """ | 104 """ |
107 def AddSummary(value_name_memory, value_name_trace): | 105 def AddResult(value_name_memory, value_name_trace): |
108 """Add a summary to the results for a given statistic. | 106 """Add a result for a given statistic. |
109 | 107 |
110 Args: | 108 Args: |
111 value_name_memory: Name of some statistic, e.g. VM, WorkingSetSize | 109 value_name_memory: Name of some statistic, e.g. VM, WorkingSetSize |
112 value_name_trace: Name of this statistic to be used in the output | 110 value_name_trace: Name of this statistic to be used in the output |
113 """ | 111 """ |
114 if len(process_types_memory) > 1 and value_name_memory.endswith('Peak'): | 112 if len(process_types_memory) > 1 and value_name_memory.endswith('Peak'): |
115 return | 113 return |
116 values = [] | 114 values = [] |
117 for process_type_memory in process_types_memory: | 115 for process_type_memory in process_types_memory: |
118 stats = self._memory_stats[process_type_memory] | 116 stats = self._memory_stats[process_type_memory] |
119 if value_name_memory in stats: | 117 if value_name_memory in stats: |
120 values.append(stats[value_name_memory]) | 118 values.append(stats[value_name_memory]) |
121 if values: | 119 if values: |
122 if trace_name: | 120 if trace_name: |
123 current_trace = '%s_%s' % (trace_name, process_type_trace) | 121 current_trace = '%s_%s' % (trace_name, process_type_trace) |
124 chart_name = value_name_trace | 122 chart_name = value_name_trace |
125 else: | 123 else: |
126 current_trace = '%s_%s' % (value_name_trace, process_type_trace) | 124 current_trace = '%s_%s' % (value_name_trace, process_type_trace) |
127 chart_name = current_trace | 125 chart_name = current_trace |
128 results.AddSummary(current_trace, 'bytes', sum(values), | 126 results.Add(current_trace, 'bytes', sum(values), |
129 chart_name=chart_name, data_type='unimportant') | 127 chart_name=chart_name, data_type='unimportant') |
130 | 128 |
131 AddSummary('VM', 'vm_final_size') | 129 AddResult('VM', 'vm_final_size') |
132 AddSummary('WorkingSetSize', 'vm_%s_final_size' % metric) | 130 AddResult('WorkingSetSize', 'vm_%s_final_size' % metric) |
133 AddSummary('PrivateDirty', 'vm_private_dirty_final') | 131 AddResult('PrivateDirty', 'vm_private_dirty_final') |
134 AddSummary('ProportionalSetSize', 'vm_proportional_set_size_final') | 132 AddResult('ProportionalSetSize', 'vm_proportional_set_size_final') |
135 AddSummary('SharedDirty', 'vm_shared_dirty_final') | 133 AddResult('SharedDirty', 'vm_shared_dirty_final') |
136 AddSummary('VMPeak', 'vm_peak_size') | 134 AddResult('VMPeak', 'vm_peak_size') |
137 AddSummary('WorkingSetSizePeak', '%s_peak_size' % metric) | 135 AddResult('WorkingSetSizePeak', '%s_peak_size' % metric) |
138 | 136 |
139 AddSummariesForProcessTypes(['Browser'], 'browser') | 137 AddResultsForProcessTypes(['Browser'], 'browser') |
140 AddSummariesForProcessTypes(['Renderer'], 'renderer') | 138 AddResultsForProcessTypes(['Renderer'], 'renderer') |
141 AddSummariesForProcessTypes(['Gpu'], 'gpu') | 139 AddResultsForProcessTypes(['Gpu'], 'gpu') |
142 AddSummariesForProcessTypes(['Browser', 'Renderer', 'Gpu'], 'total') | 140 AddResultsForProcessTypes(['Browser', 'Renderer', 'Gpu'], 'total') |
143 | 141 |
144 end_commit_charge = self._memory_stats['SystemCommitCharge'] | 142 end_commit_charge = self._memory_stats['SystemCommitCharge'] |
145 commit_charge_difference = end_commit_charge - self._start_commit_charge | 143 commit_charge_difference = end_commit_charge - self._start_commit_charge |
146 results.AddSummary(trace_name or 'commit_charge', 'kb', | 144 results.Add(trace_name or 'commit_charge', 'kb', |
147 commit_charge_difference, | 145 commit_charge_difference, |
148 chart_name='commit_charge', | 146 chart_name='commit_charge', |
149 data_type='unimportant') | 147 data_type='unimportant') |
150 results.AddSummary(trace_name or 'processes', 'count', | 148 results.Add(trace_name or 'processes', 'count', |
151 self._memory_stats['ProcessCount'], | 149 self._memory_stats['ProcessCount'], |
152 chart_name='processes', | 150 chart_name='processes', |
153 data_type='unimportant') | 151 data_type='unimportant') |
154 | |
OLD | NEW |