linux-trace-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: "Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com>
Cc: y.karadz@gmail.com, linux-trace-devel@vger.kernel.org
Subject: Re: [PATCH 4/4] libtracefs: New API for applying filter on event.
Date: Wed, 1 Dec 2021 14:55:23 -0500	[thread overview]
Message-ID: <20211201145523.6731a87d@gandalf.local.home> (raw)
In-Reply-To: <20211130050057.336228-5-tz.stoyanov@gmail.com>


Note, the subject should not have a period.

On Tue, 30 Nov 2021 07:00:57 +0200
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> There is no API for applying a filter string on event. Existing APIs

"on an event."

> only constructs and verifies the filter string. Even though the actual

  "only construct and verify"

> applying is just writing into the event's filter file, it is good to
> have a dedicated API for that:

[ add empty line here ]

> 	tracefs_event_apply_filter()
> 
> Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
> ---
>  Documentation/libtracefs-filter.txt | 11 ++++++++++-
>  include/tracefs.h                   |  3 +++
>  src/tracefs-filter.c                | 19 +++++++++++++++++++
>  3 files changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/Documentation/libtracefs-filter.txt b/Documentation/libtracefs-filter.txt
> index 7e167bc..7532c96 100644
> --- a/Documentation/libtracefs-filter.txt
> +++ b/Documentation/libtracefs-filter.txt
> @@ -3,7 +3,8 @@ libtracefs(3)
>  
>  NAME
>  ----
> -tracefs_event_append_filter, tracefs_event_verify_filter - Add and verify event filters
> +tracefs_event_append_filter, tracefs_event_verify_filter tracefs_event_apply_filter -

Missing comma (and you also need to rebase with the updates).


> +Add, verify and apply event filters
>  
>  SYNOPSIS
>  --------
> @@ -15,6 +16,7 @@ int tracefs_event_append_filter(struct tep_event pass:[*]event, char pass:[**] f
>  				 struct tracefs_filter type, const char pass:[*]field,
>  				 enum tracefs_synth_compare compare, const char pass:[*]val);
>  int tracefs_event_verify_filter(struct tep_event pass:[*]event, const char pass:[*]filter, char pass:[**]err);

I renamed the above, because it doesn't really affect the event.

> +int tracefs_event_apply_filter(struct tracefs_instance pass:[*]instance, struct tep_event pass:[*]event, const char pass:[*]filter);

But you can keep this name, as it makes sense to call this
"tracefs_event_.."

>  
>  --
>  
> @@ -66,6 +68,8 @@ error in the syntax, and _err_ is not NULL, then it will be allocated with an
>  error message stating what was found wrong with the filter. _err_ must be freed
>  with *free*().
>  
> +*tracefs_event_apply_filter*() applies given _filter_ string on _event_ in given _instance_.
> +
>  RETURN VALUE
>  ------------
>  *tracefs_event_append_filter*() returns 0 on success and -1 on error.
> @@ -75,6 +79,8 @@ is an error, and _errno_ is not *ENOMEM*, then _err_ is allocated and will
>  contain a string describing what was found wrong with _filter_. _err_ must be
>  freed with *free*().
>  
> +*tracefs_event_apply_filter*() returns 0 on success and -1 on error.
> +
>  EXAMPLE
>  -------
>  [source,c]
> @@ -269,6 +275,9 @@ int main (int argc, char **argv)
>  		}
>  	}
>  
> +	if (tracefs_event_apply_filter(NULL, event, new_filter))
> +		fprintf(stderr, "Failed to apply filter on event");
> +
>  	tep_free(tep);
>  
>  	printf("Created new filter: '%s'\n", new_filter);
> diff --git a/include/tracefs.h b/include/tracefs.h
> index fbd7d31..8ac9694 100644
> --- a/include/tracefs.h
> +++ b/include/tracefs.h
> @@ -475,6 +475,9 @@ int tracefs_event_append_filter(struct tep_event *event, char **filter,
>  				const char *val);
>  int tracefs_event_verify_filter(struct tep_event *event, const char *filter,
>  				char **err);
> +int tracefs_event_apply_filter(struct tracefs_instance *instance,
> +			       struct tep_event *event, const char *filter);
> +
>  
>  #define TRACEFS_TIMESTAMP "common_timestamp"
>  #define TRACEFS_TIMESTAMP_USECS "common_timestamp.usecs"
> diff --git a/src/tracefs-filter.c b/src/tracefs-filter.c
> index def8f68..43683d0 100644
> --- a/src/tracefs-filter.c
> +++ b/src/tracefs-filter.c
> @@ -745,3 +745,22 @@ int tracefs_event_verify_filter(struct tep_event *event, const char *filter,
>  	free(str);
>  	return 0;
>  }
> +
> +/**
> + * tracefs_event_apply_filter - apply given filter on event in given instance
> + * @instance: The instance in which the filter will be applied (NULL for toplevel).
> + * @event: The event to apply the filter on.
> + * @filter: The filter to apply.
> + *
> + * Apply the @filter to given @event in givem @instance. The @filter string
> + * should be created with tracefs_event_append_filter().

The name of the function has been renamed.

> + *
> + * Returns 0 on succes and -1 on error.
> + */
> +int tracefs_event_apply_filter(struct tracefs_instance *instance,
> +			       struct tep_event *event, const char *filter)
> +{
> +	return tracefs_event_file_append(instance, event->system, event->name,
> +					 "filter", filter);

I think we want this to be tracefs_event_file_write(), as it should replace
the filter, not add on to it.

> +}
> +

Note, I moved the old deprecated names at the end of the file. Make sure
they stay at the end. In other words, this goes before them.

-- Steve

      reply	other threads:[~2021-12-01 19:56 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-30  5:00 [PATCH 0/4] New tracefs APIs Tzvetomir Stoyanov (VMware)
2021-11-30  5:00 ` [PATCH 1/4] libtracefs: Reuse logic for loading events inside the library Tzvetomir Stoyanov (VMware)
2021-11-30  5:00 ` [PATCH 2/4] libtracefs: New API for getting dynamic event Tzvetomir Stoyanov (VMware)
2021-12-01 21:04   ` Steven Rostedt
2021-12-02  5:05     ` Tzvetomir Stoyanov
2021-11-30  5:00 ` [PATCH 3/4] libtracefs: Unit test for tracefs_dynevent_get_event() Tzvetomir Stoyanov (VMware)
2021-11-30  5:00 ` [PATCH 4/4] libtracefs: New API for applying filter on event Tzvetomir Stoyanov (VMware)
2021-12-01 19:55   ` Steven Rostedt [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211201145523.6731a87d@gandalf.local.home \
    --to=rostedt@goodmis.org \
    --cc=linux-trace-devel@vger.kernel.org \
    --cc=tz.stoyanov@gmail.com \
    --cc=y.karadz@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).