From 9bb52fae4f0bb3f81da19cc2f0387260d7e21c0d Mon Sep 17 00:00:00 2001 From: Joel Fernandes Date: Sun, 25 Jun 2017 13:07:00 -0700 Subject: trappy: skip empty array regex sub for common case I found that trappy spends a lot of time looking for the array pattern "{}". Vast majority of trace lines don't have them. Instead of running the regex every time, check for the ={} pattern using the 'in' operator which is much faster than the regex for the common case, and then do the regex sub if needed. The speed up is huge and in my test run, I saw parsing stage on a 100MB trace speed up from 13s -> 10.5s !! Change-Id: I7ae68efc99eaf8844624871be2a4d66a7820a9b0 Signed-off-by: Joel Fernandes Reviewed-by: KP Singh --- trappy/ftrace.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/trappy/ftrace.py b/trappy/ftrace.py index ab9ed0a..e2a636c 100644 --- a/trappy/ftrace.py +++ b/trappy/ftrace.py @@ -299,7 +299,8 @@ subclassed by FTrace (for parsing FTrace coming from trace-cmd) and SysTrace.""" return # Remove empty arrays from the trace - data_str = re.sub(r"[A-Za-z0-9_]+=\{\} ", r"", data_str) + if "={}" in data_str: + data_str = re.sub(r"[A-Za-z0-9_]+=\{\} ", r"", data_str) trace_class.append_data(timestamp, comm, pid, cpu, self.lines, data_str) self.lines += 1 -- cgit v1.2.3