All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libtracefs: New API for getting synthetic event
@ 2022-01-12 16:36 Yordan Karadzhov (VMware)
  2022-01-13  5:01 ` Tzvetomir Stoyanov
  2022-01-13 19:17 ` Steven Rostedt
  0 siblings, 2 replies; 6+ messages in thread
From: Yordan Karadzhov (VMware) @ 2022-01-12 16:36 UTC (permalink / raw)
  To: rostedt, linux-trace-devel; +Cc: Yordan Karadzhov (VMware)

A new API is proposed, to get tep event descriptor for given synthetic
event:

tracefs_synth_get_event ()

The API implementation gets derived from the implementation of the
existing API  tracefs_dynevent_get_event(). It can detect any newly
created or removed synthetic events.

Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
---
 Documentation/libtracefs-synth2.txt | 14 ++++++++++++--
 include/tracefs-local.h             |  2 ++
 include/tracefs.h                   |  2 ++
 src/tracefs-dynevents.c             | 17 +----------------
 src/tracefs-events.c                | 21 +++++++++++++++++++++
 src/tracefs-hist.c                  | 18 ++++++++++++++++++
 6 files changed, 56 insertions(+), 18 deletions(-)

diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt
index 8056ab8..fac155b 100644
--- a/Documentation/libtracefs-synth2.txt
+++ b/Documentation/libtracefs-synth2.txt
@@ -6,7 +6,8 @@ NAME
 tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_echo_cmd, tracefs_synth_complete,
 tracefs_synth_get_start_hist, tracefs_synth_trace, tracefs_synth_snapshot,
 tracefs_synth_get_name, tracefs_synth_raw_fmt, tracefs_synth_show_event,
-tracefs_synth_show_start_hist, tracefs_synth_show_end_hist - Creation of synthetic events
+tracefs_synth_show_start_hist, tracefs_synth_show_end_hist, tracefs_synth_get_event
+- Creation of synthetic events
 
 SYNOPSIS
 --------
@@ -32,7 +33,8 @@ int tracefs_synth_raw_fmt(struct trace_seq pass:[*]seq, struct tracefs_synth pas
 const char *tracefs_synth_show_event(struct tracefs_synth pass:[*]synth);
 const char *tracefs_synth_show_start_hist(struct tracefs_synth pass:[*]synth);
 const char *tracefs_synth_show_end_hist(struct tracefs_synth pass:[*]synth);
-
+tracefs_synth_get_event
+struct tep_event pass:[*]*tracefs_synth_get_event*(struct tep_handle pass:[*]_tep_, struct tracefs_synth pass:[*]_synth_);
 --
 
 DESCRIPTION
@@ -114,11 +116,19 @@ and is freed with the event by *tracefs_synth_free*().
 synthetic event or NULL on error. The returned string belongs to the synth event object
 and is freed with the event by *tracefs_synth_free*().
 
+The *tracefs_synth_get_event*() function returns a tep event, describing the given synthetic
+event. The API detects any newly created or removed dynamic events. The returned pointer to
+tep event is controlled by @tep and must not be freed.
+
 RETURN VALUE
 ------------
 *tracefs_synth_get_name*(), *tracefs_synth_show_event*(), *tracefs_synth_show_start_hist*()
 and *tracefs_synth_show_end_hist*()  return a string owned by the synth event object.
 
+The *tracefs_synth_get_event*() function returns a pointer to a tep event or NULL in case of an
+error or if the requested synthetic event is missing. The returned pointer to tep event is
+controlled by @tep and must not be freed.
+
 All other functions return zero on success or -1 on error.
 
 ERRORS
diff --git a/include/tracefs-local.h b/include/tracefs-local.h
index daea5da..fc0a2c5 100644
--- a/include/tracefs-local.h
+++ b/include/tracefs-local.h
@@ -116,5 +116,7 @@ int trace_load_events(struct tep_handle *tep,
 		      const char *tracing_dir, const char *system);
 int trace_rescan_events(struct tep_handle *tep,
 			const char *tracing_dir, const char *system);
+__hidden struct tep_event *get_tep_event(struct tep_handle *tep,
+					 const char *system, const char *name);
 
 #endif /* _TRACE_FS_LOCAL_H */
diff --git a/include/tracefs.h b/include/tracefs.h
index bd758dc..9c53b84 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -564,5 +564,7 @@ const char *tracefs_synth_show_end_hist(struct tracefs_synth *synth);
 
 struct tracefs_synth *tracefs_sql(struct tep_handle *tep, const char *name,
 				  const char *sql_buffer, char **err);
+struct tep_event *
+tracefs_synth_get_event(struct tep_handle *tep, struct tracefs_synth *synth);
 
 #endif /* _TRACE_FS_H */
diff --git a/src/tracefs-dynevents.c b/src/tracefs-dynevents.c
index d089d02..ddebb6b 100644
--- a/src/tracefs-dynevents.c
+++ b/src/tracefs-dynevents.c
@@ -765,23 +765,8 @@ error:
 struct tep_event *
 tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent)
 {
-	struct tep_event *event;
-
 	if (!tep || !dynevent || !dynevent->event)
 		return NULL;
 
-	/* Check if event exists in the system */
-	if (!tracefs_event_file_exists(NULL, dynevent->system, dynevent->event, "format"))
-		return NULL;
-
-	/* If the dynamic event is already loaded in the tep, return it */
-	event = tep_find_event_by_name(tep, dynevent->system, dynevent->event);
-	if (event)
-		return event;
-
-	/* Try to load any new events from the given system */
-	if (trace_rescan_events(tep, NULL, dynevent->system))
-		return NULL;
-
-	return tep_find_event_by_name(tep, dynevent->system, dynevent->event);
+	return get_tep_event(tep, dynevent->system, dynevent->event);
 }
diff --git a/src/tracefs-events.c b/src/tracefs-events.c
index 067f6e0..30e80ce 100644
--- a/src/tracefs-events.c
+++ b/src/tracefs-events.c
@@ -752,6 +752,27 @@ __hidden int trace_load_events(struct tep_handle *tep,
 	return load_events(tep, tracing_dir, system, false);
 }
 
+__hidden struct tep_event *get_tep_event(struct tep_handle *tep,
+					 const char *system, const char *name)
+{
+	struct tep_event *event;
+
+	/* Check if event exists in the system */
+	if (!tracefs_event_file_exists(NULL, system, name, "format"))
+		return NULL;
+
+	/* If the dynamic event is already loaded in the tep, return it */
+	event = tep_find_event_by_name(tep, system, name);
+	if (event)
+		return event;
+
+	/* Try to load any new events from the given system */
+	if (trace_rescan_events(tep, NULL, system))
+		return NULL;
+
+	return tep_find_event_by_name(tep, system, name);
+}
+
 static int read_header(struct tep_handle *tep, const char *tracing_dir)
 {
 	struct stat st;
diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
index 7146fc1..8d99492 100644
--- a/src/tracefs-hist.c
+++ b/src/tracefs-hist.c
@@ -2197,3 +2197,21 @@ int tracefs_synth_echo_cmd(struct trace_seq *seq,
 	}
 	return ret;
 }
+
+/**
+ * tracefs_synth_get_event - return tep event representing the given synthetic event
+ * @tep: a handle to the trace event parser context that holds the events
+ * @synth: a synthetic event context, describing given synthetic event.
+ *
+ * Returns a pointer to a tep event describing the given synthetic event. The pointer
+ * is managed by the @tep handle and must not be freed. In case of an error, or in case
+ * the requested synthetic event is missing in the @tep handler - NULL is returned.
+ */
+struct tep_event *
+tracefs_synth_get_event(struct tep_handle *tep, struct tracefs_synth *synth)
+{
+	if (!tep || !synth || !synth->name)
+		return NULL;
+
+	return get_tep_event(tep, SYNTHETIC_GROUP, synth->name);
+}
-- 
2.32.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH] libtracefs: New API for getting synthetic event
  2022-01-12 16:36 [PATCH] libtracefs: New API for getting synthetic event Yordan Karadzhov (VMware)
@ 2022-01-13  5:01 ` Tzvetomir Stoyanov
  2022-01-13 10:26   ` Yordan Karadzhov
  2022-01-13 19:17 ` Steven Rostedt
  1 sibling, 1 reply; 6+ messages in thread
From: Tzvetomir Stoyanov @ 2022-01-13  5:01 UTC (permalink / raw)
  To: Yordan Karadzhov (VMware); +Cc: Steven Rostedt, Linux Trace Devel

On Thu, Jan 13, 2022 at 1:33 AM Yordan Karadzhov (VMware)
<y.karadz@gmail.com> wrote:
>
> A new API is proposed, to get tep event descriptor for given synthetic
> event:
>
> tracefs_synth_get_event ()
>
> The API implementation gets derived from the implementation of the
> existing API  tracefs_dynevent_get_event(). It can detect any newly
> created or removed synthetic events.
>
> Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
> ---
>  Documentation/libtracefs-synth2.txt | 14 ++++++++++++--
>  include/tracefs-local.h             |  2 ++
>  include/tracefs.h                   |  2 ++
>  src/tracefs-dynevents.c             | 17 +----------------
>  src/tracefs-events.c                | 21 +++++++++++++++++++++
>  src/tracefs-hist.c                  | 18 ++++++++++++++++++
>  6 files changed, 56 insertions(+), 18 deletions(-)
>
> diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt
> index 8056ab8..fac155b 100644
> --- a/Documentation/libtracefs-synth2.txt
> +++ b/Documentation/libtracefs-synth2.txt
> @@ -6,7 +6,8 @@ NAME
>  tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_echo_cmd, tracefs_synth_complete,
>  tracefs_synth_get_start_hist, tracefs_synth_trace, tracefs_synth_snapshot,
>  tracefs_synth_get_name, tracefs_synth_raw_fmt, tracefs_synth_show_event,
> -tracefs_synth_show_start_hist, tracefs_synth_show_end_hist - Creation of synthetic events
> +tracefs_synth_show_start_hist, tracefs_synth_show_end_hist, tracefs_synth_get_event
> +- Creation of synthetic events
>
>  SYNOPSIS
>  --------
> @@ -32,7 +33,8 @@ int tracefs_synth_raw_fmt(struct trace_seq pass:[*]seq, struct tracefs_synth pas
>  const char *tracefs_synth_show_event(struct tracefs_synth pass:[*]synth);
>  const char *tracefs_synth_show_start_hist(struct tracefs_synth pass:[*]synth);
>  const char *tracefs_synth_show_end_hist(struct tracefs_synth pass:[*]synth);
> -
> +tracefs_synth_get_event

Looks like something forgotten.

> +struct tep_event pass:[*]*tracefs_synth_get_event*(struct tep_handle pass:[*]_tep_, struct tracefs_synth pass:[*]_synth_);

The arguments of the other functions in this man page are not
underlined, all should follow the same style. As in the other man
pages of the library all arguments are underlined, this should be the
default style.
This could be addressed in a follow up patch - applying the same style
of all tracefs man pages.

>  --
>
>  DESCRIPTION
> @@ -114,11 +116,19 @@ and is freed with the event by *tracefs_synth_free*().
>  synthetic event or NULL on error. The returned string belongs to the synth event object
>  and is freed with the event by *tracefs_synth_free*().
>
> +The *tracefs_synth_get_event*() function returns a tep event, describing the given synthetic
> +event. The API detects any newly created or removed dynamic events. The returned pointer to
> +tep event is controlled by @tep and must not be freed.
> +
>  RETURN VALUE
>  ------------
>  *tracefs_synth_get_name*(), *tracefs_synth_show_event*(), *tracefs_synth_show_start_hist*()
>  and *tracefs_synth_show_end_hist*()  return a string owned by the synth event object.
>
> +The *tracefs_synth_get_event*() function returns a pointer to a tep event or NULL in case of an
> +error or if the requested synthetic event is missing. The returned pointer to tep event is
> +controlled by @tep and must not be freed.
> +
>  All other functions return zero on success or -1 on error.
>
>  ERRORS
> diff --git a/include/tracefs-local.h b/include/tracefs-local.h
> index daea5da..fc0a2c5 100644
> --- a/include/tracefs-local.h
> +++ b/include/tracefs-local.h
> @@ -116,5 +116,7 @@ int trace_load_events(struct tep_handle *tep,
>                       const char *tracing_dir, const char *system);
>  int trace_rescan_events(struct tep_handle *tep,
>                         const char *tracing_dir, const char *system);
> +__hidden struct tep_event *get_tep_event(struct tep_handle *tep,
> +                                        const char *system, const char *name);

"__hidden" is not needed here, in the header file. All functions in
tracefs-local.h are hidden and this is specified in their
implementation.

>
>  #endif /* _TRACE_FS_LOCAL_H */
> diff --git a/include/tracefs.h b/include/tracefs.h
> index bd758dc..9c53b84 100644
> --- a/include/tracefs.h
> +++ b/include/tracefs.h
> @@ -564,5 +564,7 @@ const char *tracefs_synth_show_end_hist(struct tracefs_synth *synth);
>
>  struct tracefs_synth *tracefs_sql(struct tep_handle *tep, const char *name,
>                                   const char *sql_buffer, char **err);
> +struct tep_event *
> +tracefs_synth_get_event(struct tep_handle *tep, struct tracefs_synth *synth);
>
>  #endif /* _TRACE_FS_H */
> diff --git a/src/tracefs-dynevents.c b/src/tracefs-dynevents.c
> index d089d02..ddebb6b 100644
> --- a/src/tracefs-dynevents.c
> +++ b/src/tracefs-dynevents.c
> @@ -765,23 +765,8 @@ error:
>  struct tep_event *
>  tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent)
>  {
> -       struct tep_event *event;
> -
>         if (!tep || !dynevent || !dynevent->event)
>                 return NULL;
>
> -       /* Check if event exists in the system */
> -       if (!tracefs_event_file_exists(NULL, dynevent->system, dynevent->event, "format"))
> -               return NULL;
> -
> -       /* If the dynamic event is already loaded in the tep, return it */
> -       event = tep_find_event_by_name(tep, dynevent->system, dynevent->event);
> -       if (event)
> -               return event;
> -
> -       /* Try to load any new events from the given system */
> -       if (trace_rescan_events(tep, NULL, dynevent->system))
> -               return NULL;
> -
> -       return tep_find_event_by_name(tep, dynevent->system, dynevent->event);
> +       return get_tep_event(tep, dynevent->system, dynevent->event);
>  }
> diff --git a/src/tracefs-events.c b/src/tracefs-events.c
> index 067f6e0..30e80ce 100644
> --- a/src/tracefs-events.c
> +++ b/src/tracefs-events.c
> @@ -752,6 +752,27 @@ __hidden int trace_load_events(struct tep_handle *tep,
>         return load_events(tep, tracing_dir, system, false);
>  }
>
> +__hidden struct tep_event *get_tep_event(struct tep_handle *tep,
> +                                        const char *system, const char *name)
> +{
> +       struct tep_event *event;
> +
> +       /* Check if event exists in the system */
> +       if (!tracefs_event_file_exists(NULL, system, name, "format"))
> +               return NULL;
> +
> +       /* If the dynamic event is already loaded in the tep, return it */
> +       event = tep_find_event_by_name(tep, system, name);
> +       if (event)
> +               return event;
> +
> +       /* Try to load any new events from the given system */
> +       if (trace_rescan_events(tep, NULL, system))
> +               return NULL;
> +
> +       return tep_find_event_by_name(tep, system, name);
> +}
> +
>  static int read_header(struct tep_handle *tep, const char *tracing_dir)
>  {
>         struct stat st;
> diff --git a/src/tracefs-hist.c b/src/tracefs-hist.c
> index 7146fc1..8d99492 100644
> --- a/src/tracefs-hist.c
> +++ b/src/tracefs-hist.c
> @@ -2197,3 +2197,21 @@ int tracefs_synth_echo_cmd(struct trace_seq *seq,
>         }
>         return ret;
>  }
> +
> +/**
> + * tracefs_synth_get_event - return tep event representing the given synthetic event
> + * @tep: a handle to the trace event parser context that holds the events
> + * @synth: a synthetic event context, describing given synthetic event.
> + *
> + * Returns a pointer to a tep event describing the given synthetic event. The pointer
> + * is managed by the @tep handle and must not be freed. In case of an error, or in case
> + * the requested synthetic event is missing in the @tep handler - NULL is returned.
> + */
> +struct tep_event *
> +tracefs_synth_get_event(struct tep_handle *tep, struct tracefs_synth *synth)
> +{
> +       if (!tep || !synth || !synth->name)
> +               return NULL;
> +
> +       return get_tep_event(tep, SYNTHETIC_GROUP, synth->name);
> +}
> --
> 2.32.0
>


-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libtracefs: New API for getting synthetic event
  2022-01-13  5:01 ` Tzvetomir Stoyanov
@ 2022-01-13 10:26   ` Yordan Karadzhov
  2022-01-13 12:37     ` Tzvetomir Stoyanov
  0 siblings, 1 reply; 6+ messages in thread
From: Yordan Karadzhov @ 2022-01-13 10:26 UTC (permalink / raw)
  To: Tzvetomir Stoyanov; +Cc: Steven Rostedt, Linux Trace Devel



On 13.01.22 г. 7:01 ч., Tzvetomir Stoyanov wrote:
>> +struct tep_event pass:[*]*tracefs_synth_get_event*(struct tep_handle pass:[*]_tep_, struct tracefs_synth pass:[*]_synth_);
> The arguments of the other functions in this man page are not
> underlined, all should follow the same style. As in the other man
> pages of the library all arguments are underlined, this should be the
> default style.
> This could be addressed in a follow up patch - applying the same style
> of all tracefs man pages.
> 

So, do I have to change something on this particular line?

Thanks!
Yordan

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libtracefs: New API for getting synthetic event
  2022-01-13 10:26   ` Yordan Karadzhov
@ 2022-01-13 12:37     ` Tzvetomir Stoyanov
  2022-01-13 12:41       ` Yordan Karadzhov
  0 siblings, 1 reply; 6+ messages in thread
From: Tzvetomir Stoyanov @ 2022-01-13 12:37 UTC (permalink / raw)
  To: Yordan Karadzhov; +Cc: Steven Rostedt, Linux Trace Devel

On Thu, Jan 13, 2022 at 12:26 PM Yordan Karadzhov <y.karadz@gmail.com> wrote:
>
>
>
> On 13.01.22 г. 7:01 ч., Tzvetomir Stoyanov wrote:
> >> +struct tep_event pass:[*]*tracefs_synth_get_event*(struct tep_handle pass:[*]_tep_, struct tracefs_synth pass:[*]_synth_);
> > The arguments of the other functions in this man page are not
> > underlined, all should follow the same style. As in the other man
> > pages of the library all arguments are underlined, this should be the
> > default style.
> > This could be addressed in a follow up patch - applying the same style
> > of all tracefs man pages.
> >
>
> So, do I have to change something on this particular line?

This line is OK, I'll submit a patch to unify the other man pages. The
arguments should be underlined.

>
> Thanks!
> Yordan



-- 
Tzvetomir (Ceco) Stoyanov
VMware Open Source Technology Center

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libtracefs: New API for getting synthetic event
  2022-01-13 12:37     ` Tzvetomir Stoyanov
@ 2022-01-13 12:41       ` Yordan Karadzhov
  0 siblings, 0 replies; 6+ messages in thread
From: Yordan Karadzhov @ 2022-01-13 12:41 UTC (permalink / raw)
  To: Tzvetomir Stoyanov; +Cc: Steven Rostedt, Linux Trace Devel



On 13.01.22 г. 14:37 ч., Tzvetomir Stoyanov wrote:
> On Thu, Jan 13, 2022 at 12:26 PM Yordan Karadzhov <y.karadz@gmail.com> wrote:
>>
>>
>>
>> On 13.01.22 г. 7:01 ч., Tzvetomir Stoyanov wrote:
>>>> +struct tep_event pass:[*]*tracefs_synth_get_event*(struct tep_handle pass:[*]_tep_, struct tracefs_synth pass:[*]_synth_);
>>> The arguments of the other functions in this man page are not
>>> underlined, all should follow the same style. As in the other man
>>> pages of the library all arguments are underlined, this should be the
>>> default style.
>>> This could be addressed in a follow up patch - applying the same style
>>> of all tracefs man pages.
>>>
>>
>> So, do I have to change something on this particular line?
> 
> This line is OK, I'll submit a patch to unify the other man pages. The
> arguments should be underlined.
> 

OK, I will send v2, fixing the other problems you found in your review.
thanks,
Y.

>>
>> Thanks!
>> Yordan
> 
> 
> 

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH] libtracefs: New API for getting synthetic event
  2022-01-12 16:36 [PATCH] libtracefs: New API for getting synthetic event Yordan Karadzhov (VMware)
  2022-01-13  5:01 ` Tzvetomir Stoyanov
@ 2022-01-13 19:17 ` Steven Rostedt
  1 sibling, 0 replies; 6+ messages in thread
From: Steven Rostedt @ 2022-01-13 19:17 UTC (permalink / raw)
  To: Yordan Karadzhov (VMware); +Cc: linux-trace-devel

On Wed, 12 Jan 2022 18:36:19 +0200
"Yordan Karadzhov (VMware)" <y.karadz@gmail.com> wrote:

> A new API is proposed, to get tep event descriptor for given synthetic
> event:
> 
> tracefs_synth_get_event ()
> 
> The API implementation gets derived from the implementation of the
> existing API  tracefs_dynevent_get_event(). It can detect any newly
> created or removed synthetic events.

Hi Yordan,

> 
> Signed-off-by: Yordan Karadzhov (VMware) <y.karadz@gmail.com>
> ---
>  Documentation/libtracefs-synth2.txt | 14 ++++++++++++--
>  include/tracefs-local.h             |  2 ++
>  include/tracefs.h                   |  2 ++
>  src/tracefs-dynevents.c             | 17 +----------------
>  src/tracefs-events.c                | 21 +++++++++++++++++++++
>  src/tracefs-hist.c                  | 18 ++++++++++++++++++
>  6 files changed, 56 insertions(+), 18 deletions(-)
> 
> diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt
> index 8056ab8..fac155b 100644
> --- a/Documentation/libtracefs-synth2.txt
> +++ b/Documentation/libtracefs-synth2.txt
> @@ -6,7 +6,8 @@ NAME
>  tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_echo_cmd, tracefs_synth_complete,
>  tracefs_synth_get_start_hist, tracefs_synth_trace, tracefs_synth_snapshot,
>  tracefs_synth_get_name, tracefs_synth_raw_fmt, tracefs_synth_show_event,
> -tracefs_synth_show_start_hist, tracefs_synth_show_end_hist - Creation of synthetic events
> +tracefs_synth_show_start_hist, tracefs_synth_show_end_hist, tracefs_synth_get_event
> +- Creation of synthetic events
>  
>  SYNOPSIS
>  --------
> @@ -32,7 +33,8 @@ int tracefs_synth_raw_fmt(struct trace_seq pass:[*]seq, struct tracefs_synth pas
>  const char *tracefs_synth_show_event(struct tracefs_synth pass:[*]synth);
>  const char *tracefs_synth_show_start_hist(struct tracefs_synth pass:[*]synth);
>  const char *tracefs_synth_show_end_hist(struct tracefs_synth pass:[*]synth);
> -
> +tracefs_synth_get_event
> +struct tep_event pass:[*]*tracefs_synth_get_event*(struct tep_handle pass:[*]_tep_, struct tracefs_synth pass:[*]_synth_);
>  --
>  
>  DESCRIPTION
> @@ -114,11 +116,19 @@ and is freed with the event by *tracefs_synth_free*().
>  synthetic event or NULL on error. The returned string belongs to the synth event object
>  and is freed with the event by *tracefs_synth_free*().
>  
> +The *tracefs_synth_get_event*() function returns a tep event, describing the given synthetic
> +event. The API detects any newly created or removed dynamic events. The returned pointer to
> +tep event is controlled by @tep and must not be freed.
> +
>  RETURN VALUE
>  ------------
>  *tracefs_synth_get_name*(), *tracefs_synth_show_event*(), *tracefs_synth_show_start_hist*()
>  and *tracefs_synth_show_end_hist*()  return a string owned by the synth event object.
>  
> +The *tracefs_synth_get_event*() function returns a pointer to a tep event or NULL in case of an
> +error or if the requested synthetic event is missing. The returned pointer to tep event is
> +controlled by @tep and must not be freed.
> +
>  All other functions return zero on success or -1 on error.
>  
>  ERRORS
> diff --git a/include/tracefs-local.h b/include/tracefs-local.h
> index daea5da..fc0a2c5 100644
> --- a/include/tracefs-local.h
> +++ b/include/tracefs-local.h
> @@ -116,5 +116,7 @@ int trace_load_events(struct tep_handle *tep,
>  		      const char *tracing_dir, const char *system);
>  int trace_rescan_events(struct tep_handle *tep,
>  			const char *tracing_dir, const char *system);
> +__hidden struct tep_event *get_tep_event(struct tep_handle *tep,
> +					 const char *system, const char *name);
>  
>  #endif /* _TRACE_FS_LOCAL_H */
> diff --git a/include/tracefs.h b/include/tracefs.h
> index bd758dc..9c53b84 100644
> --- a/include/tracefs.h
> +++ b/include/tracefs.h
> @@ -564,5 +564,7 @@ const char *tracefs_synth_show_end_hist(struct tracefs_synth *synth);
>  
>  struct tracefs_synth *tracefs_sql(struct tep_handle *tep, const char *name,
>  				  const char *sql_buffer, char **err);
> +struct tep_event *
> +tracefs_synth_get_event(struct tep_handle *tep, struct tracefs_synth *synth);
>  
>  #endif /* _TRACE_FS_H */
> diff --git a/src/tracefs-dynevents.c b/src/tracefs-dynevents.c
> index d089d02..ddebb6b 100644
> --- a/src/tracefs-dynevents.c
> +++ b/src/tracefs-dynevents.c
> @@ -765,23 +765,8 @@ error:
>  struct tep_event *
>  tracefs_dynevent_get_event(struct tep_handle *tep, struct tracefs_dynevent *dynevent)
>  {
> -	struct tep_event *event;
> -
>  	if (!tep || !dynevent || !dynevent->event)
>  		return NULL;
>  
> -	/* Check if event exists in the system */
> -	if (!tracefs_event_file_exists(NULL, dynevent->system, dynevent->event, "format"))
> -		return NULL;
> -
> -	/* If the dynamic event is already loaded in the tep, return it */
> -	event = tep_find_event_by_name(tep, dynevent->system, dynevent->event);
> -	if (event)
> -		return event;
> -
> -	/* Try to load any new events from the given system */
> -	if (trace_rescan_events(tep, NULL, dynevent->system))
> -		return NULL;
> -
> -	return tep_find_event_by_name(tep, dynevent->system, dynevent->event);
> +	return get_tep_event(tep, dynevent->system, dynevent->event);
>  }
> diff --git a/src/tracefs-events.c b/src/tracefs-events.c
> index 067f6e0..30e80ce 100644
> --- a/src/tracefs-events.c
> +++ b/src/tracefs-events.c
> @@ -752,6 +752,27 @@ __hidden int trace_load_events(struct tep_handle *tep,
>  	return load_events(tep, tracing_dir, system, false);
>  }
>  
> +__hidden struct tep_event *get_tep_event(struct tep_handle *tep,
> +					 const char *system, const char *name)
> +{
> +	struct tep_event *event;
> +
> +	/* Check if event exists in the system */
> +	if (!tracefs_event_file_exists(NULL, system, name, "format"))
> +		return NULL;
> +
> +	/* If the dynamic event is already loaded in the tep, return it */

As this was moved out of the tracefs_dynevent_get_event() function, we
probably should update the comments too ;-)

	/* If the event is already loaded in the tep handler, return it */

-- Steve

> +	event = tep_find_event_by_name(tep, system, name);
> +	if (event)
> +		return event;
> +
> +	/* Try to load any new events from the given system */
> +	if (trace_rescan_events(tep, NULL, system))
> +		return NULL;
> +
> +	return tep_find_event_by_name(tep, system, name);
> +}
> +

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2022-01-13 19:17 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12 16:36 [PATCH] libtracefs: New API for getting synthetic event Yordan Karadzhov (VMware)
2022-01-13  5:01 ` Tzvetomir Stoyanov
2022-01-13 10:26   ` Yordan Karadzhov
2022-01-13 12:37     ` Tzvetomir Stoyanov
2022-01-13 12:41       ` Yordan Karadzhov
2022-01-13 19:17 ` Steven Rostedt

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.