Chromium Code Reviews| Index: tools/perf/metrics/memory.py |
| diff --git a/tools/perf/metrics/memory.py b/tools/perf/metrics/memory.py |
| index cbc0660e548b9916c8ceaf254ab37ac905eef99e..d35ad6f62546d045cf22ba5338c361a3338355c1 100644 |
| --- a/tools/perf/metrics/memory.py |
| +++ b/tools/perf/metrics/memory.py |
| @@ -1,32 +1,74 @@ |
| # Copyright 2013 The Chromium Authors. All rights reserved. |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file. |
| + |
| import sys |
| from metrics import Metric |
| +from metrics import histogram |
| + |
| +_HISTOGRAMS = [ |
| + {'name': 'V8.MemoryExternalFragmentationTotal', 'units': 'percent', |
| + 'type': histogram.MEMORY_HISTOGRAM}, |
| + {'name': 'V8.MemoryHeapSampleTotalCommitted', 'units': 'kb', |
| + 'type': histogram.MEMORY_HISTOGRAM}, |
| + {'name': 'V8.MemoryHeapSampleTotalUsed', 'units': 'kb', |
| + 'type': histogram.MEMORY_HISTOGRAM}, |
| + {'name': 'Memory.RendererUsed', 'units': 'kb', |
| + 'type': histogram.MEMORY_HISTOGRAM}, |
| + {'name': 'Memory.BrowserUsed', 'units': 'kb', |
| + 'type': histogram.BROWSER_HISTOGRAM}] |
|
qyearsley
2013/08/08 17:35:52
I also put the histogram type into each list item
|
| class MemoryMetric(Metric): |
| - """MemoryMetric gathers memory statistics from the browser object.""" |
| + """MemoryMetric gathers memory statistics from the browser object. |
| + |
| + This includes both per-page histogram stats, most about javascript |
| + memory usage, and overall memory stats from the system for the whole |
| + test run.""" |
| def __init__(self, browser): |
| super(MemoryMetric, self).__init__() |
| self._browser = browser |
| - self._memory_stats = None |
| - self._start_commit_charge = None |
| - |
| - def Start(self, page=None, tab=None): |
| - """Record the initial value of 'SystemCommitCharge'.""" |
| self._start_commit_charge = self._browser.memory_stats['SystemCommitCharge'] |
| + self._end_memory_stats = None |
| + self._histogram_start_values = dict() |
| + self._histogram_delta_values = dict() |
| - def Stop(self, page=None, tab=None): |
| - """Fetch the browser memory stats.""" |
| - assert self._start_commit_charge, 'Must call Start() first' |
| - self._memory_stats = self._browser.memory_stats |
| + def Start(self, page, tab): |
| + """Start the per-page preparation for this metric. |
| + |
| + Here, this consists of recording the start value of all the histograms. |
| + """ |
| + for h in _HISTOGRAMS: |
| + histogram_data = histogram.GetHistogramData(h['type'], h['name'], tab) |
| + if not histogram_data: |
| + continue |
| + self._histogram_start_values[h['name']] = histogram_data |
| + |
| + def Stop(self, page, tab): |
| + """Prepare the results for this page. |
| + |
| + The results are the differences between the current histogram values |
| + and the values when Start() was called. |
| + """ |
| + assert self._histogram_start_values, 'Must call Start() first' |
| + for h in _HISTOGRAMS: |
| + histogram_data = histogram.GetHistogramData(h['type'], h['name'], tab) |
| + self._histogram_delta_values = histogram.SubtractHistogram( |
| + histogram_data, self._histogram_start_values[h['name']]) |
| def AddResults(self, tab, results): |
| - """Add summary results to the results object.""" |
| - assert self._memory_stats, 'Must call Stop() first' |
| - if not self._memory_stats['Browser']: |
| + """Add results for this page to the results object.""" |
| + assert self._histogram_delta_values, 'Must call Stop() first' |
| + for h in _HISTOGRAMS: |
| + histogram_data = self._histogram_delta_values[h['name']] |
| + results.Add(h['name'], h['units'], histogram_data, |
| + data_type='unimportant-histogram') |
| + |
| + def AddSummaryResults(self, results): |
| + """Add summary (overall) results to the results object.""" |
| + self._end_memory_stats = self._browser.memory_stats |
| + if not self._end_memory_stats['Browser']: |
| return |
| metric = 'resident_set_size' |
| @@ -51,7 +93,7 @@ class MemoryMetric(Metric): |
| return |
| values = [] |
| for process_type_memory in process_types_memory: |
| - stats = self._memory_stats[process_type_memory] |
| + stats = self._end_memory_stats[process_type_memory] |
| if value_name_memory in stats: |
| values.append(stats[value_name_memory]) |
| if values: |
| @@ -70,7 +112,7 @@ class MemoryMetric(Metric): |
| AddSummariesForProcessTypes(['Gpu'], 'gpu') |
| AddSummariesForProcessTypes(['Browser', 'Renderer', 'Gpu'], 'total') |
| - end_commit_charge = self._memory_stats['SystemCommitCharge'] |
| + end_commit_charge = self._end_memory_stats['SystemCommitCharge'] |
| commit_charge_difference = end_commit_charge - self._start_commit_charge |
| results.AddSummary('commit_charge', 'kb', commit_charge_difference, |
| data_type='unimportant') |