summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authornednguyen <nednguyen@google.com>2015-04-24 23:12:28 -0700
committerCommit bot <commit-bot@chromium.org>2015-04-25 06:12:38 +0000
commitc3d7606e8efbb5ac063f2e98a14e09e48aff5022 (patch)
tree917024874e7d281c45a38e8d7dd880580532c4f7 /tools
parent0a74fd9a8fb634aa6e7407afed9fa556fc8ebca2 (diff)
downloadchromium_src-c3d7606e8efbb5ac063f2e98a14e09e48aff5022.zip
chromium_src-c3d7606e8efbb5ac063f2e98a14e09e48aff5022.tar.gz
chromium_src-c3d7606e8efbb5ac063f2e98a14e09e48aff5022.tar.bz2
[Telemetry] Improve _GetProcJiffies operation with using grep.
Previously, telemetry read the whole '/proc/timer_list' file just to parse the first occurence of "jiffies". In case the file is big and telemetry is run against remote device, this can create a big delay for transferring the file to host device. This patch modify it so that telemetry just use 'grep jiffies /proc/timer_list' to get the only lines that contain 'jiffies'. Context: https://groups.google.com/a/chromium.org/forum/#!topic/telemetry/SblQqF0tHbc Try job runs: ./tools/perf/run_benchmark --browser=trybot-all-android page_cycler.top_10_mobile --also-run-disabled-tests https://codereview.chromium.org/1100233003 ./tools/perf/run_benchmark --browser=trybot-all-mac page_cycler.intl_ja_zh https://codereview.chromium.org/1106833004 ./tools/perf/run_benchmark --browser=trybot-all-linux page_cycler.intl_ja_zh https://codereview.chromium.org/1102673005 Review URL: https://codereview.chromium.org/1106043003 Cr-Commit-Position: refs/heads/master@{#326961}
Diffstat (limited to 'tools')
-rw-r--r--tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py28
-rw-r--r--tools/telemetry/telemetry/core/platform/linux_based_platform_backend_unittest.py25
-rw-r--r--tools/telemetry/unittest_data/timer_list62
3 files changed, 38 insertions, 77 deletions
diff --git a/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py b/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py
index 6da1628..7e84dde 100644
--- a/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py
+++ b/tools/telemetry/telemetry/core/platform/linux_based_platform_backend.py
@@ -7,6 +7,8 @@ try:
except ImportError:
resource = None # Not available on all platforms
+import re
+
from telemetry.core import exceptions
from telemetry.core.platform import platform_backend
from telemetry import decorators
@@ -53,8 +55,7 @@ class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
return results
def GetCpuTimestamp(self):
- timer_list = self.GetFileContents('/proc/timer_list')
- total_jiffies = float(self._GetProcJiffies(timer_list))
+ total_jiffies = self._GetProcJiffies()
clock_ticks = self.GetClockTicks()
return {'TotalTime': total_jiffies / clock_ticks}
@@ -146,15 +147,22 @@ class LinuxBasedPlatformBackend(platform_backend.PlatformBackend):
retval[key.strip()] = value.strip()
return retval
- def _GetProcJiffies(self, timer_list):
+ def _GetProcJiffies(self):
"""Parse '/proc/timer_list' output and returns the first jiffies attribute.
Multi-CPU machines will have multiple 'jiffies:' lines, all of which will be
essentially the same. Return the first one."""
- if isinstance(timer_list, str):
- timer_list = timer_list.splitlines()
- for line in timer_list:
- if line.startswith('jiffies:'):
- _, value = line.split(':')
- return value
- raise Exception('Unable to find jiffies from /proc/timer_list')
+ jiffies_timer_lines = self.RunCommand(
+ ['grep', 'jiffies','/proc/timer_list'])
+ if not jiffies_timer_lines:
+ raise Exception('Unable to find jiffies from /proc/timer_list')
+ jiffies_timer_list = jiffies_timer_lines.splitlines()
+ # Each line should look something like 'jiffies: 4315883489'.
+ for line in jiffies_timer_list:
+ print repr(line)
+ match = re.match('\s*jiffies\s*:\s*(\d+)', line)
+ if match:
+ value = match.group(1)
+ return float(value)
+ raise Exception('Unable to parse jiffies attribute: %s' %
+ repr(jiffies_timer_lines))
diff --git a/tools/telemetry/telemetry/core/platform/linux_based_platform_backend_unittest.py b/tools/telemetry/telemetry/core/platform/linux_based_platform_backend_unittest.py
index 6e706a5..c76289d 100644
--- a/tools/telemetry/telemetry/core/platform/linux_based_platform_backend_unittest.py
+++ b/tools/telemetry/telemetry/core/platform/linux_based_platform_backend_unittest.py
@@ -8,6 +8,10 @@ import unittest
from telemetry.core.platform import linux_based_platform_backend
from telemetry.core import util
+util.AddDirToPythonPath(util.GetTelemetryDir(), 'third_party', 'mock')
+import mock # pylint: disable=import-error
+
+
class TestBackend(linux_based_platform_backend.LinuxBasedPlatformBackend):
@@ -47,11 +51,22 @@ class LinuxBasedPlatformBackendTest(unittest.TestCase):
if not linux_based_platform_backend.resource:
logging.warning('Test not supported')
return
-
- backend = TestBackend()
- self.SetMockFileInBackend(backend, 'timer_list', '/proc/timer_list')
- result = backend.GetCpuTimestamp()
- self.assertEquals(result, {'TotalTime': 105054633.0})
+ jiffies_grep_string = """
+ jiffies
+jiffies a1111
+ .last_jiffies : 4307239958
+ .next_jiffies : 4307239968
+ jiffies: 10505463300
+ jiffies: 10505463333
+ """
+ with mock.patch.object(
+ linux_based_platform_backend.LinuxBasedPlatformBackend,
+ 'RunCommand', return_value=jiffies_grep_string) as mock_method:
+ backend = linux_based_platform_backend.LinuxBasedPlatformBackend()
+ result = backend.GetCpuTimestamp()
+ self.assertEquals(result, {'TotalTime': 105054633.0})
+ mock_method.assert_call_once_with(
+ ['grep', '-m', '1', 'jiffies:','/proc/timer_list'])
def testGetMemoryStatsBasic(self):
if not linux_based_platform_backend.resource:
diff --git a/tools/telemetry/unittest_data/timer_list b/tools/telemetry/unittest_data/timer_list
deleted file mode 100644
index d7ff169..0000000
--- a/tools/telemetry/unittest_data/timer_list
+++ /dev/null
@@ -1,62 +0,0 @@
-Timer List Version: v0.7
-HRTIMER_MAX_CLOCK_BASES: 4
-now at 49390649032656 nsecs
-
-cpu: 0
- clock 0:
- .base: 0000000000000000
- .index: 0
- .resolution: 1 nsecs
- .get_time: ktime_get
- .offset: 0 nsecs
-active timers:
- #0: <0000000000000000>, hrtimer_wakeup, S:01, schedule_hrtimeout_range_clock, census_census_h/2343
- # expires at 49390651724646-49390651774646 nsecs [in 2691990 to 2741990 nsecs]
- #1: <0000000000000000>, hrtimer_wakeup, S:01, schedule_hrtimeout_range_clock, census_census_h/3680
- # expires at 49390656983466-49390657033466 nsecs [in 7950810 to 8000810 nsecs]
- clock 1:
- .base: 0000000000000000
- .index: 1
- .resolution: 1 nsecs
- .get_time: ktime_get_real
- .offset: 1414432541083798144 nsecs
-active timers:
- #0: <0000000000000000>, hrtimer_wakeup, S:01, hrtimer_start_range_ns, mysqld/27245
- # expires at 1414481934522781000-1414481934522831000 nsecs [in 1414432543873748344 to 1414432543873798344 nsecs]
- #1: <0000000000000000>, hrtimer_wakeup, S:01, hrtimer_start_range_ns, DNS Res~ver #14/21520
- # expires at 1414482222918140000-1414482222918190000 nsecs [in 1414432832269107344 to 1414432832269157344 nsecs]
- clock 2:
- .base: 0000000000000000
- .index: 2
- .resolution: 1 nsecs
- .get_time: ktime_get_boottime
- .offset: 0 nsecs
-active timers:
- clock 3:
- .base: 0000000000000000
- .index: 3
- .resolution: 1 nsecs
- .get_time: ktime_get_clocktai
- .offset: 1414432541083798144 nsecs
-active timers:
- .expires_next : 49390651774646 nsecs
- .hres_active : 1
- .nr_events : 9793846
- .nr_retries : 580
- .nr_hangs : 0
- .max_hang_time : 0 nsecs
- .nohz_mode : 2
- .last_tick : 49390648000000 nsecs
- .tick_stopped : 1
- .idle_jiffies : 4307239958
- .idle_calls : 16879086
- .idle_sleeps : 15799778
- .idle_entrytime : 49390647721066 nsecs
- .idle_waketime : 49390647714831 nsecs
- .idle_exittime : 49390647489308 nsecs
- .idle_sleeptime : 44326049938322 nsecs
- .iowait_sleeptime: 1007311574977 nsecs
- .last_jiffies : 4307239958
- .next_jiffies : 4307239968
- .idle_expires : 49390684000000 nsecs
-jiffies: 4307239953