Commit 3598d35d authored by dtu's avatar dtu Committed by Commit bot

[telemetry] Drop data for sysfs power monitor if distribution changes but total does not.

The log showed that the sum across all C-states didn't change, but C0 went down and WFI went up. AFAIK it shouldn't be possible for any of them to go down, so we'll just drop the data in this case.

BUG=426430
TEST=None.
TBR=tonyg

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

Cr-Commit-Position: refs/heads/master@{#302492}
parent 03d88765
...@@ -170,6 +170,11 @@ class SysfsPowerMonitor(power_monitor.PowerMonitor): ...@@ -170,6 +170,11 @@ class SysfsPowerMonitor(power_monitor.PowerMonitor):
for state in initial[cpu]: for state in initial[cpu]:
current_cpu[state] = final[cpu][state] - initial[cpu][state] current_cpu[state] = final[cpu][state] - initial[cpu][state]
total += current_cpu[state] total += current_cpu[state]
if total == 0:
# Somehow it's possible for initial and final to have the same sum,
# but a different distribution, making total == 0. crbug.com/426430
cpu_stats[cpu] = collections.defaultdict(int)
continue
for state in current_cpu: for state in current_cpu:
current_cpu[state] /= (float(total) / 100.0) current_cpu[state] /= (float(total) / 100.0)
# Calculate the average c-state residency across all CPUs. # Calculate the average c-state residency across all CPUs.
......
...@@ -195,6 +195,26 @@ class SysfsPowerMonitorMonitorTest(unittest.TestCase): ...@@ -195,6 +195,26 @@ class SysfsPowerMonitorMonitorTest(unittest.TestCase):
self.assertAlmostEqual(results[cpu][freq], self.assertAlmostEqual(results[cpu][freq],
self.expected_freq_percents[cpu][freq]) self.expected_freq_percents[cpu][freq])
def testComputeCpuStatsWithMissingData(self):
results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats(
{'cpu1': {}}, {'cpu1': {}})
self.assertEqual(results['cpu1'][12345], 0)
results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats(
{'cpu1': {123: 0}}, {'cpu1': {123: 0}})
self.assertEqual(results['cpu1'][123], 0)
results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats(
{'cpu1': {123: 456}}, {'cpu1': {123: 456}})
self.assertEqual(results['cpu1'][123], 0)
def testComputeCpuStatsWithNumberChange(self):
results = sysfs_power_monitor.SysfsPowerMonitor.ComputeCpuStats(
{'cpu1': {'C0': 10, 'WFI': 20}},
{'cpu1': {'C0': 20, 'WFI': 10}})
self.assertEqual(results['cpu1']['C0'], 0)
self.assertEqual(results['cpu1']['WFI'], 0)
def testGetCpuStateForAndroidDevices(self): def testGetCpuStateForAndroidDevices(self):
class PlatformStub(object): class PlatformStub(object):
def __init__(self, run_command_return_value): def __init__(self, run_command_return_value):
......
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