Commit 7bf057f8 authored by bulach@chromium.org's avatar bulach@chromium.org

Android: splits cache_control and perf_control.

Second step towards deprecating "perf_tests_helper.py"
towards more meaningful modules.
Also move thermal_throttle.py into perf/ and some
other minor cleanup.

BUG=

Review URL: https://chromiumcodereview.appspot.com/23681011

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@223606 0039d316-1c4b-4281-b951-d872f2087c98
parent e77b6082
...@@ -937,13 +937,18 @@ class AndroidCommands(object): ...@@ -937,13 +937,18 @@ class AndroidCommands(object):
i += 1 i += 1
return self.GetExternalStorage() + '/' + base_name % i return self.GetExternalStorage() + '/' + base_name % i
def RunShellCommandWithSU(self, command, timeout_time=20, log_result=False):
return self.RunShellCommand('su -c %s' % command,
timeout_time=timeout_time,
log_result=log_result)
def CanAccessProtectedFileContents(self): def CanAccessProtectedFileContents(self):
"""Returns True if Get/SetProtectedFileContents would work via "su". """Returns True if Get/SetProtectedFileContents would work via "su".
Devices running user builds don't have adb root, but may provide "su" which Devices running user builds don't have adb root, but may provide "su" which
can be used for accessing protected files. can be used for accessing protected files.
""" """
r = self.RunShellCommand('su -c cat /dev/null') r = self.RunShellCommandWithSU('cat /dev/null')
return r == [] or r[0].strip() == '' return r == [] or r[0].strip() == ''
def GetProtectedFileContents(self, filename, log_result=False): def GetProtectedFileContents(self, filename, log_result=False):
...@@ -953,7 +958,7 @@ class AndroidCommands(object): ...@@ -953,7 +958,7 @@ class AndroidCommands(object):
files and device files. files and device files.
""" """
# Run the script as root # Run the script as root
return self.RunShellCommand('su -c cat "%s" 2> /dev/null' % filename) return self.RunShellCommandWithSU('cat "%s" 2> /dev/null' % filename)
def SetProtectedFileContents(self, filename, contents): def SetProtectedFileContents(self, filename, contents):
"""Writes |contents| to the protected file specified by |filename|. """Writes |contents| to the protected file specified by |filename|.
...@@ -970,7 +975,7 @@ class AndroidCommands(object): ...@@ -970,7 +975,7 @@ class AndroidCommands(object):
# Create a script to copy the file contents to its final destination # Create a script to copy the file contents to its final destination
self.SetFileContents(temp_script, 'cat %s > %s' % (temp_file, filename)) self.SetFileContents(temp_script, 'cat %s > %s' % (temp_file, filename))
# Run the script as root # Run the script as root
self.RunShellCommand('su -c sh %s' % temp_script) self.RunShellCommandWithSU('sh %s' % temp_script)
# And remove the temporary files # And remove the temporary files
self.RunShellCommand('rm ' + temp_file) self.RunShellCommand('rm ' + temp_file)
self.RunShellCommand('rm ' + temp_script) self.RunShellCommand('rm ' + temp_script)
......
# Copyright (c) 2012 The Chromium Authors. All rights reserved. # Copyright 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
......
...@@ -12,11 +12,11 @@ import time ...@@ -12,11 +12,11 @@ import time
from pylib import android_commands from pylib import android_commands
from pylib import constants from pylib import constants
from pylib import flag_changer from pylib import flag_changer
from pylib import json_perf_parser
from pylib import perf_tests_helper from pylib import perf_tests_helper
from pylib import valgrind_tools from pylib import valgrind_tools
from pylib.base import base_test_result from pylib.base import base_test_result
from pylib.base import base_test_runner from pylib.base import base_test_runner
from pylib.instrumentation import json_perf_parser
import test_result import test_result
......
# 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.
class CacheControl(object):
_DROP_CACHES = '/proc/sys/vm/drop_caches'
def __init__(self, adb):
self._adb = adb
def DropRamCaches(self):
"""Drops the filesystem ram caches for performance testing."""
self._adb.RunShellCommandWithSU('sync')
self._adb.SetProtectedFileContents(CacheControl._DROP_CACHES, '3')
# 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
class PerfControl(object):
"""Provides methods for setting the performance mode of a device."""
_SCALING_GOVERNOR_FMT = (
'/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor')
_KERNEL_MAX = '/sys/devices/system/cpu/kernel_max'
def __init__(self, adb):
self._adb = adb
kernel_max = self._adb.GetFileContents(PerfControl._KERNEL_MAX,
log_result=False)
assert kernel_max, 'Unable to find %s' % PerfControl._KERNEL_MAX
self._kernel_max = int(kernel_max[0])
logging.info('Maximum CPU index: %d', self._kernel_max)
self._original_scaling_governor = self._adb.GetFileContents(
PerfControl._SCALING_GOVERNOR_FMT % 0,
log_result=False)[0]
def SetHighPerfMode(self):
"""Sets the highest possible performance mode for the device."""
self._SetScalingGovernorInternal('performance')
def SetDefaultPerfMode(self):
"""Sets the performance mode for the device to its default mode."""
product_model = self._adb.GetProductModel()
governor_mode = {
'GT-I9300': 'pegasusq',
'Galaxy Nexus': 'interactive',
'Nexus 4': 'ondemand',
'Nexus 7': 'interactive',
'Nexus 10': 'interactive'
}.get(product_model, 'ondemand')
self._SetScalingGovernorInternal(governor_mode)
def RestoreOriginalPerfMode(self):
"""Resets the original performance mode of the device."""
self._SetScalingGovernorInternal(self._original_scaling_governor)
def _SetScalingGovernorInternal(self, value):
for cpu in range(self._kernel_max + 1):
scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu
if self._adb.FileExistsOnDevice(scaling_governor_file):
logging.info('Writing scaling governor mode \'%s\' -> %s',
value, scaling_governor_file)
self._adb.SetProtectedFileContents(scaling_governor_file, value)
This diff is collapsed.
# 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
class ThermalThrottle(object):
"""Class to detect and track thermal throttling.
Usage:
Wait for IsThrottled() to be False before running test
After running test call HasBeenThrottled() to find out if the
test run was affected by thermal throttling.
Currently assumes an OMap device.
"""
def __init__(self, adb):
self._adb = adb
self._throttled = False
def HasBeenThrottled(self):
"""True if there has been any throttling since the last call to
HasBeenThrottled or IsThrottled.
"""
return self._ReadLog()
def IsThrottled(self):
"""True if currently throttled."""
self._ReadLog()
return self._throttled
def _ReadLog(self):
has_been_throttled = False
serial_number = self._adb.Adb().GetSerialNumber()
log = self._adb.RunShellCommand('dmesg -c')
degree_symbol = unichr(0x00B0)
for line in log:
if 'omap_thermal_throttle' in line:
if not self._throttled:
logging.warning('>>> Device %s Thermally Throttled', serial_number)
self._throttled = True
has_been_throttled = True
if 'omap_thermal_unthrottle' in line:
if self._throttled:
logging.warning('>>> Device %s Thermally Unthrottled', serial_number)
self._throttled = False
has_been_throttled = True
if 'throttle_delayed_work_fn' in line:
temp = float([s for s in line.split() if s.isdigit()][0]) / 1000.0
logging.info(u' Device %s Thermally Thottled at %3.1f%sC',
serial_number, temp, degree_symbol)
if logging.getLogger().isEnabledFor(logging.DEBUG):
# Print temperature of CPU SoC.
omap_temp_file = ('/sys/devices/platform/omap/omap_temp_sensor.0/'
'temperature')
if self._adb.FileExistsOnDevice(omap_temp_file):
tempdata = self._adb.GetFileContents(omap_temp_file)
temp = float(tempdata[0]) / 1000.0
logging.debug(u'Current OMAP Temperature of %s = %3.1f%sC',
serial_number, temp, degree_symbol)
# Print temperature of battery, to give a system temperature
dumpsys_log = self._adb.RunShellCommand('dumpsys battery')
for line in dumpsys_log:
if 'temperature' in line:
btemp = float([s for s in line.split() if s.isdigit()][0]) / 10.0
logging.debug(u'Current battery temperature of %s = %3.1f%sC',
serial_number, btemp, degree_symbol)
return has_been_throttled
...@@ -2,13 +2,17 @@ ...@@ -2,13 +2,17 @@
# Use of this source code is governed by a BSD-style license that can be # Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file. # found in the LICENSE file.
import json
import logging
import math
import re import re
import sys import sys
import android_commands import android_commands
import json
import logging from perf import cache_control
import math from perf import perf_control
# Valid values of result type. # Valid values of result type.
RESULT_TYPES = {'unimportant': 'RESULT ', RESULT_TYPES = {'unimportant': 'RESULT ',
...@@ -146,58 +150,11 @@ def PrintPerfResult(measurement, trace, values, units, result_type='default', ...@@ -146,58 +150,11 @@ def PrintPerfResult(measurement, trace, values, units, result_type='default',
return output return output
class CacheControl(object): # TODO(bulach): remove once all references to PerfControl are fixed.
_DROP_CACHES = '/proc/sys/vm/drop_caches' class CacheControl(cache_control.CacheControl):
def __init__(self, adb): def __init__(self, adb):
self._adb = adb super(CacheControl, self).__init__(adb)
def DropRamCaches(self):
"""Drops the filesystem ram caches for performance testing."""
self._adb.RunShellCommand('su -c sync')
self._adb.SetProtectedFileContents(CacheControl._DROP_CACHES, '3')
class PerfControl(object):
"""Provides methods for setting the performance mode of a device."""
_SCALING_GOVERNOR_FMT = (
'/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor')
class PerfControl(perf_control.PerfControl):
def __init__(self, adb): def __init__(self, adb):
self._adb = adb super(PerfControl, self).__init__(adb)
kernel_max = self._adb.GetFileContents('/sys/devices/system/cpu/kernel_max',
log_result=False)
assert kernel_max, 'Unable to find /sys/devices/system/cpu/kernel_max'
self._kernel_max = int(kernel_max[0])
logging.info('Maximum CPU index: %d' % self._kernel_max)
self._original_scaling_governor = self._adb.GetFileContents(
PerfControl._SCALING_GOVERNOR_FMT % 0,
log_result=False)[0]
def SetHighPerfMode(self):
"""Sets the highest possible performance mode for the device."""
self._SetScalingGovernorInternal('performance')
def SetDefaultPerfMode(self):
"""Sets the performance mode for the device to its default mode."""
product_model = self._adb.GetProductModel()
governor_mode = {
"GT-I9300" : 'pegasusq',
"Galaxy Nexus" : 'interactive',
"Nexus 4" : 'ondemand',
"Nexus 7" : 'interactive',
"Nexus 10": 'interactive'
}.get(product_model, 'ondemand')
self._SetScalingGovernorInternal(governor_mode)
def RestoreOriginalPerfMode(self):
"""Resets the original performance mode of the device."""
self._SetScalingGovernorInternal(self._original_scaling_governor)
def _SetScalingGovernorInternal(self, value):
for cpu in range(self._kernel_max + 1):
scaling_governor_file = PerfControl._SCALING_GOVERNOR_FMT % cpu
if self._adb.FileExistsOnDevice(scaling_governor_file):
logging.info('Writing scaling governor mode \'%s\' -> %s' %
(value, scaling_governor_file))
self._adb.SetProtectedFileContents(scaling_governor_file, value)
...@@ -4,69 +4,9 @@ ...@@ -4,69 +4,9 @@
import logging import logging
class ThermalThrottle(object): from perf import thermal_throttle
"""Class to detect and track thermal throttling
Usage: # TODO(bulach): remove once all references to ThermalThrottle are fixed.
Wait for IsThrottled() to be False before running test class ThermalThrottle(thermal_throttle.ThermalThrottle):
After running test call HasBeenThrottled() to find out if the
test run was affected by thermal throttling.
Currently assumes an OMap device.
"""
def __init__(self, adb): def __init__(self, adb):
self._adb = adb super(ThermalThrottle, self).__init__(adb)
self._throttled = False
def HasBeenThrottled(self):
""" True if there has been any throttling since the last call to
HasBeenThrottled or IsThrottled
"""
return self._ReadLog()
def IsThrottled(self):
"""True if currently throttled"""
self._ReadLog()
return self._throttled
def _ReadLog(self):
has_been_throttled = False
serial_number = self._adb.Adb().GetSerialNumber()
log = self._adb.RunShellCommand('dmesg -c')
degree_symbol = unichr(0x00B0)
for line in log:
if 'omap_thermal_throttle' in line:
if not self._throttled:
logging.warning('>>> Device %s Thermally Throttled', serial_number)
self._throttled = True
has_been_throttled = True
if 'omap_thermal_unthrottle' in line:
if self._throttled:
logging.warning('>>> Device %s Thermally Unthrottled', serial_number)
self._throttled = False
has_been_throttled = True
if 'throttle_delayed_work_fn' in line:
temp = float([s for s in line.split() if s.isdigit()][0]) / 1000.0
logging.info(u' Device %s Thermally Thottled at %3.1f%sC',
serial_number, temp, degree_symbol)
if logging.getLogger().isEnabledFor(logging.DEBUG):
# Print temperature of CPU SoC.
omap_temp_file = ('/sys/devices/platform/omap/omap_temp_sensor.0/'
'temperature')
if self._adb.FileExistsOnDevice(omap_temp_file):
tempdata = self._adb.GetFileContents(omap_temp_file)
temp = float(tempdata[0]) / 1000.0
logging.debug(u'Current OMAP Temperature of %s = %3.1f%sC',
serial_number, temp, degree_symbol)
# Print temperature of battery, to give a system temperature
dumpsys_log = self._adb.RunShellCommand('dumpsys battery')
for line in dumpsys_log:
if 'temperature' in line:
btemp = float([s for s in line.split() if s.isdigit()][0]) / 10.0
logging.debug(u'Current battery temperature of %s = %3.1f%sC',
serial_number, btemp, degree_symbol)
return has_been_throttled
...@@ -13,7 +13,8 @@ import optparse ...@@ -13,7 +13,8 @@ import optparse
import sys import sys
import time import time
from pylib import android_commands, surface_stats_collector from pylib import android_commands
from pylib.perf import surface_stats_collector
from pylib.utils import run_tests_helper from pylib.utils import run_tests_helper
......
...@@ -106,8 +106,8 @@ def PrintPerfResult(measurement, trace, values, units, ...@@ -106,8 +106,8 @@ def PrintPerfResult(measurement, trace, values, units,
Returns: Returns:
String of the formated perf result. String of the formated perf result.
""" """
assert (perf_result_data_type.IsValidType(result_type), assert perf_result_data_type.IsValidType(result_type), \
'result type: %s is invalid' % result_type) 'result type: %s is invalid' % result_type
trace_name = _EscapePerfResult(trace) trace_name = _EscapePerfResult(trace)
......
...@@ -11,11 +11,12 @@ from telemetry.core.platform import proc_util ...@@ -11,11 +11,12 @@ from telemetry.core.platform import proc_util
# Get build/android scripts into our path. # Get build/android scripts into our path.
util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android') util.AddDirToPythonPath(util.GetChromiumSrcDir(), 'build', 'android')
from pylib import perf_tests_helper # pylint: disable=F0401 from pylib.perf import cache_control # pylint: disable=F0401
from pylib import thermal_throttle # pylint: disable=F0401 from pylib.perf import perf_control # pylint: disable=F0401
from pylib.perf import thermal_throttle # pylint: disable=F0401
try: try:
from pylib import surface_stats_collector # pylint: disable=F0401 from pylib.perf import surface_stats_collector # pylint: disable=F0401
except Exception: except Exception:
surface_stats_collector = None surface_stats_collector = None
...@@ -25,7 +26,7 @@ class AndroidPlatformBackend(platform_backend.PlatformBackend): ...@@ -25,7 +26,7 @@ class AndroidPlatformBackend(platform_backend.PlatformBackend):
super(AndroidPlatformBackend, self).__init__() super(AndroidPlatformBackend, self).__init__()
self._adb = adb self._adb = adb
self._surface_stats_collector = None self._surface_stats_collector = None
self._perf_tests_setup = perf_tests_helper.PerfControl(self._adb) self._perf_tests_setup = perf_control.PerfControl(self._adb)
self._thermal_throttle = thermal_throttle.ThermalThrottle(self._adb) self._thermal_throttle = thermal_throttle.ThermalThrottle(self._adb)
self._no_performance_mode = no_performance_mode self._no_performance_mode = no_performance_mode
self._raw_display_frame_rate_measurements = [] self._raw_display_frame_rate_measurements = []
...@@ -139,8 +140,8 @@ class AndroidPlatformBackend(platform_backend.PlatformBackend): ...@@ -139,8 +140,8 @@ class AndroidPlatformBackend(platform_backend.PlatformBackend):
return False return False
def FlushEntireSystemCache(self): def FlushEntireSystemCache(self):
cache_control = perf_tests_helper.CacheControl(self._adb) cache = cache_control.CacheControl(self._adb)
cache_control.DropRamCaches() cache.DropRamCaches()
def FlushSystemCacheForDirectory(self, directory, ignoring=None): def FlushSystemCacheForDirectory(self, directory, ignoring=None):
raise NotImplementedError() raise NotImplementedError()
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