1 # Copyright (c) 2012 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.
5 from metrics
import memory
6 from metrics
import power
7 from telemetry
.page
import page_measurement
9 class Memory(page_measurement
.PageMeasurement
):
11 super(Memory
, self
).__init
__('stress_memory')
12 self
._memory
_metric
= None
13 self
._power
_metric
= power
.PowerMetric()
15 def DidStartBrowser(self
, browser
):
16 self
._memory
_metric
= memory
.MemoryMetric(browser
)
18 def DidNavigateToPage(self
, page
, tab
):
19 self
._memory
_metric
.Start(page
, tab
)
20 self
._power
_metric
.Start(page
, tab
)
22 def CustomizeBrowserOptions(self
, options
):
23 memory
.MemoryMetric
.CustomizeBrowserOptions(options
)
24 # Since this is a memory benchmark, we want to sample memory histograms at
26 options
.AppendExtraBrowserArgs('--memory-metrics')
28 def CanRunForPage(self
, page
):
29 return hasattr(page
, 'stress_memory')
31 def MeasurePage(self
, page
, tab
, results
):
32 self
._power
_metric
.Stop(page
, tab
)
33 self
._memory
_metric
.Stop(page
, tab
)
34 self
._memory
_metric
.AddResults(tab
, results
)
35 self
._power
_metric
.AddResults(tab
, results
)
37 if tab
.browser
.is_profiler_active('tcmalloc-heap'):
38 # The tcmalloc_heap_profiler dumps files at regular
39 # intervals (~20 secs).
40 # This is a minor optimization to ensure it'll dump the last file when
42 tab
.ExecuteJavaScript("""
43 if (chrome && chrome.memoryBenchmarking) {
44 chrome.memoryBenchmarking.heapProfilerDump('renderer', 'final');
45 chrome.memoryBenchmarking.heapProfilerDump('browser', 'final');