ftrace: Add filter for ftrace/print buf
This commit adds a filter that discards some ftrace/print events based
on the content of their buffer.
The filtered ftrace/print events still take space in the ftrace per-cpu
kernel buffer (they're discarded later, in userspace), but do not take
space in the perfetto buffers.
The filter can be configured with multiple rules, processed in order.
Each rule matches the prefix of the ftrace/print buffer. If an
ftrace/print event doesn't match any rule, it will be allowed by the
filter.
For example, the following config discards all the atrace begin and end
slices:
```
ftrace_config
...
print_filter {
rules {
prefix: "B|"
allow: false
}
rules {
prefix: "E|"
allow: false
}
}
...
}
```
Tested by sideloading on Android, capturing a trace with the prefix "C|"
disallowed, and confirming that counters disappear from the UI.
Benchmarks before:
```
------------------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------------------
BM_ParsePageFullOfSchedSwitch 15029 ns 15028 ns 44778
BM_ParsePageFullOfPrint 15130 ns 15130 ns 45195
```
Benchmarks after:
```
------------------------------------------------------------------------------------
Benchmark Time CPU Iterations
------------------------------------------------------------------------------------
BM_ParsePageFullOfSchedSwitch 15241 ns 15240 ns 44093
BM_ParsePageFullOfPrint 15077 ns 15077 ns 45144
BM_ParsePageFullOfPrintWithFilterRules/0 14869 ns 14869 ns 46117
BM_ParsePageFullOfPrintWithFilterRules/1 14801 ns 14801 ns 46633
BM_ParsePageFullOfPrintWithFilterRules/2 15103 ns 15103 ns 46043
BM_ParsePageFullOfPrintWithFilterRules/3 15244 ns 15243 ns 45705
BM_ParsePageFullOfPrintWithFilterRules/4 15662 ns 15662 ns 44557
BM_ParsePageFullOfPrintWithFilterRules/5 16014 ns 16012 ns 43686
BM_ParsePageFullOfPrintWithFilterRules/6 16250 ns 16249 ns 42996
BM_ParsePageFullOfPrintWithFilterRules/7 16552 ns 16551 ns 42189
BM_ParsePageFullOfPrintWithFilterRules/8 16872 ns 16871 ns 41442
BM_ParsePageFullOfPrintWithFilterRules/9 17239 ns 17239 ns 40532
BM_ParsePageFullOfPrintWithFilterRules/10 17608 ns 17608 ns 39784
BM_ParsePageFullOfPrintWithFilterRules/11 17872 ns 17871 ns 39043
BM_ParsePageFullOfPrintWithFilterRules/12 18180 ns 18179 ns 38410
BM_ParsePageFullOfPrintWithFilterRules/13 18543 ns 18543 ns 37765
BM_ParsePageFullOfPrintWithFilterRules/14 18842 ns 18841 ns 37027
BM_ParsePageFullOfPrintWithFilterRules/15 19190 ns 19188 ns 36293
BM_ParsePageFullOfPrintWithFilterRules/16 19506 ns 19505 ns 35820
```
Change-Id: I3c61a0ca614b518d96ea7476c5e94d1404d6aabe
diff --git a/Android.bp b/Android.bp
index 580d90f..110c652 100644
--- a/Android.bp
+++ b/Android.bp
@@ -9949,6 +9949,7 @@
"src/traced/probes/ftrace/ftrace_config_utils.cc",
"src/traced/probes/ftrace/ftrace_controller.cc",
"src/traced/probes/ftrace/ftrace_data_source.cc",
+ "src/traced/probes/ftrace/ftrace_print_filter.cc",
"src/traced/probes/ftrace/ftrace_stats.cc",
"src/traced/probes/ftrace/printk_formats_parser.cc",
"src/traced/probes/ftrace/proto_translation_table.cc",
@@ -10096,6 +10097,7 @@
"src/traced/probes/ftrace/ftrace_config_muxer_unittest.cc",
"src/traced/probes/ftrace/ftrace_config_unittest.cc",
"src/traced/probes/ftrace/ftrace_controller_unittest.cc",
+ "src/traced/probes/ftrace/ftrace_print_filter_unittest.cc",
"src/traced/probes/ftrace/ftrace_procfs_unittest.cc",
"src/traced/probes/ftrace/printk_formats_parser_unittest.cc",
"src/traced/probes/ftrace/proto_translation_table_unittest.cc",