diff options
author | Joel Fernandes <joelaf@google.com> | 2017-07-08 19:22:22 -0700 |
---|---|---|
committer | KP Singh <kpsingh@google.com> | 2017-07-14 11:26:18 +0200 |
commit | 96f1148d408ef63a47db70eb97739189dce27f9f (patch) | |
tree | 75b65904ba32eb654aeb2f221eaf249d7d0d187c | |
parent | 46660d432e6ecb68dec8ff38180d93ba4e6ec7f0 (diff) | |
download | trappy-96f1148d408ef63a47db70eb97739189dce27f9f.tar.gz |
cache: Fix issue where single missing CSV deletes all
There's a bug in trappy caching where corruption or removal of single CSVs
causes all CSVs to get removed. Fix this and add a test-case to cover it.
Also test that only missing items are regenerated.
Change-Id: Iea41c8e0a005515790b580e7f78f06bdd60141a3
Signed-off-by: Joel Fernandes <joelaf@google.com>
Reviewed-by: KP Singh <kpsingh@google.com>
-rw-r--r-- | tests/test_caching.py | 22 | ||||
-rw-r--r-- | trappy/ftrace.py | 2 |
2 files changed, 23 insertions, 1 deletions
diff --git a/tests/test_caching.py b/tests/test_caching.py index d0893b7..9fcd33a 100644 --- a/tests/test_caching.py +++ b/tests/test_caching.py @@ -191,3 +191,25 @@ class TestCaching(utils_tests.SetupDirectory): window=(0, None)) self.assertEqual(len(trace1.sched_wakeup.data_frame), 2) + + def test_cache_delete_single(self): + GenericFTrace.disable_cache = False + trace = trappy.FTrace() + + trace_path = os.path.abspath(trace.trace_path) + trace_dir = os.path.dirname(trace_path) + trace_file = os.path.basename(trace_path) + cache_dir = '.' + trace_file + '.cache' + self.assertEquals(len(os.listdir(cache_dir)), 22) + + os.remove(os.path.join(cache_dir, 'SchedWakeup.csv')) + self.assertEquals(len(os.listdir(cache_dir)), 21) + + # Generate trace again, should regenerate only the missing item + trace = trappy.FTrace() + self.assertEquals(len(os.listdir(cache_dir)), 22) + for c in trace.trace_classes: + if isinstance(c, trace.class_definitions['sched_wakeup']): + self.assertEquals(c.cached, False) + continue + self.assertEquals(c.cached, True) diff --git a/trappy/ftrace.py b/trappy/ftrace.py index 226cd96..2737086 100644 --- a/trappy/ftrace.py +++ b/trappy/ftrace.py @@ -216,7 +216,7 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace.""" if not self.__class__.disable_cache: try: # Recreate basic cache directories only if nothing cached - if not all([c.cached for c in self.trace_classes]): + if not any([c.cached for c in self.trace_classes]): self._create_trace_cache(params) # Write out only events that weren't cached before |