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 import re | 5 import re |
6 | 6 |
| 7 import android_commands |
7 | 8 |
8 # Valid values of result type. | 9 # Valid values of result type. |
9 RESULT_TYPES = {'unimportant': 'RESULT ', | 10 RESULT_TYPES = {'unimportant': 'RESULT ', |
10 'default': '*RESULT ', | 11 'default': '*RESULT ', |
11 'informational': ''} | 12 'informational': ''} |
12 | 13 |
13 | 14 |
14 def _EscapePerfResult(s): | 15 def _EscapePerfResult(s): |
15 """Escapes |s| for use in a perf result.""" | 16 """Escapes |s| for use in a perf result.""" |
16 # Colons (:) and equal signs (=) are not allowed, and we chose an arbitrary | 17 # Colons (:) and equal signs (=) are not allowed, and we chose an arbitrary |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 # Do not show equal sign if the trace is empty. Usually it happens when | 63 # Do not show equal sign if the trace is empty. Usually it happens when |
63 # measurement is enough clear to describe the result. | 64 # measurement is enough clear to describe the result. |
64 '= ' if trace_name else '', | 65 '= ' if trace_name else '', |
65 value, | 66 value, |
66 units) | 67 units) |
67 if avg: | 68 if avg: |
68 output += '\nAvg %s: %f%s' % (measurement, avg, units) | 69 output += '\nAvg %s: %f%s' % (measurement, avg, units) |
69 if print_to_stdout: | 70 if print_to_stdout: |
70 print output | 71 print output |
71 return output | 72 return output |
| 73 |
| 74 |
| 75 class PerfTestSetup(object): |
| 76 """Provides methods for setting up a device for perf testing.""" |
| 77 _DROP_CACHES = '/proc/sys/vm/drop_caches' |
| 78 _SCALING_GOVERNOR = '/sys/devices/system/cpu/cpu%d/cpufreq/scaling_governor' |
| 79 |
| 80 def __init__(self, adb): |
| 81 self._adb = adb |
| 82 num_cpus = self._adb.GetFileContents('/sys/devices/system/cpu/online', |
| 83 log_result=False) |
| 84 assert num_cpus, 'Unable to find /sys/devices/system/cpu/online' |
| 85 self._num_cpus = int(num_cpus[0].split('-')[-1]) |
| 86 self._original_scaling_governor = None |
| 87 |
| 88 def DropRamCaches(self): |
| 89 """Drops the filesystem ram caches for performance testing.""" |
| 90 self._adb.RunShellCommand('echo 3 > ' + PerfTestSetup._DROP_CACHES) |
| 91 |
| 92 def SetUp(self): |
| 93 """Sets up performance tests.""" |
| 94 if not self._original_scaling_governor: |
| 95 self._original_scaling_governor = self._adb.GetFileContents( |
| 96 PerfTestSetup._SCALING_GOVERNOR % 0, |
| 97 log_result=False)[0] |
| 98 self._SetScalingGovernorInternal('performance') |
| 99 self.DropRamCaches() |
| 100 |
| 101 def TearDown(self): |
| 102 """Tears down performance tests.""" |
| 103 if self._original_scaling_governor: |
| 104 self._SetScalingGovernorInternal(self._original_scaling_governor) |
| 105 self._original_scaling_governor = None |
| 106 |
| 107 def _SetScalingGovernorInternal(self, value): |
| 108 for cpu in range(self._num_cpus): |
| 109 self._adb.RunShellCommand( |
| 110 ('echo %s > ' + PerfTestSetup._SCALING_GOVERNOR) % (value, cpu)) |
OLD | NEW |