aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKapileshwar Singh <kapileshwarsingh@gmail.com>2017-06-30 11:59:25 +0200
committerGitHub <noreply@github.com>2017-06-30 11:59:25 +0200
commit46660d432e6ecb68dec8ff38180d93ba4e6ec7f0 (patch)
tree3469bbd029f3333540ab8837fa958d3dbe904bb7
parent180ba383f2ab4e544273a1e75e8bee61df654ceb (diff)
parentcd7f2e045fa07bb14433a6506ab8756e94cd0f19 (diff)
downloadtrappy-46660d432e6ecb68dec8ff38180d93ba4e6ec7f0.tar.gz
Merge pull request #259 from joelagnel/trappy-cache-fixes
Trappy cache fixes
-rw-r--r--trappy/bare_trace.py3
-rw-r--r--trappy/ftrace.py21
2 files changed, 21 insertions, 3 deletions
diff --git a/trappy/bare_trace.py b/trappy/bare_trace.py
index e4fec48..a953a60 100644
--- a/trappy/bare_trace.py
+++ b/trappy/bare_trace.py
@@ -134,6 +134,9 @@ class BareTrace(object):
def finalize_objects(self):
for trace_class in self.trace_classes:
+ # If cached, don't need to do any other DF operation
+ if trace_class.cached:
+ continue
trace_class.tracer = self
trace_class.create_dataframe()
trace_class.finalize_object()
diff --git a/trappy/ftrace.py b/trappy/ftrace.py
index c0a40c2..226cd96 100644
--- a/trappy/ftrace.py
+++ b/trappy/ftrace.py
@@ -78,6 +78,7 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
def _check_trace_cache(self, params):
cache_path = self._trace_cache_path()
md5file = os.path.join(cache_path, 'md5sum')
+ basetime_path = os.path.join(cache_path, 'basetime')
params_path = os.path.join(cache_path, 'params.json')
for path in [cache_path, md5file, params_path]:
@@ -86,10 +87,15 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
with open(md5file) as f:
cache_md5sum = f.read()
+ with open(basetime_path) as f:
+ self.basetime = float(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)
+ cache_params = json.dumps(json.load(f))
+
+ # Convert to a json string for comparison
+ params = json.dumps(params)
# check if cache is valid
if cache_md5sum != trace_md5sum or cache_params != params:
@@ -100,6 +106,7 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
def _create_trace_cache(self, params):
cache_path = self._trace_cache_path()
md5file = os.path.join(cache_path, 'md5sum')
+ basetime_path = os.path.join(cache_path, 'basetime')
params_path = os.path.join(cache_path, 'params.json')
if os.path.exists(cache_path):
@@ -110,6 +117,9 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
with open(md5file, 'w') as f:
f.write(md5sum)
+ with open(basetime_path, 'w') as f:
+ f.write(str(self.basetime))
+
with open(params_path, 'w') as f:
json.dump(params, f)
@@ -194,8 +204,15 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
warnstr = "TRAPpy: Couldn't read {} from cache, reading it from trace".format(trace_class)
warnings.warn(warnstr)
+ if all([c.cached for c in self.trace_classes]):
+ if self.normalize_time:
+ self._normalize_time()
+ return
+
self.__parse_trace_file(self.trace_path)
+ self.finalize_objects()
+
if not self.__class__.disable_cache:
try:
# Recreate basic cache directories only if nothing cached
@@ -212,8 +229,6 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace."""
warnings.warn(
"TRAPpy: Cache not created due to OS error: {0}".format(err))
- self.finalize_objects()
-
if self.normalize_time:
self._normalize_time()