[PATCH v4 4/6] Optimize default filtering
Nikolay Marchuk
marchuk.nikolay.a at gmail.com
Fri Jul 14 14:55:33 UTC 2017
* filter_action.c (default_flags, clear_default_flags): Add default flags.
(add_action): Clear default flags.
(filter_syscall): Add default_flags to qual_flg.
* strace.c (init): Remove default filters.
---
filter_action.c | 21 +++++++++++++++++++++
strace.c | 3 ---
2 files changed, 21 insertions(+), 3 deletions(-)
diff --git a/filter_action.c b/filter_action.c
index 3bd3d0c..4c944fc 100644
--- a/filter_action.c
+++ b/filter_action.c
@@ -87,6 +87,7 @@ struct filter_action {
void* _priv_data;
};
+static int default_flags = DEFAULT_QUAL_FLAGS;
static struct filter_action *filter_actions;
static unsigned int nfilter_actions;
@@ -110,6 +111,8 @@ compare_action_priority(const void *a, const void *b)
void
filtering_parsing_finish(void)
{
+ if (nfilter_actions == 0)
+ return;
qsort(filter_actions, nfilter_actions, sizeof(struct filter_action),
&compare_action_priority);
/* Allocate variables_buf sufficient for any action */
@@ -122,6 +125,22 @@ filtering_parsing_finish(void)
variables_buf = xcalloc(maxfilters, sizeof(bool));
}
+static void
+clear_default_flags(const char *name)
+{
+ if ((default_flags & QUAL_TRACE) && !strcmp(name, "trace")) {
+ default_flags &= ~QUAL_TRACE;
+ return;
+ } else if ((default_flags & QUAL_ABBREV) && !strcmp(name, "abbrev")) {
+ default_flags &= ~QUAL_ABBREV;
+ return;
+ } else if ((default_flags & QUAL_VERBOSE) && !strcmp(name, "verbose")) {
+ default_flags &= ~QUAL_VERBOSE;
+ return;
+ }
+
+}
+
static const struct filter_action_type *
lookup_filter_action_type(const char *str)
{
@@ -138,6 +157,7 @@ lookup_filter_action_type(const char *str)
static struct filter_action *
add_action(const struct filter_action_type *type)
{
+ clear_default_flags(type->name);
filter_actions = xreallocarray(filter_actions, ++nfilter_actions,
sizeof(struct filter_action));
struct filter_action *action = &filter_actions[nfilter_actions - 1];
@@ -195,6 +215,7 @@ set_qualify_mode(struct filter_action *action)
void
filter_syscall(struct tcb *tcp)
{
+ tcp->qual_flg |= default_flags;
unsigned int i;
for (i = 0; i < nfilter_actions; i++) {
run_filter_action(tcp, &filter_actions[i]);
diff --git a/strace.c b/strace.c
index 6ad367a..b8c027a 100644
--- a/strace.c
+++ b/strace.c
@@ -1637,9 +1637,6 @@ init(int argc, char *argv[])
shared_log = stderr;
set_sortby(DEFAULT_SORTBY);
set_personality(DEFAULT_PERSONALITY);
- parse_qualify_filter("trace=all");
- parse_qualify_filter("abbrev=all");
- parse_qualify_filter("verbose=all");
#if DEFAULT_QUAL_FLAGS != (QUAL_TRACE | QUAL_ABBREV | QUAL_VERBOSE)
# error Bug in DEFAULT_QUAL_FLAGS
#endif
--
2.1.4
More information about the Strace-devel
mailing list