Commit e2eeedb8 authored by Ehsan Chiniforooshan's avatar Ehsan Chiniforooshan Committed by Commit Bot

Telemetry: clean up unused metrics

Change-Id: I9f539e61174d0aa23767e9de9107b5fa8c606418
Reviewed-on: https://chromium-review.googlesource.com/c/1323690Reviewed-by: default avatarNed Nguyen <nednguyen@google.com>
Reviewed-by: default avatarTarun Bansal <tbansal@chromium.org>
Commit-Queue: Ehsan Chiniforooshan <chiniforooshan@chromium.org>
Cr-Commit-Position: refs/heads/master@{#606644}
parent fee9f198
...@@ -9,7 +9,6 @@ import urlparse ...@@ -9,7 +9,6 @@ import urlparse
from common import chrome_proxy_measurements as measurements from common import chrome_proxy_measurements as measurements
from common.chrome_proxy_measurements import ChromeProxyValidation from common.chrome_proxy_measurements import ChromeProxyValidation
from integration_tests import chrome_proxy_metrics as metrics from integration_tests import chrome_proxy_metrics as metrics
from metrics import loading
from telemetry.core import exceptions, util from telemetry.core import exceptions, util
from telemetry.page import legacy_page_test from telemetry.page import legacy_page_test
......
# 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 logging
from telemetry.value import scalar
from metrics import Metric
class CpuMetric(Metric):
"""Calculates CPU load over a span of time."""
def __init__(self, browser):
super(CpuMetric, self).__init__()
self._browser = browser
self._start_cpu = None
self._stop_cpu = None
def DidStartBrowser(self, browser):
# Save the browser object so that cpu_stats can be accessed later.
self._browser = browser
def Start(self, page, tab):
if not self._browser.supports_cpu_metrics:
logging.warning('CPU metrics not supported.')
return
self._start_cpu = self._browser.cpu_stats
def Stop(self, page, tab):
if not self._browser.supports_cpu_metrics:
return
assert self._start_cpu, 'Must call Start() first'
self._stop_cpu = self._browser.cpu_stats
# Optional argument trace_name is not in base class Metric.
# pylint: disable=arguments-differ
def AddResults(self, tab, results, trace_name='cpu_utilization'):
if not self._browser.supports_cpu_metrics:
return
assert self._stop_cpu, 'Must call Stop() first'
cpu_stats = _SubtractCpuStats(self._stop_cpu, self._start_cpu)
# FIXME: Renderer process CPU times are impossible to compare correctly.
# http://crbug.com/419786#c11
if 'Renderer' in cpu_stats:
del cpu_stats['Renderer']
# Add a result for each process type.
for process_type in cpu_stats:
trace_name_for_process = '%s_%s' % (trace_name, process_type.lower())
cpu_percent = 100 * cpu_stats[process_type]
results.AddValue(scalar.ScalarValue(
results.current_page, 'cpu_utilization.%s' % trace_name_for_process,
'%', cpu_percent, important=False))
def _SubtractCpuStats(cpu_stats, start_cpu_stats):
"""Computes average cpu usage over a time period for different process types.
Each of the two cpu_stats arguments is a dict with the following format:
{'Browser': {'CpuProcessTime': ..., 'TotalTime': ...},
'Renderer': {'CpuProcessTime': ..., 'TotalTime': ...}
'Gpu': {'CpuProcessTime': ..., 'TotalTime': ...}}
The 'CpuProcessTime' fields represent the number of seconds of CPU time
spent in each process, and total time is the number of real seconds
that have passed (this may be a Unix timestamp).
Returns:
A dict of process type names (Browser, Renderer, etc.) to ratios of cpu
time used to total time elapsed.
"""
cpu_usage = {}
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 cpu_stats[process_type]) or (not 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'])
# Fix overflow for 32-bit jiffie counter, 64-bit counter will not overflow.
# Linux kernel starts with a value close to an overflow, so correction is
# necessary. Assume jiffie counter is at 100 Hz.
if total_time < 0:
total_time += 2 ** 32 / 100.
# Assert that the arguments were given in the correct order.
assert total_time > 0 and total_time < 2 ** 31 / 100., (
'Expected total_time > 0, was: %d' % total_time)
cpu_usage[process_type] = float(cpu_process_time) / total_time
return cpu_usage
# 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 unittest
from metrics import cpu
# Testing private method.
# pylint: disable=protected-access
class CpuMetricTest(unittest.TestCase):
def testSubtractCpuStats(self):
# The result computed is a ratio of cpu time used to time elapsed.
start = {'Browser': {'CpuProcessTime': 0, 'TotalTime': 0}}
end = {'Browser': {'CpuProcessTime': 5, 'TotalTime': 20}}
self.assertEqual({'Browser': 0.25}, cpu._SubtractCpuStats(end, start))
# An error is thrown if the args are called in the wrong order.
self.assertRaises(AssertionError, cpu._SubtractCpuStats, start, end)
# An error is thrown if there's a process type in end that's not in start.
end['Renderer'] = {'CpuProcessTime': 2, 'TotalTime': 20}
self.assertRaises(AssertionError, cpu._SubtractCpuStats, end, start)
# A process type will be ignored if there's an empty dict for start or end.
start['Renderer'] = {}
self.assertEqual({'Browser': 0.25}, cpu._SubtractCpuStats(end, start))
# Results for multiple process types can be computed.
start['Renderer'] = {'CpuProcessTime': 0, 'TotalTime': 0}
self.assertEqual({'Browser': 0.25, 'Renderer': 0.1},
cpu._SubtractCpuStats(end, start))
# Test 32-bit overflow.
start = {'Browser': {'CpuProcessTime': 0, 'TotalTime': 2 ** 32 / 100. - 20}}
end = {'Browser': {'CpuProcessTime': 5, 'TotalTime': 20}}
self.assertEqual({'Browser': 0.125}, cpu._SubtractCpuStats(end, start))
self.assertRaises(AssertionError, cpu._SubtractCpuStats, start, end)
# 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 telemetry.value import scalar
from metrics import Metric
class LoadingMetric(Metric):
"""A metric for page loading time based entirely on window.performance"""
def Start(self, page, tab):
raise NotImplementedError()
def Stop(self, page, tab):
raise NotImplementedError()
def AddResults(self, tab, results):
load_timings = tab.EvaluateJavaScript('window.performance.timing')
# NavigationStart relative markers in milliseconds.
load_start = (
float(load_timings['loadEventStart']) - load_timings['navigationStart'])
results.AddValue(scalar.ScalarValue(
results.current_page, 'load_start', 'ms', load_start))
dom_content_loaded_start = (
float(load_timings['domContentLoadedEventStart']) -
load_timings['navigationStart'])
results.AddValue(scalar.ScalarValue(
results.current_page, 'dom_content_loaded_start', 'ms',
dom_content_loaded_start))
fetch_start = (
float(load_timings['fetchStart']) - load_timings['navigationStart'])
results.AddValue(scalar.ScalarValue(
results.current_page, 'fetch_start', 'ms', fetch_start,
important=False))
request_start = (
float(load_timings['requestStart']) - load_timings['navigationStart'])
results.AddValue(scalar.ScalarValue(
results.current_page, 'request_start', 'ms', request_start,
important=False))
# Phase measurements in milliseconds.
domain_lookup_duration = (
float(load_timings['domainLookupEnd']) -
load_timings['domainLookupStart'])
results.AddValue(scalar.ScalarValue(
results.current_page, 'domain_lookup_duration', 'ms',
domain_lookup_duration, important=False))
connect_duration = (
float(load_timings['connectEnd']) - load_timings['connectStart'])
results.AddValue(scalar.ScalarValue(
results.current_page, 'connect_duration', 'ms', connect_duration,
important=False))
request_duration = (
float(load_timings['responseStart']) - load_timings['requestStart'])
results.AddValue(scalar.ScalarValue(
results.current_page, 'request_duration', 'ms', request_duration,
important=False))
response_duration = (
float(load_timings['responseEnd']) - load_timings['responseStart'])
results.AddValue(scalar.ScalarValue(
results.current_page, 'response_duration', 'ms', response_duration,
important=False))
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment