Commit 317caf49 authored by bulach@chromium.org's avatar bulach@chromium.org

Telemetry / Android: do not crash on GetCpuStats() if the process is gone.

Some bots are failing with:
...[0].split()
IndexError: list index out of range
This can specially happen on page cyclers,
since multiple renders can be started and killed by the
framework.

BUG=

Review URL: https://codereview.chromium.org/25002005

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@226642 0039d316-1c4b-4281-b951-d872f2087c98
parent e43c41ac
......@@ -86,8 +86,11 @@ class AndroidPlatformBackend(platform_backend.PlatformBackend):
logging.warning('CPU stats cannot be retrieved on non-rooted device.')
return {}
stats = self._adb.GetProtectedFileContents('/proc/%s/stat' % pid,
log_result=False)[0].split()
return proc_util.GetCpuStats(stats)
log_result=False)
if not stats:
logging.warning('Unable to get /proc/%s/stat, process gone?', pid)
return {}
return proc_util.GetCpuStats(stats[0].split())
def GetCpuTimestamp(self):
if not self._adb.CanAccessProtectedFileContents():
......
# 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 telemetry.core.platform import android_platform_backend
from telemetry.unittest import system_stub
class MockAdbCommands(object):
def __init__(self, mock_content):
self.mock_content = mock_content
def CanAccessProtectedFileContents(self):
return True
# pylint: disable=W0613
def GetProtectedFileContents(self, file_name, log_result):
return self.mock_content
class AndroidPlatformBackendTest(unittest.TestCase):
def setUp(self):
self._stubs = system_stub.Override(android_platform_backend,
['perf_control', 'thermal_throttle'])
def tearDown(self):
self._stubs.Restore()
def testGetCpuStats(self):
proc_stat_content = [
'7702 (.android.chrome) S 167 167 0 0 -1 1077936448 '
'3247 0 0 0 4 1 0 0 20 0 9 0 5603962 337379328 5867 '
'4294967295 1074458624 1074463824 3197495984 3197494152 '
'1074767676 0 4612 0 38136 4294967295 0 0 17 0 0 0 0 0 0 '
'1074470376 1074470912 1102155776']
adb_valid_proc_content = MockAdbCommands(proc_stat_content)
backend = android_platform_backend.AndroidPlatformBackend(
adb_valid_proc_content, False)
cpu_stats = backend.GetCpuStats('7702')
self.assertEquals(cpu_stats, {'CpuProcessTime': 5.0})
def testGetCpuStatsInvalidPID(self):
# Mock an empty /proc/pid/stat.
adb_empty_proc_stat = MockAdbCommands([])
backend = android_platform_backend.AndroidPlatformBackend(
adb_empty_proc_stat, False)
cpu_stats = backend.GetCpuStats('7702')
self.assertEquals(cpu_stats, {})
......@@ -14,6 +14,8 @@ import sys as real_sys
class Override(object):
def __init__(self, base_module, module_list):
stubs = {'adb_commands': AdbCommandsModuleStub,
'perf_control': PerfControlModuleStub,
'thermal_throttle': ThermalThrottleModuleStub,
'os': OsModuleStub,
'subprocess': SubprocessModuleStub,
'sys': SysModuleStub,
......@@ -79,6 +81,24 @@ class AdbCommandsModuleStub(object):
def HasForwarder(_=None):
return True
class PerfControlModuleStub(object):
class PerfControlStub(object):
def __init__(self, adb):
pass
def __init__(self):
self.PerfControl = PerfControlModuleStub.PerfControlStub
class ThermalThrottleModuleStub(object):
class ThermalThrottleStub(object):
def __init__(self, adb):
pass
def __init__(self):
self.ThermalThrottle = ThermalThrottleModuleStub.ThermalThrottleStub
class OsModuleStub(object):
class OsPathModuleStub(object):
def __init__(self, sys_module):
......
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