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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 assert self._histogram_start, 'Must call Start() first' | 70 assert self._histogram_start, 'Must call Start() first' |
71 for h in _HISTOGRAMS: | 71 for h in _HISTOGRAMS: |
72 # Histogram data may not be available | 72 # Histogram data may not be available |
73 if h['name'] not in self._histogram_start: | 73 if h['name'] not in self._histogram_start: |
74 continue | 74 continue |
75 histogram_data = histogram_util.GetHistogram( | 75 histogram_data = histogram_util.GetHistogram( |
76 h['type'], h['name'], tab) | 76 h['type'], h['name'], tab) |
77 self._histogram_delta[h['name']] = histogram_util.SubtractHistogram( | 77 self._histogram_delta[h['name']] = histogram_util.SubtractHistogram( |
78 histogram_data, self._histogram_start[h['name']]) | 78 histogram_data, self._histogram_start[h['name']]) |
79 | 79 |
80 # Optional argument trace_name is not in base class Metric. | 80 def AddResults(self, tab, results): |
81 # pylint: disable=W0221 | |
82 def AddResults(self, tab, results, trace_name=None): | |
83 """Add results for this page to the results object.""" | 81 """Add results for this page to the results object.""" |
84 assert self._histogram_delta, 'Must call Stop() first' | 82 assert self._histogram_delta, 'Must call Stop() first' |
85 for h in _HISTOGRAMS: | 83 for h in _HISTOGRAMS: |
86 # Histogram data may not be available | 84 # Histogram data may not be available |
87 if h['name'] not in self._histogram_start: | 85 if h['name'] not in self._histogram_start: |
88 continue | 86 continue |
89 results.Add(h['name'], h['units'], self._histogram_delta[h['name']], | 87 results.Add(h['name'], h['units'], self._histogram_delta[h['name']], |
90 data_type='unimportant-histogram') | 88 data_type='unimportant-histogram') |
| 89 |
| 90 def AddSummaryResults(self, results, trace_name=None): |
| 91 """Add summary (overall) results to the results object.""" |
91 self._memory_stats = self._browser.memory_stats | 92 self._memory_stats = self._browser.memory_stats |
92 if not self._memory_stats['Browser']: | 93 if not self._memory_stats['Browser']: |
93 return | 94 return |
94 | 95 |
95 metric = 'resident_set_size' | 96 metric = 'resident_set_size' |
96 if sys.platform == 'win32': | 97 if sys.platform == 'win32': |
97 metric = 'working_set' | 98 metric = 'working_set' |
98 | 99 |
99 def AddResultsForProcessTypes(process_types_memory, process_type_trace): | 100 def AddSummariesForProcessTypes(process_types_memory, process_type_trace): |
100 """Add all results for a given set of process types. | 101 """Add all summaries to the results for a given set of process types. |
101 | 102 |
102 Args: | 103 Args: |
103 process_types_memory: A list of process types, e.g. Browser, 'Renderer' | 104 process_types_memory: A list of process types, e.g. Browser, 'Renderer' |
104 process_type_trace: The name of this set of process types in the output | 105 process_type_trace: The name of this set of process types in the output |
105 """ | 106 """ |
106 def AddResult(value_name_memory, value_name_trace): | 107 def AddSummary(value_name_memory, value_name_trace): |
107 """Add a result for a given statistic. | 108 """Add a summary to the results for a given statistic. |
108 | 109 |
109 Args: | 110 Args: |
110 value_name_memory: Name of some statistic, e.g. VM, WorkingSetSize | 111 value_name_memory: Name of some statistic, e.g. VM, WorkingSetSize |
111 value_name_trace: Name of this statistic to be used in the output | 112 value_name_trace: Name of this statistic to be used in the output |
112 """ | 113 """ |
113 if len(process_types_memory) > 1 and value_name_memory.endswith('Peak'): | 114 if len(process_types_memory) > 1 and value_name_memory.endswith('Peak'): |
114 return | 115 return |
115 values = [] | 116 values = [] |
116 for process_type_memory in process_types_memory: | 117 for process_type_memory in process_types_memory: |
117 stats = self._memory_stats[process_type_memory] | 118 stats = self._memory_stats[process_type_memory] |
118 if value_name_memory in stats: | 119 if value_name_memory in stats: |
119 values.append(stats[value_name_memory]) | 120 values.append(stats[value_name_memory]) |
120 if values: | 121 if values: |
121 if trace_name: | 122 if trace_name: |
122 current_trace = '%s_%s' % (trace_name, process_type_trace) | 123 current_trace = '%s_%s' % (trace_name, process_type_trace) |
123 chart_name = value_name_trace | 124 chart_name = value_name_trace |
124 else: | 125 else: |
125 current_trace = '%s_%s' % (value_name_trace, process_type_trace) | 126 current_trace = '%s_%s' % (value_name_trace, process_type_trace) |
126 chart_name = current_trace | 127 chart_name = current_trace |
127 results.Add(current_trace, 'bytes', sum(values), | 128 results.AddSummary(current_trace, 'bytes', sum(values), |
128 chart_name=chart_name, data_type='unimportant') | 129 chart_name=chart_name, data_type='unimportant') |
129 | 130 |
130 AddResult('VM', 'vm_final_size') | 131 AddSummary('VM', 'vm_final_size') |
131 AddResult('WorkingSetSize', 'vm_%s_final_size' % metric) | 132 AddSummary('WorkingSetSize', 'vm_%s_final_size' % metric) |
132 AddResult('PrivateDirty', 'vm_private_dirty_final') | 133 AddSummary('PrivateDirty', 'vm_private_dirty_final') |
133 AddResult('ProportionalSetSize', 'vm_proportional_set_size_final') | 134 AddSummary('ProportionalSetSize', 'vm_proportional_set_size_final') |
134 AddResult('SharedDirty', 'vm_shared_dirty_final') | 135 AddSummary('SharedDirty', 'vm_shared_dirty_final') |
135 AddResult('VMPeak', 'vm_peak_size') | 136 AddSummary('VMPeak', 'vm_peak_size') |
136 AddResult('WorkingSetSizePeak', '%s_peak_size' % metric) | 137 AddSummary('WorkingSetSizePeak', '%s_peak_size' % metric) |
137 | 138 |
138 AddResultsForProcessTypes(['Browser'], 'browser') | 139 AddSummariesForProcessTypes(['Browser'], 'browser') |
139 AddResultsForProcessTypes(['Renderer'], 'renderer') | 140 AddSummariesForProcessTypes(['Renderer'], 'renderer') |
140 AddResultsForProcessTypes(['Gpu'], 'gpu') | 141 AddSummariesForProcessTypes(['Gpu'], 'gpu') |
141 AddResultsForProcessTypes(['Browser', 'Renderer', 'Gpu'], 'total') | 142 AddSummariesForProcessTypes(['Browser', 'Renderer', 'Gpu'], 'total') |
142 | 143 |
143 end_commit_charge = self._memory_stats['SystemCommitCharge'] | 144 end_commit_charge = self._memory_stats['SystemCommitCharge'] |
144 commit_charge_difference = end_commit_charge - self._start_commit_charge | 145 commit_charge_difference = end_commit_charge - self._start_commit_charge |
145 results.Add(trace_name or 'commit_charge', 'kb', | 146 results.AddSummary(trace_name or 'commit_charge', 'kb', |
146 commit_charge_difference, | 147 commit_charge_difference, |
147 chart_name='commit_charge', | 148 chart_name='commit_charge', |
148 data_type='unimportant') | 149 data_type='unimportant') |
149 results.Add(trace_name or 'processes', 'count', | 150 results.AddSummary(trace_name or 'processes', 'count', |
150 self._memory_stats['ProcessCount'], | 151 self._memory_stats['ProcessCount'], |
151 chart_name='processes', | 152 chart_name='processes', |
152 data_type='unimportant') | 153 data_type='unimportant') |
| 154 |
OLD | NEW |