diff options
author | Javi Merino <javi.merino@arm.com> | 2014-12-11 16:17:54 +0000 |
---|---|---|
committer | Javi Merino <javi.merino@arm.com> | 2015-08-12 16:03:44 +0100 |
commit | 0ecdf2613fc993ca96385f15c709f5b6454a4cd6 (patch) | |
tree | e3ce1d6283a1daccb8f105f274f69fd2415898b5 | |
parent | 6c339784613ddd9f0f01f674c737408e3bac3391 (diff) | |
download | trappy-0ecdf2613fc993ca96385f15c709f5b6454a4cd6.tar.gz |
run: Normalize if some of the tracepoints are not present
5b0ef70e160c (cr2/run, thermal: consider all classes when setting
global basetime) fails to normalize the time if only some of the
classes are present. This is because BaseThermal::get_basetime()
returns 0 if there is no dataframe, which is wrong. Normalize against
the minimum time of the *present* tracepoints instead.
-rw-r--r-- | cr2/run.py | 8 | ||||
-rw-r--r-- | cr2/thermal.py | 4 | ||||
-rw-r--r-- | tests/test_run.py | 13 |
3 files changed, 20 insertions, 5 deletions
@@ -49,7 +49,13 @@ class Run(object): basetimes = [] for attr in self.classes.iterkeys(): - basetimes.append(getattr(self, attr).get_basetime()) + try: + basetimes.append(getattr(self, attr).data_frame.index[0]) + except IndexError: + pass + + if len(basetimes) == 0: + return 0 return min(basetimes) diff --git a/cr2/thermal.py b/cr2/thermal.py index cc45326..86e8590 100644 --- a/cr2/thermal.py +++ b/cr2/thermal.py @@ -175,10 +175,6 @@ class BaseThermal(object): self.data_frame["Time"] = self.data_frame["Time"] - basetime self.data_frame.set_index("Time", inplace=True) - def get_basetime(self): - """ Return the base time of the data frame""" - return self.data_frame.index[0] if not self.data_frame.empty else 0 - class Thermal(BaseThermal): """Process the thermal framework data in a ftrace dump""" def __init__(self, path=None): diff --git a/tests/test_run.py b/tests/test_run.py index ffe9f15..7b61e5b 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -3,6 +3,7 @@ import matplotlib import os import re +import shutil import tempfile from test_thermal import BaseTestThermal @@ -89,6 +90,18 @@ class TestRun(BaseTestThermal): self.assertEqual(run.get_basetime(), 0) + def test_run_normalize_some_tracepoints(self): + """Test that normalizing time works if not all the tracepoints are in the trace""" + + os.remove("trace.txt") + shutil.move("trace_empty.txt", "trace.txt") + with open("trace.txt", "a") as fil: + fil.write(" kworker/4:1-1219 [004] 508.424826: thermal_temperature: thermal_zone=exynos-therm id=0 temp_prev=24000 temp=24000") + + run = cr2.Run() + + self.assertEqual(run.thermal.data_frame.index[0], 0) + def test_run_normalize_time(self): """Run().normalize_time() works accross all classes""" |