Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(18)

Unified Diff: tools/perf/measurements/loading_profile.py

Issue 19857003: [Telemetry] Add a profiler based loading measurement. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add tests Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tools/perf/measurements/loading_measurement_analyzer.py ('k') | tools/telemetry/telemetry/core/browser.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/perf/measurements/loading_profile.py
diff --git a/tools/perf/measurements/loading_profile.py b/tools/perf/measurements/loading_profile.py
new file mode 100644
index 0000000000000000000000000000000000000000..405ee81e2d0d1c057ef0dadbd084e07ca225d4df
--- /dev/null
+++ b/tools/perf/measurements/loading_profile.py
@@ -0,0 +1,62 @@
+# Copyright (c) 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 os
+import tempfile
+
+from telemetry.core import util
+from telemetry.core.platform.profiler import perf_profiler
+from telemetry.page import page_measurement
+
+class LoadingProfile(page_measurement.PageMeasurement):
+ def __init__(self):
+ super(LoadingProfile, self).__init__(discard_first_result=True)
+
+ @property
+ def results_are_the_same_on_every_page(self):
+ return False
+
+ def AddCommandLineOptions(self, parser):
+ # In order to change the default of an option, we must remove and re-add it.
+ page_repeat_option = parser.get_option('--page-repeat')
+ page_repeat_option.default = 2
+ parser.remove_option('--page-repeat')
+ parser.add_option(page_repeat_option)
+
+ def CustomizeBrowserOptions(self, options):
+ options.AppendExtraBrowserArg('--no-sandbox')
+
+ def WillNavigateToPage(self, page, tab):
+ tab.browser.StartProfiling(perf_profiler.PerfProfiler.name(),
+ os.path.join(tempfile.mkdtemp(),
+ page.url_as_file_safe_name))
+
+ def MeasurePage(self, page, tab, results):
+ # In current telemetry tests, all tests wait for DocumentComplete state,
+ # but we need to wait for the load event.
+ def IsLoaded():
+ return bool(tab.EvaluateJavaScript('performance.timing.loadEventStart'))
+ util.WaitFor(IsLoaded, 300)
+
+ profile_files = tab.browser.StopProfiling()
+
+ load_timings = tab.EvaluateJavaScript('window.performance.timing')
+ load_time_ms = (
+ float(load_timings['loadEventStart']) -
+ load_timings['navigationStart'])
+ dom_content_loaded_time_ms = (
+ float(load_timings['domContentLoadedEventStart']) -
+ load_timings['navigationStart'])
+ results.Add('load_time', 'ms', load_time_ms)
+ results.Add('dom_content_loaded_time', 'ms',
+ dom_content_loaded_time_ms)
+
+ profile_file = None
+ for profile_file in profile_files:
+ if 'renderer' in profile_file:
+ break
+
+ for function, period in perf_profiler.PerfProfiler.GetTopSamples(
+ profile_file, 10).iteritems():
+ results.Add(function.replace('.', '_'), 'period', period)
« no previous file with comments | « tools/perf/measurements/loading_measurement_analyzer.py ('k') | tools/telemetry/telemetry/core/browser.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698