diff options
author | Joel Fernandes <joelaf@google.com> | 2017-06-25 13:07:00 -0700 |
---|---|---|
committer | Joel Fernandes <joelaf@google.com> | 2017-06-25 13:08:46 -0700 |
commit | c9243e261fb37be1b1149ae6d111e18745b75959 (patch) | |
tree | ba24bf0cd82b1b5272e41475b2b37a4bb21fcfdd | |
parent | 9493bfaba69108b16db1ee21c53c7f0f95eec5ba (diff) | |
download | trappy-c9243e261fb37be1b1149ae6d111e18745b75959.tar.gz |
trappy: Speed up trappy parsing by 20% by skipping regex sub
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.
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>
-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 ee5efec..977fdd4 100644 --- a/trappy/ftrace.py +++ b/trappy/ftrace.py @@ -215,7 +215,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 |