1 # Copyright 2014 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from telemetry.core.platform.power_monitor import sysfs_platform
8 class CrosSysfsPlatform(sysfs_platform.SysfsPlatform):
9 """A SysfsPlatform implementation to be used for ChromeOS devices."""
10 def __init__(self, cri):
14 cri: Chrome interface.
16 super(CrosSysfsPlatform, self).__init__()
19 def RunShellCommand(self, command):
20 return self._cri.RunCmdOnDevice(command.split())[0]
23 def ParseStateSample(sample):
26 values = sample[cpu].splitlines()
27 # There are three values per state after excluding the single time value.
28 num_states = (len(values) - 1) / 3
29 names = values[:num_states]
30 times = values[num_states:2 * num_states]
31 latencies = values[2 * num_states:]
32 # The last line in the sample contains the time.
33 cstates = {'C0': int(values[-1]) * 10 ** 6}
34 for i, state in enumerate(names):
35 if names[i] == 'POLL' and not int(latencies[i]):
36 # C0 state. Kernel stats aren't right, so calculate by
37 # subtracting all other states from total time (using epoch
38 # timer since we calculate differences in the end anyway).
39 # NOTE: Only x86 lists C0 under cpuidle, ARM does not.
41 cstates['C0'] -= int(times[i])
42 if names[i] == '<null>':
43 # Kernel race condition that can happen while a new C-state gets
44 # added (e.g. AC->battery). Don't know the 'name' of the state
45 # yet, but its 'time' would be 0 anyway.
47 cstates[state] = int(times[i])
48 sample_stats[cpu] = cstates