| OLD | NEW |
| 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 from metrics import memory | 5 from metrics import memory |
| 6 from telemetry.page import page_measurement | 6 from telemetry.page import page_measurement |
| 7 | 7 |
| 8 class Memory(page_measurement.PageMeasurement): | 8 class Memory(page_measurement.PageMeasurement): |
| 9 def __init__(self): | 9 def __init__(self): |
| 10 super(Memory, self).__init__('stress_memory') | 10 super(Memory, self).__init__('stress_memory') |
| 11 self._memory_metric = None | 11 self._memory_metric = None |
| 12 | 12 |
| 13 def DidStartBrowser(self, browser): | 13 def DidStartBrowser(self, browser): |
| 14 self._memory_metric = memory.MemoryMetric(browser) | 14 self._memory_metric = memory.MemoryMetric(browser) |
| 15 | 15 |
| 16 def DidNavigateToPage(self, page, tab): | 16 def DidNavigateToPage(self, page, tab): |
| 17 self._memory_metric.Start(page, tab) | 17 self._memory_metric.Start(page, tab) |
| 18 | 18 |
| 19 def CustomizeBrowserOptions(self, options): | 19 def CustomizeBrowserOptions(self, options): |
| 20 memory.MemoryMetric.CustomizeBrowserOptions(options) | 20 memory.MemoryMetric.CustomizeBrowserOptions(options) |
| 21 # Since this is a memory benchmark, we want to sample memory histograms at | 21 # Since this is a memory benchmark, we want to sample memory histograms at |
| 22 # a high frequency. | 22 # a high frequency. |
| 23 options.AppendExtraBrowserArg('--memory-metrics') | 23 options.AppendExtraBrowserArgs('--memory-metrics') |
| 24 | 24 |
| 25 def CanRunForPage(self, page): | 25 def CanRunForPage(self, page): |
| 26 return hasattr(page, 'stress_memory') | 26 return hasattr(page, 'stress_memory') |
| 27 | 27 |
| 28 def MeasurePage(self, page, tab, results): | 28 def MeasurePage(self, page, tab, results): |
| 29 self._memory_metric.Stop(page, tab) | 29 self._memory_metric.Stop(page, tab) |
| 30 self._memory_metric.AddResults(tab, results) | 30 self._memory_metric.AddResults(tab, results) |
| 31 | 31 |
| 32 if tab.browser.is_profiler_active('tcmalloc-heap'): | 32 if tab.browser.is_profiler_active('tcmalloc-heap'): |
| 33 # The tcmalloc_heap_profiler dumps files at regular | 33 # The tcmalloc_heap_profiler dumps files at regular |
| 34 # intervals (~20 secs). | 34 # intervals (~20 secs). |
| 35 # This is a minor optimization to ensure it'll dump the last file when | 35 # This is a minor optimization to ensure it'll dump the last file when |
| 36 # the test completes. | 36 # the test completes. |
| 37 tab.ExecuteJavaScript(""" | 37 tab.ExecuteJavaScript(""" |
| 38 if (chrome && chrome.memoryBenchmarking) { | 38 if (chrome && chrome.memoryBenchmarking) { |
| 39 chrome.memoryBenchmarking.heapProfilerDump('renderer', 'final'); | 39 chrome.memoryBenchmarking.heapProfilerDump('renderer', 'final'); |
| 40 chrome.memoryBenchmarking.heapProfilerDump('browser', 'final'); | 40 chrome.memoryBenchmarking.heapProfilerDump('browser', 'final'); |
| 41 } | 41 } |
| 42 """) | 42 """) |
| 43 | 43 |
| 44 def DidRunTest(self, tab, results): | 44 def DidRunTest(self, tab, results): |
| 45 self._memory_metric.AddSummaryResults(results) | 45 self._memory_metric.AddSummaryResults(results) |
| OLD | NEW |