diff mbox series

[2/2] libtracefs: Documentation for tracefs_synth_set_instance

Message ID 20230328150321.34808-3-tz.stoyanov@gmail.com (mailing list archive)
State Accepted
Commit c860f934852142751886b9c68e0a5dade6089500
Headers show
Series Introduce new API to set synthetic event instance | expand

Commit Message

Tzvetomir Stoyanov (VMware) March 28, 2023, 3:03 p.m. UTC
The newly introduced API tracefs_synth_set_instance() should be
described in the man pages of the tracefs library.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 Documentation/libtracefs-synth2.txt | 15 +++++++++++----
 Documentation/libtracefs.txt        |  1 +
 2 files changed, 12 insertions(+), 4 deletions(-)

Comments

Steven Rostedt May 30, 2023, 4:50 a.m. UTC | #1
On Tue, 28 Mar 2023 18:03:21 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

> @@ -45,9 +46,11 @@ as a field for both events to calculate the delta in nanoseconds, or use
>  *TRACEFS_TIMESTAMP_USECS* as the compare fields for both events to calculate the
>  delta in microseconds. This is used as the example below.
>  
> -*tracefs_synth_create*() creates the synthetic event in the system. The synthetic events apply
> -across all instances. A synthetic event must be created with *tracefs_synth_alloc*(3) before
> -it can be created.
> +*tracefs_synth_create*() creates the synthetic event in the system. By default, the synthetic
> +events are created in the top trace instance and apply across all instances.
> +The *tracefs_synth_set_instance()* API can be used to set a custom instance, where the synthetic
> +event will be created. In that case the event operates only in that instance. A synthetic event

The above is somewhat incorrect. That makes it sound like you can not
use the event elsewhere, where you most certainly can.

 ># cd /sys/kernel/tracing
 ># mkdir instances/foo
 ># echo 'wakeup pid_t pid; u64 lat' > synthetic_events
 ># echo 'hist:keys=pid:ts=common_timestamp.usecs' > instances/foo/events/sched/sched_waking/trigger
 ># echo 'hist:keys=next_pid:lat=common_timestamp.usecs-$ts:onmatch(sched.sched_waking).trace(wakeup,next_pid,$lat)' > instances/foo/events/sched/sched_switch/trigger
 ># mkdir instances/bar
 ># echo 1 > instances/bar/events/synthetic/wakeup/enable
 ># cat instances/bar/trace
# tracer: nop
#
# entries-in-buffer/entries-written: 73761/73761   #P:8
#
#                                _-----=> irqs-off/BH-disabled
#                               / _----=> need-resched
#                              | / _---=> hardirq/softirq
#                              || / _--=> preempt-depth
#                              ||| / _-=> migrate-disable
#                              |||| /     delay
#           TASK-PID     CPU#  |||||  TIMESTAMP  FUNCTION
#              | |         |   |||||     |         |
          <idle>-0       [001] d..4. 56208.972686: wakeup: pid=1352 lat=25
            bash-843     [002] d..4. 56208.972784: wakeup: pid=1353 lat=20
          <idle>-0       [004] d..4. 56208.972894: wakeup: pid=3408 lat=25
          <idle>-0       [006] d..4. 56208.972937: wakeup: pid=820 lat=33
          <idle>-0       [004] d..4. 56208.972951: wakeup: pid=3408 lat=23
          <idle>-0       [004] d..4. 56208.972993: wakeup: pid=1355 lat=12
          <idle>-0       [003] d..4. 56208.973030: wakeup: pid=1354 lat=26


Now, I am going to apply these patches, but I also will update them to
reflect the actual benefit of them. The issue I see is that you have
triggers in the toplevel (histograms). And perhaps you don't want those
histograms there, and want to keep the histograms used to create a
synthetic event in a particular instance. That makes more sense,
although it's not that much of a interference, as you can add more than
one histogram to an event.

 ># cat instances/foo/events/sched/sched_waking/hist
# event histogram
#
# trigger info: hist:keys=pid:vals=hitcount:ts=common_timestamp.usecs:sort=hitcount:size=2048:clock=global [active]
#

{ pid:          2 } hitcount:          1
{ pid:         41 } hitcount:          1
{ pid:       3609 } hitcount:          1
{ pid:         26 } hitcount:          1
{ pid:       3612 } hitcount:          1
{ pid:         15 } hitcount:          1
[..]
{ pid:        289 } hitcount:       1920
{ pid:        454 } hitcount:       3747
{ pid:         84 } hitcount:       4714
{ pid:       3257 } hitcount:      83897
{ pid:       1351 } hitcount:     681823
{ pid:       1357 } hitcount:     681830
{ pid:       1353 } hitcount:     681831
{ pid:       1352 } hitcount:     681834
{ pid:       1358 } hitcount:     681837
{ pid:       1356 } hitcount:     681869
{ pid:       1355 } hitcount:     681872
{ pid:       1354 } hitcount:     681878

Totals:
    Hits: 5564963
    Entries: 89
    Dropped: 0

 ># cat events/sched/sched_waking/hist
 >#

-- Steve


> +must be created with *tracefs_synth_alloc*(3) before it can be created.
>
diff mbox series

Patch

diff --git a/Documentation/libtracefs-synth2.txt b/Documentation/libtracefs-synth2.txt
index 7e8e6cc..d94fa7c 100644
--- a/Documentation/libtracefs-synth2.txt
+++ b/Documentation/libtracefs-synth2.txt
@@ -4,7 +4,7 @@  libtracefs(3)
 NAME
 ----
 tracefs_synth_create, tracefs_synth_destroy, tracefs_synth_complete,
-tracefs_synth_trace, tracefs_synth_snapshot, tracefs_synth_save
+tracefs_synth_trace, tracefs_synth_snapshot, tracefs_synth_save,tracefs_synth_set_instance,
 - Creation of synthetic events
 
 SYNOPSIS
@@ -17,6 +17,7 @@  int *tracefs_synth_create*(struct tracefs_synth pass:[*]_synth_);
 int *tracefs_synth_destroy*(struct tracefs_synth pass:[*]_synth_);
 bool *tracefs_synth_complete*(struct tracefs_synth pass:[*]_synth_);
 
+int *tracefs_synth_set_instance*(struct tracefs_synth pass:[*]_synth_, struct tracefs_instance pass:[*]_instance_);
 int *tracefs_synth_trace*(struct tracefs_synth pass:[*]_synth_,
 			enum tracefs_synth_handler _type_, const char pass:[*]_var_);
 int *tracefs_synth_snapshot*(struct tracefs_synth pass:[*]_synth_,
@@ -45,9 +46,11 @@  as a field for both events to calculate the delta in nanoseconds, or use
 *TRACEFS_TIMESTAMP_USECS* as the compare fields for both events to calculate the
 delta in microseconds. This is used as the example below.
 
-*tracefs_synth_create*() creates the synthetic event in the system. The synthetic events apply
-across all instances. A synthetic event must be created with *tracefs_synth_alloc*(3) before
-it can be created.
+*tracefs_synth_create*() creates the synthetic event in the system. By default, the synthetic
+events are created in the top trace instance and apply across all instances.
+The *tracefs_synth_set_instance()* API can be used to set a custom instance, where the synthetic
+event will be created. In that case the event operates only in that instance. A synthetic event
+must be created with *tracefs_synth_alloc*(3) before it can be created.
 
 *tracefs_synth_destroy*() destroys the synthetic event. It will attempt to stop the running of it in
 its instance (top by default), but if its running in another instance this may fail as busy.
@@ -74,6 +77,10 @@  then save the given _save_fields_ list. The fields will be stored in the histogr
 "hist" file of the event that can be retrieved with *tracefs_event_file_read*(3).
 _var_ must be one of the _name_ elements used in *tracefs_synth_add_end_field*(3).
 
+*tracefs_synth_set_instance()* Set the trace instance, where the synthetic event will be
+created. By default, the top instance is used. This API must be called before the call to
+*tracefs_synth_create()*, in order to use the new instance when creating the event.
+
 RETURN VALUE
 ------------
 All functions return zero on success or -1 on error.
diff --git a/Documentation/libtracefs.txt b/Documentation/libtracefs.txt
index c3f448d..daf044f 100644
--- a/Documentation/libtracefs.txt
+++ b/Documentation/libtracefs.txt
@@ -213,6 +213,7 @@  Synthetic events:
 	void *tracefs_synth_free*(struct tracefs_synth pass:[*]_synth_);
 	int *tracefs_synth_create*(struct tracefs_synth pass:[*]_synth_);
 	int *tracefs_synth_destroy*(struct tracefs_synth pass:[*]_synth_);
+	int *tracefs_synth_set_instance*(struct tracefs_synth pass:[*]_synth_, struct tracefs_instance pass:[*]_instance_);
 	int *tracefs_synth_echo_cmd*(struct trace_seq pass:[*]_seq_, struct tracefs_synth pass:[*]_synth_);
 	bool *tracefs_synth_complete*(struct tracefs_synth pass:[*]_synth_);
 	struct tracefs_hist pass:[*]*tracefs_synth_get_start_hist*(struct tracefs_synth pass:[*]_synth_);