aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Fernandes <joelaf@google.com>2017-07-08 19:22:22 -0700
committerJoel Fernandes <joelaf@google.com>2017-07-08 19:26:02 -0700
commitff807880438eb0c480bda11c961764e155b49eb2 (patch)
tree48cb638415c527dcb5cf173492fd42dbba886aef
parenta951463b87e0a17229d5fcd426b0b05a4ffb0764 (diff)
downloadtrappy-ff807880438eb0c480bda11c961764e155b49eb2.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>
-rw-r--r--tests/test_caching.py22
-rw-r--r--trappy/ftrace.py2
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 eabafc8..2c5fc60 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