aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrendan Jackman <brendan.jackman@arm.com>2017-06-14 15:03:23 +0100
committerKP Singh <kpsingh@google.com>2017-06-29 22:52:38 +0200
commit3fdf6872b0d59743ff05ca4f7ec7f429a3cc81be (patch)
treef1c10a5446805fcff2f1f59f20624d00f68da785
parenta19ff2508e37fce5e4909e0b717c3a4d2f0be679 (diff)
downloadtrappy-3fdf6872b0d59743ff05ca4f7ec7f429a3cc81be.tar.gz
ftrace: Store and retrieve window params in trace cache
Store a JSON file with the parameters used to parse a trace in the cache. If, on retrieval, we find a mismatch then simply invalidate the cache. A richer implementation might detect whether we can still use the cache (e.g. if the requested window is a subset of the cached one), but for now I don't think that's worth the effort/complexity. Reviewed-by: KP Singh <kpsingh@google.com>
-rw-r--r--trappy/ftrace.py24
1 files changed, 17 insertions, 7 deletions
diff --git a/trappy/ftrace.py b/trappy/ftrace.py
index 2176d30..dae1e43 100644
--- a/trappy/ftrace.py
+++ b/trappy/ftrace.py
@@ -18,6 +18,7 @@
# pylint: disable=no-member
import itertools
+import json
import os
import re
import pandas as pd
@@ -74,27 +75,32 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
cache_path = os.path.join(tracefile_dir, cache_dir)
return cache_path
- def _check_trace_cache(self):
+ def _check_trace_cache(self, params):
cache_path = self._trace_cache_path()
md5file = os.path.join(cache_path, 'md5sum')
+ params_path = os.path.join(cache_path, 'params.json')
- if not os.path.exists(cache_path) or not os.path.exists(md5file):
- return False
+ for path in [cache_path, md5file, params_path]:
+ if not os.path.exists(path):
+ return False
with open(md5file) as f:
cache_md5sum = f.read()
with open(self.trace_path, 'rb') as f:
trace_md5sum = hashlib.md5(f.read()).hexdigest()
+ with open(params_path) as f:
+ cache_params = json.load(f)
# check if cache is valid
- if cache_md5sum != trace_md5sum:
+ if cache_md5sum != trace_md5sum or cache_params != params:
shutil.rmtree(cache_path)
return False
return True
- def _create_trace_cache(self):
+ def _create_trace_cache(self, params):
cache_path = self._trace_cache_path()
md5file = os.path.join(cache_path, 'md5sum')
+ params_path = os.path.join(cache_path, 'params.json')
if os.path.exists(cache_path):
shutil.rmtree(cache_path)
@@ -104,6 +110,9 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
with open(md5file, 'w') as f:
f.write(md5sum)
+ with open(params_path, 'w') as f:
+ json.dump(params, f)
+
def _get_csv_path(self, trace_class):
path = self._trace_cache_path()
return os.path.join(path, trace_class.__class__.__name__ + '.csv')
@@ -173,7 +182,8 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
del scope_classes[name]
def _do_parse(self):
- if not self.__class__.disable_cache and self._check_trace_cache():
+ params = {'window': self.window, 'abs_window': self.abs_window}
+ if not self.__class__.disable_cache and self._check_trace_cache(params):
# Read csv into frames
for trace_class in self.trace_classes:
try:
@@ -190,7 +200,7 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
try:
# Recreate basic cache directories only if nothing cached
if not all([c.cached for c in self.trace_classes]):
- self._create_trace_cache()
+ self._create_trace_cache(params)
# Write out only events that weren't cached before
for trace_class in self.trace_classes: