diff options
author | Joel Fernandes <joelaf@google.com> | 2017-06-25 13:07:00 -0700 |
---|---|---|
committer | KP Singh <kpsingh@google.com> | 2017-06-29 23:11:05 +0200 |
commit | 9bb52fae4f0bb3f81da19cc2f0387260d7e21c0d (patch) | |
tree | e17f04ea79a74768e75144ef3361e9064a12b6e6 | |
parent | 677e6e5471b4d20270b8a7a839b6c0a961f7fc3e (diff) | |
download | trappy-9bb52fae4f0bb3f81da19cc2f0387260d7e21c0d.tar.gz |
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 <joelaf@google.com>
Reviewed-by: KP Singh <kpsingh@google.com>
-rw-r--r-- | trappy/ftrace.py | 3 |
1 files changed, 2 insertions, 1 deletions
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 |