[PATCH v6 5/9] Optimize default filtering

Eugene Syromiatnikov esyr at redhat.com
Mon Aug 7 05:29:32 UTC 2017


On Wed, Aug 02, 2017 at 12:36:45PM +0700, Nikolay Marchuk wrote:
> * filter_action.c (default_flags, update_default_flags): Add default flags.
> (add_action): Clear default flags.
> (filter_syscall): Add default_flags to qual_flg.
> (filtering_parse_finish): Init trace action for pathtracing. Don't sort empty
> actions' array.
> * strace.c (init): Remove default filters.
> ---
>  filter_action.c | 26 ++++++++++++++++++++++++++
>  strace.c        |  3 ---
>  2 files changed, 26 insertions(+), 3 deletions(-)
> 
> diff --git a/filter_action.c b/filter_action.c
> index f8bca97..74a2d29 100644
> --- a/filter_action.c
> +++ b/filter_action.c
> @@ -90,6 +90,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;
>  
> @@ -117,7 +118,14 @@ filtering_parsing_finish(void)
>  	unsigned int maxfilters = 0;
>  	unsigned int i;
>  
> +	/* Init trace action if pathtracing is enabled */
> +	if (tracing_paths && (default_flags & QUAL_TRACE)) {
> +		parse_qualify_filter("trace=all");
> +	}
Braces may be omitted here.

Otherwise, this is quite interesting special case.

> +
>  	/* Sort actions by priority */
> +	if (nfilter_actions == 0)
> +		return;
Since filter_actions may be NULL, this check should be added in
"Introduce new filtering architecture".

>  	qsort(filter_actions, nfilter_actions, sizeof(struct filter_action),
>  	      &compare_action_priority);
>  
> @@ -128,6 +136,22 @@ filtering_parsing_finish(void)
>  	}
>  	variables_buf = xcalloc(maxfilters, sizeof(bool));
>  }
> +static void
> +update_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;
> +	}
I'd prefer having this check not so hard-coded. For example, it is
possible to have corresponding QUAL_* flag in filter_action descriptor,
in this case check could be reduced to something like

	if (default_flags & type->qual_flg)
		default_flags &= ~type->qual_flg

inside add_action.

> +
Bogus empty line.

> +}
> +
>  
>  static const struct filter_action_type *
>  lookup_filter_action_type(const char *str)
> @@ -146,6 +170,7 @@ add_action(const struct filter_action_type *type)
>  {
>  	struct filter_action *action;
>  
> +	update_default_flags(type->name);
>  	filter_actions = xreallocarray(filter_actions, ++nfilter_actions,
>  				       sizeof(struct filter_action));
>  	action = &filter_actions[nfilter_actions - 1];
> @@ -203,6 +228,7 @@ filter_syscall(struct tcb *tcp)
>  {
>  	unsigned int i;
>  
> +	tcp->qual_flg |= default_flags;
>  	for (i = 0; i < nfilter_actions; ++i)
>  		run_filter_action(tcp, &filter_actions[i]);
>  }
> diff --git a/strace.c b/strace.c
> index 0e82cc5..137559c 100644
> --- a/strace.c
> +++ b/strace.c
> @@ -1645,9 +1645,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