summaryrefslogtreecommitdiffstats
path: root/tools/perf
diff options
context:
space:
mode:
authoredmundyan@chromium.org <edmundyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 17:51:59 +0000
committeredmundyan@chromium.org <edmundyan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-09-10 17:51:59 +0000
commit9a506fbbe3548dc8e3c47cfe237da67b2c966dde (patch)
treebe26df7bfd1ff5ac4d5ec6c06504145a09c00185 /tools/perf
parente2a1dd6a86aea6651fecbbce9a2b44336f5befcd (diff)
downloadchromium_src-9a506fbbe3548dc8e3c47cfe237da67b2c966dde.zip
chromium_src-9a506fbbe3548dc8e3c47cfe237da67b2c966dde.tar.gz
chromium_src-9a506fbbe3548dc8e3c47cfe237da67b2c966dde.tar.bz2
New Cpu metric that calculates avg cpu_load of the browser over a span of time using browser.cpu_stats. Added this metric to tab_switching measurement to get idle-cpu usage of the browser
TEST=tools/perf/run_measurement tab_switching tools/perf/page_sets/top_10.json BUG=264075 Review URL: https://chromiumcodereview.appspot.com/23645006 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@222303 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'tools/perf')
-rw-r--r--tools/perf/measurements/tab_switching.py25
-rw-r--r--tools/perf/metrics/cpu.py55
2 files changed, 78 insertions, 2 deletions
diff --git a/tools/perf/measurements/tab_switching.py b/tools/perf/measurements/tab_switching.py
index 19eb1de..6342673 100644
--- a/tools/perf/measurements/tab_switching.py
+++ b/tools/perf/measurements/tab_switching.py
@@ -9,6 +9,9 @@ it cycles through each tab in sequence, and records a histogram of the time
between when a tab was first requested to be shown, and when it was painted.
"""
+import time
+
+from metrics import cpu
from metrics import histogram_util
from telemetry.core import util
from telemetry.page import page_measurement
@@ -17,6 +20,10 @@ from telemetry.page import page_runner
# TODO: Revisit this test once multitab support is finalized.
class TabSwitching(page_measurement.PageMeasurement):
+ def __init__(self):
+ super(TabSwitching, self).__init__()
+ self._cpu_metric = None
+
def CustomizeBrowserOptions(self, options):
options.AppendExtraBrowserArgs([
'--enable-stats-collection-bindings',
@@ -24,6 +31,9 @@ class TabSwitching(page_measurement.PageMeasurement):
'--reduce-security-for-dom-automation-tests'
])
+ def DidStartBrowser(self, browser):
+ self._cpu_metric = cpu.Cpu(browser)
+
def CanRunForPage(self, page):
return not page.page_set.pages.index(page)
@@ -31,15 +41,26 @@ class TabSwitching(page_measurement.PageMeasurement):
for i in xrange(1, len(page.page_set.pages)):
t = tab.browser.tabs.New()
+ # We create a test_stub to be able to call 'navigate_steps' on pages
+ test_stub = page_measurement.PageMeasurement()
page_state = page_runner.PageState()
page_state.PreparePage(page.page_set.pages[i], t)
- page_state.ImplicitPageNavigation(page.page_set.pages[i], t)
+ page_state.ImplicitPageNavigation(page.page_set.pages[i], t, test_stub)
- def MeasurePage(self, _, tab, results):
+ # Start tracking cpu load after all pages have loaded.
+ self._cpu_metric.Start(page, tab)
+
+ def MeasurePage(self, page, tab, results):
"""Although this is called MeasurePage, we're actually using this function
to cycle through each tab that was opened via DidNavigateToPage and
then record a single histogram for the tab switching metric.
"""
+ # Calculate the idle cpu load before any actions are done.
+ time.sleep(.5)
+ self._cpu_metric.Stop(page, tab)
+ self._cpu_metric.AddResults(tab, results,
+ 'idle_cpu_utilization')
+
histogram_name = 'MPArch.RWH_TabSwitchPaintDuration'
histogram_type = histogram_util.BROWSER_HISTOGRAM
first_histogram = histogram_util.GetHistogramFromDomAutomation(
diff --git a/tools/perf/metrics/cpu.py b/tools/perf/metrics/cpu.py
new file mode 100644
index 0000000..18a9c80
--- /dev/null
+++ b/tools/perf/metrics/cpu.py
@@ -0,0 +1,55 @@
+# 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.
+
+from metrics import Metric
+
+class Cpu(Metric):
+ """Calulates CPU load over a span of time."""
+
+ def __init__(self, browser):
+ super(Cpu, self).__init__()
+ self._results = None
+ self._browser = browser
+ self.start_cpu = None
+
+ def DidStartBrowser(self, browser):
+ # Save the browser for cpu_stats.
+ self._browser = browser
+
+ def Start(self, page, tab):
+ self.start_cpu = self._browser.cpu_stats
+
+ def Stop(self, page, tab):
+ assert self.start_cpu != None, 'Must call Start() first'
+ self._results = Cpu.SubtractCpuStats(self._browser.cpu_stats,
+ self.start_cpu)
+
+ # pylint: disable=W0221
+ def AddResults(self, tab, results, trace_name='cpu_utilization'):
+ assert self._results != None, 'Must call Stop() first'
+ for process_type in self._results:
+ results.Add(trace_name + '_%s' % process_type.lower(),
+ '%',
+ self._results[process_type]['CpuPercent'],
+ chart_name='cpu_utilization',
+ data_type='unimportant')
+
+ @staticmethod
+ def SubtractCpuStats(cpu_stats, start_cpu_stats):
+ """Returns difference of a previous cpu_stats from a cpu_stats."""
+ diff = {}
+ for process_type in cpu_stats:
+ assert process_type in start_cpu_stats, 'Mismatching process types'
+ # Skip any process_types that are empty.
+ if (not len(cpu_stats[process_type]) or
+ not len(start_cpu_stats[process_type])):
+ continue
+ cpu_process_time = (cpu_stats[process_type]['CpuProcessTime'] -
+ start_cpu_stats[process_type]['CpuProcessTime'])
+ total_time = (cpu_stats[process_type]['TotalTime'] -
+ start_cpu_stats[process_type]['TotalTime'])
+ assert total_time > 0
+ cpu_percent = 100 * cpu_process_time / total_time
+ diff[process_type] = {'CpuPercent': cpu_percent}
+ return diff