All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/11] libtracefs: Have all man page examples be executable
@ 2021-11-22 23:49 Steven Rostedt
  2021-11-22 23:49 ` [PATCH 01/11] libtracefs: Move creation of sqlhist into new samples directory Steven Rostedt
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Fix the man pages, and add a "make samples" that extracts the man page
examples to create executables from.

Note, several man pages do not have a proper example, and those will
need to be updated to have one.

Steven Rostedt (VMware) (11):
  libtracefs: Move creation of sqlhist into new samples directory
  libtracefs: Fix example in the dynamic events man page to compile
  libtracefs/Documentation: Fix man page examples to include the proper
    header
  tracefs/Documentation: Fix example in libtracefs-eprobes.txt to
    compile
  libtracefs: Make samples easily extract man page example programs
  libtracefs: Add new API tracefs_dynevent_get()
  libtracefs/Documentation: Fix example in libtracefs-error.txt
  libtracefs/Documentation: Fix function-filter call to
    tracefs_list_free()
  libtracefs/Documentation: Update libtracefs-hist-cont.txt to new API
  libtracefs: Add all working man page examples to samples
  libtracefs/Documentation: Update stream example to have a parameter

 Documentation/libtracefs-dynevents.txt       | 14 +++-
 Documentation/libtracefs-eprobes.txt         |  6 +-
 Documentation/libtracefs-error.txt           |  9 ++-
 Documentation/libtracefs-function-filter.txt |  2 +-
 Documentation/libtracefs-hist-cont.txt       | 29 +++++---
 Documentation/libtracefs-hist.txt            |  2 +-
 Documentation/libtracefs-kprobes.txt         |  2 +-
 Documentation/libtracefs-stream.txt          | 18 ++++-
 Makefile                                     | 14 ++--
 include/tracefs.h                            |  2 +
 samples/Makefile                             | 69 ++++++++++++++++++++
 src/tracefs-dynevents.c                      | 45 +++++++++++++
 12 files changed, 181 insertions(+), 31 deletions(-)
 create mode 100644 samples/Makefile

-- 
2.31.1


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

* [PATCH 01/11] libtracefs: Move creation of sqlhist into new samples directory
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 02/11] libtracefs: Fix example in the dynamic events man page to compile Steven Rostedt
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Move the creation of the sqlhist utility into the samples directory. This
will be where other examples in the man pages will be extracted to create
the samples.

The executables will be added to a new bin/ directory as well as the
intermediate files used to create the binaries.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Makefile         | 13 +++++--------
 samples/Makefile | 27 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 8 deletions(-)
 create mode 100644 samples/Makefile

diff --git a/Makefile b/Makefile
index 7f382c3..7c96674 100644
--- a/Makefile
+++ b/Makefile
@@ -142,6 +142,7 @@ LIBS = $(LIBTRACEEVENT_LIBS) -lpthread
 
 export LIBS
 export LIBTRACEFS_STATIC LIBTRACEFS_SHARED
+export LIBTRACEEVENT_LIBS LIBTRACEEVENT_INCLUDES
 
 export Q SILENT VERBOSE EXT
 
@@ -364,21 +365,17 @@ $(bdir)/libtracefs.so.$(TRACEFS_VERSION): force
 	$(Q)mkdir -p $(bdir)
 	$(Q)$(MAKE) -C $(src)/src libtracefs.so
 
-$(bdir)/sqlhist.c: Documentation/libtracefs-sql.txt
-	cat $< | sed -ne '/^EXAMPLE/,/FILES/ { /EXAMPLE/,+2d ; /^FILES/d ;  /^--/d ; p}' > $@
+samples/sqlhist: $(LIBTRACEFS_STATIC)
+	$(Q)$(MAKE) -C $(src)/samples sqlhist
 
-$(bdir)/sqlhist.o: $(bdir)/sqlhist.c
-	$(CC) -g -Wall -c -o $@ $^ -Iinclude/ $(LIBTRACEEVENT_INCLUDES)
-
-sqlhist: $(bdir)/sqlhist.o $(LIBTRACEFS_STATIC)
-	$(CC) -o $@ $^ $(LIBTRACEEVENT_LIBS)
+sqlhist: samples/sqlhist
 
 clean:
 	$(MAKE) -C $(src)/utest clean
 	$(MAKE) -C $(src)/src clean
+	$(MAKE) -C $(src)/samples clean
 	$(RM) $(TARGETS) $(bdir)/*.a $(bdir)/*.so $(bdir)/*.so.* $(bdir)/*.o $(bdir)/.*.d
 	$(RM) $(PKG_CONFIG_FILE)
 	$(RM) $(VERSION_FILE)
-	$(RM) $(bdir)/sqlhist.o $(bdir)/sqlhist.c sqlhist
 
 .PHONY: clean
diff --git a/samples/Makefile b/samples/Makefile
new file mode 100644
index 0000000..aae3e27
--- /dev/null
+++ b/samples/Makefile
@@ -0,0 +1,27 @@
+# SPDX-License-Identifier: LGPL-2.1
+
+#
+# The samples are pulled out of the examples used in the man pages
+# that are located in the Documentation directory.
+#
+
+include $(src)/scripts/utils.mk
+
+bdir := $(obj)/bin
+
+$(bdir):
+	@mkdir -p $(bdir)
+
+sqlhist: $(bdir) $(bdir) $(bdir)/sqlhist
+
+$(bdir)/sqlhist: $(bdir)/sqlhist.o $(LIBTRACEFS_STATIC)
+	$(CC) -o $@ $^ $(LIBTRACEEVENT_LIBS)
+
+$(bdir)/sqlhist.c: ../Documentation/libtracefs-sql.txt
+	cat $< | sed -ne '/^EXAMPLE/,/FILES/ { /EXAMPLE/,+2d ; /^FILES/d ;  /^--/d ; p}' > $@
+
+$(bdir)/sqlhist.o: $(bdir)/sqlhist.c
+	$(CC) -g -Wall -c -o $@ $^ -I../include/ $(LIBTRACEEVENT_INCLUDES)
+
+clean:
+	$(RM) $(bdir)/*
-- 
2.31.1


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

* [PATCH 02/11] libtracefs: Fix example in the dynamic events man page to compile
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
  2021-11-22 23:49 ` [PATCH 01/11] libtracefs: Move creation of sqlhist into new samples directory Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 03/11] libtracefs/Documentation: Fix man page examples to include the proper header Steven Rostedt
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The example in the dynamic events man page fails to compile because it
references an "err" variable without declaring it. Declare it so that the
example will compile.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-dynevents.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/libtracefs-dynevents.txt b/Documentation/libtracefs-dynevents.txt
index 25172c3..503bd7e 100644
--- a/Documentation/libtracefs-dynevents.txt
+++ b/Documentation/libtracefs-dynevents.txt
@@ -182,7 +182,7 @@ int main (int argc, char **argv, char **env)
 	}
 
 	if (tracefs_dynevent_create(kprobe) || tracefs_dynevent_create(kretprobe)){
-		err = tracefs_error_last(NULL);
+		char *err = tracefs_error_last(NULL);
 		perror("Failed to create kprobes:");
 		if (err && strlen(err))
 			fprintf(stderr, "%s\n", err);
-- 
2.31.1


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

* [PATCH 03/11] libtracefs/Documentation: Fix man page examples to include the proper header
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
  2021-11-22 23:49 ` [PATCH 01/11] libtracefs: Move creation of sqlhist into new samples directory Steven Rostedt
  2021-11-22 23:49 ` [PATCH 02/11] libtracefs: Fix example in the dynamic events man page to compile Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 04/11] tracefs/Documentation: Fix example in libtracefs-eprobes.txt to compile Steven Rostedt
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

It's #include <tracefs.h> not #include <tracefs/tracefs.h> as the
pkg-config will give the full path to the include headers. Anything else
will not build properly.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-dynevents.txt | 2 +-
 Documentation/libtracefs-eprobes.txt   | 2 +-
 Documentation/libtracefs-error.txt     | 2 +-
 Documentation/libtracefs-hist-cont.txt | 2 +-
 Documentation/libtracefs-hist.txt      | 2 +-
 Documentation/libtracefs-kprobes.txt   | 2 +-
 6 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Documentation/libtracefs-dynevents.txt b/Documentation/libtracefs-dynevents.txt
index 503bd7e..89b2e92 100644
--- a/Documentation/libtracefs-dynevents.txt
+++ b/Documentation/libtracefs-dynevents.txt
@@ -101,7 +101,7 @@ EXAMPLE
 #include <unistd.h>
 #include <sys/wait.h>
 
-#include <tracefs/tracefs.h>
+#include <tracefs.h>
 
 static struct tep_event *open_event;
 static struct tep_format_field *file_field;
diff --git a/Documentation/libtracefs-eprobes.txt b/Documentation/libtracefs-eprobes.txt
index 3baaea3..65e5b13 100644
--- a/Documentation/libtracefs-eprobes.txt
+++ b/Documentation/libtracefs-eprobes.txt
@@ -41,7 +41,7 @@ EXAMPLE
 #include <unistd.h>
 #include <sys/wait.h>
 
-#include <tracefs/tracefs.h>
+#include <tracefs.h>
 
 static struct tep_event *open_event;
 static struct tep_format_field *file_field;
diff --git a/Documentation/libtracefs-error.txt b/Documentation/libtracefs-error.txt
index 3f6a154..33af074 100644
--- a/Documentation/libtracefs-error.txt
+++ b/Documentation/libtracefs-error.txt
@@ -48,7 +48,7 @@ EXAMPLE
 #include <unistd.h>
 #include <errno.h>
 
-#include <tracefs/tracefs.h>
+#include <tracefs.h>
 
 int main (int argc, char **argv, char **env)
 {
diff --git a/Documentation/libtracefs-hist-cont.txt b/Documentation/libtracefs-hist-cont.txt
index 2ee830d..778b8ee 100644
--- a/Documentation/libtracefs-hist-cont.txt
+++ b/Documentation/libtracefs-hist-cont.txt
@@ -51,7 +51,7 @@ EXAMPLE
 [source,c]
 --
 #include <stdlib.h>
-#include <tracefs/tracefs.h>
+#include <tracefs.h>
 
 enum commands {
 	START,
diff --git a/Documentation/libtracefs-hist.txt b/Documentation/libtracefs-hist.txt
index cc6b859..c07fe6f 100644
--- a/Documentation/libtracefs-hist.txt
+++ b/Documentation/libtracefs-hist.txt
@@ -222,7 +222,7 @@ EXAMPLE
 [source,c]
 --
 #include <stdlib.h>
-#include <tracefs/tracefs.h>
+#include <tracefs.h>
 
 enum commands {
 	START,
diff --git a/Documentation/libtracefs-kprobes.txt b/Documentation/libtracefs-kprobes.txt
index 4a4bf01..e488f9a 100644
--- a/Documentation/libtracefs-kprobes.txt
+++ b/Documentation/libtracefs-kprobes.txt
@@ -89,7 +89,7 @@ EXAMPLE
 #include <unistd.h>
 #include <sys/wait.h>
 
-#include <tracefs/tracefs.h>
+#include <tracefs.h>
 
 static struct tep_event *open_event;
 static struct tep_format_field *file_field;
-- 
2.31.1


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

* [PATCH 04/11] tracefs/Documentation: Fix example in libtracefs-eprobes.txt to compile
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
                   ` (2 preceding siblings ...)
  2021-11-22 23:49 ` [PATCH 03/11] libtracefs/Documentation: Fix man page examples to include the proper header Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 05/11] libtracefs: Make samples easily extract man page example programs Steven Rostedt
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The example program in libtracefs-eprobes.txt man page did not compile,
and had a warning. Fix the mykprobe string, and remove the unused label.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-eprobes.txt | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/Documentation/libtracefs-eprobes.txt b/Documentation/libtracefs-eprobes.txt
index 65e5b13..4155544 100644
--- a/Documentation/libtracefs-eprobes.txt
+++ b/Documentation/libtracefs-eprobes.txt
@@ -62,8 +62,6 @@ static int callback(struct tep_event *event, struct tep_record *record,
 
 	trace_seq_terminate(&seq);
 	trace_seq_do_printf(&seq);
-
-out:
 	trace_seq_destroy(&seq);
 
 	return 0;
@@ -89,7 +87,7 @@ int main (int argc, char **argv, char **env)
 	struct tracefs_dynevent *eprobe;
 	struct tracefs_instance *instance;
 	struct tep_handle *tep;
-	const char *sysnames[] = { mykprobe, NULL };
+	const char *sysnames[] = { myprobe, NULL };
 	pid_t pid;
 
 	if (argc < 2) {
-- 
2.31.1


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

* [PATCH 05/11] libtracefs: Make samples easily extract man page example programs
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
                   ` (3 preceding siblings ...)
  2021-11-22 23:49 ` [PATCH 04/11] tracefs/Documentation: Fix example in libtracefs-eprobes.txt to compile Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 06/11] libtracefs: Add new API tracefs_dynevent_get() Steven Rostedt
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Have the Makefile in the samples directory extract examples out of the man
pages and create them as executables in the bin directory.

This adds the infrastructure to do so, and includes the dynevent example.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Makefile         |  3 +++
 samples/Makefile | 26 +++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/Makefile b/Makefile
index 7c96674..85b3c39 100644
--- a/Makefile
+++ b/Makefile
@@ -370,6 +370,9 @@ samples/sqlhist: $(LIBTRACEFS_STATIC)
 
 sqlhist: samples/sqlhist
 
+samples: $(LIBTRACEFS_STATIC) force
+	$(Q)$(MAKE) -C $(src)/samples all
+
 clean:
 	$(MAKE) -C $(src)/utest clean
 	$(MAKE) -C $(src)/src clean
diff --git a/samples/Makefile b/samples/Makefile
index aae3e27..53b6630 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -7,20 +7,36 @@
 
 include $(src)/scripts/utils.mk
 
+TARGETS :=
+TARGETS += sqlhist
+TARGETS += dynevent
+
 bdir := $(obj)/bin
 
+all: $(TARGETS)
+
+extract_example = \
+	cat $1 | sed -ne '/^EXAMPLE/,/FILES/ { /EXAMPLE/,+2d ; /^FILES/d ;  /^--/d ; p}' > $2
+
+$(bdir)/sqlhist.c: ../Documentation/libtracefs-sql.txt
+	$(call extract_example,$<,$@)
+
+$(bdir)/dynevent.c: ../Documentation/libtracefs-dynevents.txt
+	$(call extract_example,$<,$@)
+
 $(bdir):
 	@mkdir -p $(bdir)
 
 sqlhist: $(bdir) $(bdir) $(bdir)/sqlhist
 
-$(bdir)/sqlhist: $(bdir)/sqlhist.o $(LIBTRACEFS_STATIC)
-	$(CC) -o $@ $^ $(LIBTRACEEVENT_LIBS)
+$(TARGETS): $(bdir)
 
-$(bdir)/sqlhist.c: ../Documentation/libtracefs-sql.txt
-	cat $< | sed -ne '/^EXAMPLE/,/FILES/ { /EXAMPLE/,+2d ; /^FILES/d ;  /^--/d ; p}' > $@
+$(bdir)/%: $(bdir)/%.o
+	$(CC) -o $@ $^ $(LIBTRACEFS_STATIC) $(LIBTRACEEVENT_LIBS)
+
+$(TARGETS): $(patsubst %,$(bdir)/%,$(TARGETS))
 
-$(bdir)/sqlhist.o: $(bdir)/sqlhist.c
+$(bdir)/%.o: %.c
 	$(CC) -g -Wall -c -o $@ $^ -I../include/ $(LIBTRACEEVENT_INCLUDES)
 
 clean:
-- 
2.31.1


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

* [PATCH 06/11] libtracefs: Add new API tracefs_dynevent_get()
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
                   ` (4 preceding siblings ...)
  2021-11-22 23:49 ` [PATCH 05/11] libtracefs: Make samples easily extract man page example programs Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 07/11] libtracefs/Documentation: Fix example in libtracefs-error.txt Steven Rostedt
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Add tracefs_dynevent_get() that allows the user to look for a single
event, and not have to get all events in the system.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-dynevents.txt | 10 ++++++
 include/tracefs.h                      |  2 ++
 src/tracefs-dynevents.c                | 45 ++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)

diff --git a/Documentation/libtracefs-dynevents.txt b/Documentation/libtracefs-dynevents.txt
index 89b2e92..a374651 100644
--- a/Documentation/libtracefs-dynevents.txt
+++ b/Documentation/libtracefs-dynevents.txt
@@ -20,6 +20,7 @@ int *tracefs_dynevent_destroy*(struct tracefs_dynevent pass:[*]_devent_, bool _f
 int *tracefs_dynevent_destroy_all*(unsigned int _types_, bool _force_);
 void *tracefs_dynevent_free*(struct tracefs_dynevent pass:[*]_devent_);
 void *tracefs_dynevent_list_free*(struct tracefs_dynevent pass:[*]pass:[*]_events_);
+struct tracefs_dynevent pass:[*]*tracefs_dynevent_get*(enum tracefs_dynevent_type _type_, const char pass:[*]_system_, const char pass:[*]_event_);
 struct tracefs_dynevent pass:[*]pass:[*]*tracefs_dynevent_get_all*(unsigned int _types_, const char pass:[*]_system_);
 enum tracefs_dynevent_type *tracefs_dynevent_info*(struct tracefs_dynevent pass:[*]_dynevent_, char pass:[*]pass:[*]_system_, char pass:[*]pass:[*]_event_, char pass:[*]pass:[*]_prefix_, char pass:[*]pass:[*]_addr_, char pass:[*]pass:[*]_format_);
 --
@@ -39,6 +40,12 @@ types *tracefs_dynevent_type*, that will be removed. If _types_ is 0, dynamic ev
 will be removed.  If _force_ is true, the function will attempt to disable all events in all trace
 instances, before removing the dynamic events.
 
+The *tracefs_dynevent_get*() function allocates and returns a single instance of a dynamic
+event that matches the given *type*, *system* and *event* that is passed to it. NULL is returned
+if there is no match. The returned event is what is found in the system, and must be freed
+with *tracefs_dynevent_free*(). If *system* is NULL, then the first *event* of any system
+of the given type that has the name of *event* will be returned.
+
 The *tracefs_dynevent_get_all*() function allocates and returns an array of pointers to dynamic
 events of given types that exist in the system. The last element of the array is a NULL pointer.
 The array must be freed with *tracefs_dynevent_list_free*(). If there are no events a NULL pointer is
@@ -70,6 +77,9 @@ RETURN VALUE
 *tracefs_dynevent_destroy*() and *tracefs_dynevent_destroy_all*() return 0 on success, or -1 on
 error. If _force_ is enabled, the functions may fail on disabling the events.
 
+*tracefs_dynevent_get*() function returns an allocated dynamic event from the system that matches
+the type, system and event given.
+
 *tracefs_dynevent_get_all*() function returns allocated array of pointers to dynamic events, or NULL
 in case of an error or in case there are no events in the system. That array must be freed by
 *tracefs_dynevent_list_free*().
diff --git a/include/tracefs.h b/include/tracefs.h
index 81efe87..2ced45c 100644
--- a/include/tracefs.h
+++ b/include/tracefs.h
@@ -257,6 +257,8 @@ void tracefs_dynevent_free(struct tracefs_dynevent *devent);
 void tracefs_dynevent_list_free(struct tracefs_dynevent **events);
 struct tracefs_dynevent **
 tracefs_dynevent_get_all(unsigned int types, const char *system);
+struct tracefs_dynevent *
+tracefs_dynevent_get(enum tracefs_dynevent_type type, const char *system, const char *event);
 enum tracefs_dynevent_type
 tracefs_dynevent_info(struct tracefs_dynevent *dynevent, char **system,
 		      char **event, char **prefix, char **addr, char **format);
diff --git a/src/tracefs-dynevents.c b/src/tracefs-dynevents.c
index 0f7cccd..ea07d13 100644
--- a/src/tracefs-dynevents.c
+++ b/src/tracefs-dynevents.c
@@ -596,6 +596,51 @@ error:
 	return NULL;
 }
 
+/**
+ * tracefs_dynevent_get - return a single dynamic event if it exists
+ * @type; Dynamic event type
+ * @system: Get events from that system only. May be NULL.
+ * @event: Get event of the system type (may not be NULL)
+ *
+ * Returns the dynamic event of the given @type and @system for with the @event
+ * name. If @system is NULL, it will return the first dynamic event that it finds
+ * that matches the @event name.
+ *
+ * The returned event must be freed with tracefs_dynevent_free().
+ * NULL is returned if no event match is found, or other error.
+ */
+struct tracefs_dynevent *
+tracefs_dynevent_get(enum tracefs_dynevent_type type, const char *system,
+		     const char *event)
+{
+	struct tracefs_dynevent **events;
+	struct tracefs_dynevent *devent = NULL;
+	int count;
+	int i;
+
+	if (!event) {
+		errno = -EINVAL;
+		return NULL;
+	}
+
+	count = get_all_dynevents(type, system, &events);
+	if (count <= 0)
+		return NULL;
+
+	for (i = 0; i < count; i++) {
+		if (strcmp(events[i]->event, event) == 0)
+			break;
+	}
+	if (i < count) {
+		devent = events[i];
+		events[i] = NULL;
+	}
+
+	tracefs_dynevent_list_free(events);
+
+	return devent;
+}
+
 /**
  * tracefs_dynevent_destroy_all - removes all dynamic events of given types from the system
  * @types: Dynamic event type, or bitmask of dynamic event types. If 0 is passed, all types
-- 
2.31.1


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

* [PATCH 07/11] libtracefs/Documentation: Fix example in libtracefs-error.txt
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
                   ` (5 preceding siblings ...)
  2021-11-22 23:49 ` [PATCH 06/11] libtracefs: Add new API tracefs_dynevent_get() Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 08/11] libtracefs/Documentation: Fix function-filter call to tracefs_list_free() Steven Rostedt
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The example code in libtracefs-error.txt man page referenced the old
tracefs_kprobe_clear_probe() API that no longer exists. Update it to use
the new tracefs_dynevent_get() and the tracefs_dynevent_destroy() API to
do the same thing.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-error.txt | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Documentation/libtracefs-error.txt b/Documentation/libtracefs-error.txt
index 33af074..8dd5b42 100644
--- a/Documentation/libtracefs-error.txt
+++ b/Documentation/libtracefs-error.txt
@@ -52,6 +52,7 @@ EXAMPLE
 
 int main (int argc, char **argv, char **env)
 {
+	struct tracefs_dynevent *kevent;
 	char *system = NULL;
 	char *kprobe;
 	char *format;
@@ -72,7 +73,11 @@ int main (int argc, char **argv, char **env)
 	format = argv[arg++];
 
 	tracefs_error_clear(NULL);
-	tracefs_kprobe_clear_probe(system, kprobe, true);
+	kevent = tracefs_dynevent_get(TRACEFS_DYNEVENT_KPROBE, system, kprobe);
+	if (kevent) {
+		tracefs_dynevent_destroy(kevent, true);
+		tracefs_dynevent_free(kevent);
+	}
 
 	ret = tracefs_kprobe_raw(system, kprobe, addr, format);
 	if (ret < 0) {
-- 
2.31.1


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

* [PATCH 08/11] libtracefs/Documentation: Fix function-filter call to tracefs_list_free()
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
                   ` (6 preceding siblings ...)
  2021-11-22 23:49 ` [PATCH 07/11] libtracefs/Documentation: Fix example in libtracefs-error.txt Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 09/11] libtracefs/Documentation: Update libtracefs-hist-cont.txt to new API Steven Rostedt
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The function-filter man page example used tracefs_free_list() instead of
tracefs_list_free()

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-function-filter.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Documentation/libtracefs-function-filter.txt b/Documentation/libtracefs-function-filter.txt
index ac43d9b..23ba2b8 100644
--- a/Documentation/libtracefs-function-filter.txt
+++ b/Documentation/libtracefs-function-filter.txt
@@ -152,7 +152,7 @@ int main(int argc, char *argv[])
 	printf("Ignoring the following functions:\n");
 	for (i = 0; func_list[i]; i++)
 		printf("  %s\n", func_list[i]);
-	tracefs_free_list(func_list);
+	tracefs_list_free(func_list);
 
 	/* Do not trace any function with the word "lock" in it */
 	ret = tracefs_function_notrace(inst, "*lock*", NULL, TRACEFS_FL_RESET);
-- 
2.31.1


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

* [PATCH 09/11] libtracefs/Documentation: Update libtracefs-hist-cont.txt to new API
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
                   ` (7 preceding siblings ...)
  2021-11-22 23:49 ` [PATCH 08/11] libtracefs/Documentation: Fix function-filter call to tracefs_list_free() Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 10/11] libtracefs: Add all working man page examples to samples Steven Rostedt
  2021-11-22 23:49 ` [PATCH 11/11] libtracefs/Documentation: Update stream example to have a parameter Steven Rostedt
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

The histogram API has changed. Update the man page example to reflect
that.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-hist-cont.txt | 27 +++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)

diff --git a/Documentation/libtracefs-hist-cont.txt b/Documentation/libtracefs-hist-cont.txt
index 778b8ee..5cdcc0a 100644
--- a/Documentation/libtracefs-hist-cont.txt
+++ b/Documentation/libtracefs-hist-cont.txt
@@ -66,6 +66,7 @@ int main (int argc, char **argv, char **env)
 {
 	struct tracefs_instance *instance;
 	struct tracefs_hist *hist;
+	struct tep_handle *tep;
 	enum commands cmd;
 	char *cmd_str;
 	int ret;
@@ -94,22 +95,29 @@ int main (int argc, char **argv, char **env)
 		exit(-1);
 	}
 
+	tep = tracefs_local_events(NULL);
+	if (!tep) {
+		perror("Reading tracefs");
+		exit(-1);
+	}
+
 	instance = tracefs_instance_create("hist_test");
 	if (!instance) {
 		fprintf(stderr, "Failed instance create\n");
 		exit(-1);
 	}
 
-	hist = tracefs_hist_alloc(instance, "kmem", "kmalloc",
-				  "call_site", TRACEFS_HIST_KEY_SYM,
-				  "bytes_req", 0);
+	hist = tracefs_hist2d_alloc(tep, "kmem", "kmalloc",
+				    "call_site",TRACEFS_HIST_KEY_SYM,
+				    "bytes_req", 0);
 	if (!hist) {
 		fprintf(stderr, "Failed hist create\n");
 		exit(-1);
 	}
 
 	ret = tracefs_hist_add_value(hist, "bytes_alloc");
-	ret |= tracefs_hist_add_sort_key(hist, "bytes_req", "bytes_alloc", NULL);
+	ret |= tracefs_hist_add_sort_key(hist, "bytes_req");
+	ret |= tracefs_hist_add_sort_key(hist, "bytes_alloc");
 
 	ret |= tracefs_hist_sort_key_direction(hist, "bytes_alloc",
 					       TRACEFS_HIST_SORT_DESCENDING);
@@ -122,7 +130,7 @@ int main (int argc, char **argv, char **env)
 
 	switch (cmd) {
 	case START:
-		ret = tracefs_hist_start(hist);
+		ret = tracefs_hist_start(instance, hist);
 		if (ret) {
 			char *err = tracefs_error_last(instance);
 			if (err)
@@ -130,16 +138,16 @@ int main (int argc, char **argv, char **env)
 		}
 		break;
 	case PAUSE:
-		ret = tracefs_hist_pause(hist);
+		ret = tracefs_hist_pause(instance, hist);
 		break;
 	case CONT:
-		ret = tracefs_hist_continue(hist);
+		ret = tracefs_hist_continue(instance, hist);
 		break;
 	case RESET:
-		ret = tracefs_hist_reset(hist);
+		ret = tracefs_hist_reset(instance, hist);
 		break;
 	case DELETE:
-		ret = tracefs_hist_destroy(hist);
+		ret = tracefs_hist_destroy(instance, hist);
 		break;
 	case SHOW: {
 		char *content;
@@ -157,6 +165,7 @@ int main (int argc, char **argv, char **env)
 		fprintf(stderr, "Failed: command\n");
 	exit(ret);
 }
+
 --
 
 FILES
-- 
2.31.1


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

* [PATCH 10/11] libtracefs: Add all working man page examples to samples
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
                   ` (8 preceding siblings ...)
  2021-11-22 23:49 ` [PATCH 09/11] libtracefs/Documentation: Update libtracefs-hist-cont.txt to new API Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  2021-11-22 23:49 ` [PATCH 11/11] libtracefs/Documentation: Update stream example to have a parameter Steven Rostedt
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Parse out all the working examples in the man pages, and have

  make samples

build them.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 samples/Makefile | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)

diff --git a/samples/Makefile b/samples/Makefile
index 53b6630..6ee57fe 100644
--- a/samples/Makefile
+++ b/samples/Makefile
@@ -7,9 +7,22 @@
 
 include $(src)/scripts/utils.mk
 
+EXAMPLES :=
+EXAMPLES += dynevents
+EXAMPLES += kprobes
+EXAMPLES += eprobes
+EXAMPLES += synth
+EXAMPLES += error
+EXAMPLES += filter
+EXAMPLES += function-filter
+EXAMPLES += hist
+EXAMPLES += hist-cont
+EXAMPLES += tracer
+EXAMPLES += stream
+
 TARGETS :=
 TARGETS += sqlhist
-TARGETS += dynevent
+TARGETS += $(EXAMPLES)
 
 bdir := $(obj)/bin
 
@@ -21,7 +34,9 @@ extract_example = \
 $(bdir)/sqlhist.c: ../Documentation/libtracefs-sql.txt
 	$(call extract_example,$<,$@)
 
-$(bdir)/dynevent.c: ../Documentation/libtracefs-dynevents.txt
+EXAMPLE_C_CODE := $(patsubst %,$(bdir)/%.c,$(EXAMPLES))
+
+$(bdir)/%.c: ../Documentation/libtracefs-%.txt
 	$(call extract_example,$<,$@)
 
 $(bdir):
@@ -31,10 +46,21 @@ sqlhist: $(bdir) $(bdir) $(bdir)/sqlhist
 
 $(TARGETS): $(bdir)
 
+# sqlhist is unique and stands on its own
+sqlhist: $(bdir)/sqlhist
+
 $(bdir)/%: $(bdir)/%.o
 	$(CC) -o $@ $^ $(LIBTRACEFS_STATIC) $(LIBTRACEEVENT_LIBS)
 
-$(TARGETS): $(patsubst %,$(bdir)/%,$(TARGETS))
+$(EXAMPLES): $(patsubst %,$(bdir)/%,$(TARGETS))
+
+## The intermediate files get removed by Make.
+## To examine the .c files created by one of the man pages,
+## uncomment the below, and replace the XX with the exec example
+## name, and the file will not be discarded by make.
+#
+# $(bdir)/XX.o: $(bdir)/XX.c
+#	$(CC) -g -Wall -c -o $@ $^ -I../include/ $(LIBTRACEEVENT_INCLUDES)
 
 $(bdir)/%.o: %.c
 	$(CC) -g -Wall -c -o $@ $^ -I../include/ $(LIBTRACEEVENT_INCLUDES)
-- 
2.31.1


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

* [PATCH 11/11] libtracefs/Documentation: Update stream example to have a parameter
  2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
                   ` (9 preceding siblings ...)
  2021-11-22 23:49 ` [PATCH 10/11] libtracefs: Add all working man page examples to samples Steven Rostedt
@ 2021-11-22 23:49 ` Steven Rostedt
  10 siblings, 0 replies; 12+ messages in thread
From: Steven Rostedt @ 2021-11-22 23:49 UTC (permalink / raw)
  To: linux-trace-devel; +Cc: Steven Rostedt (VMware)

From: "Steven Rostedt (VMware)" <rostedt@goodmis.org>

Instead of writing the output of the tracing data to trace.txt, have the
example require a file name. As it is now compiled out, it should not
create some random file that the user will not expect.

Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
---
 Documentation/libtracefs-stream.txt | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/Documentation/libtracefs-stream.txt b/Documentation/libtracefs-stream.txt
index 48fc8fa..7d723c5 100644
--- a/Documentation/libtracefs-stream.txt
+++ b/Documentation/libtracefs-stream.txt
@@ -47,6 +47,8 @@ EXAMPLE
 -------
 [source,c]
 --
+#include <stdio.h>
+#include <stdlib.h>
 #include <unistd.h>
 #include <signal.h>
 
@@ -57,13 +59,23 @@ void stop(int sig)
 	tracefs_trace_pipe_stop(NULL);
 }
 
-int main()
+int main(int argc, char **argv)
 {
 	mode_t mode = S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH;
-	const char *filename = "trace.txt";
-	int fd = creat(filename, mode);
+	const char *filename;
+	int fd;
 	int ret;
 
+	if (argc < 2) {
+		fprintf(stderr, "usage: %s output_file\n", argv[0]);
+		exit(-1);
+	}
+	filename = argv[1];
+	fd = creat(filename, mode);
+	if (fd < 0) {
+		perror(filename);
+		exit(-1);
+	}
 	signal(SIGINT, stop);
 	ret = tracefs_trace_pipe_stream(fd, NULL, SPLICE_F_NONBLOCK);
 	close(fd);
-- 
2.31.1


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

end of thread, other threads:[~2021-11-22 23:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-11-22 23:49 [PATCH 00/11] libtracefs: Have all man page examples be executable Steven Rostedt
2021-11-22 23:49 ` [PATCH 01/11] libtracefs: Move creation of sqlhist into new samples directory Steven Rostedt
2021-11-22 23:49 ` [PATCH 02/11] libtracefs: Fix example in the dynamic events man page to compile Steven Rostedt
2021-11-22 23:49 ` [PATCH 03/11] libtracefs/Documentation: Fix man page examples to include the proper header Steven Rostedt
2021-11-22 23:49 ` [PATCH 04/11] tracefs/Documentation: Fix example in libtracefs-eprobes.txt to compile Steven Rostedt
2021-11-22 23:49 ` [PATCH 05/11] libtracefs: Make samples easily extract man page example programs Steven Rostedt
2021-11-22 23:49 ` [PATCH 06/11] libtracefs: Add new API tracefs_dynevent_get() Steven Rostedt
2021-11-22 23:49 ` [PATCH 07/11] libtracefs/Documentation: Fix example in libtracefs-error.txt Steven Rostedt
2021-11-22 23:49 ` [PATCH 08/11] libtracefs/Documentation: Fix function-filter call to tracefs_list_free() Steven Rostedt
2021-11-22 23:49 ` [PATCH 09/11] libtracefs/Documentation: Update libtracefs-hist-cont.txt to new API Steven Rostedt
2021-11-22 23:49 ` [PATCH 10/11] libtracefs: Add all working man page examples to samples Steven Rostedt
2021-11-22 23:49 ` [PATCH 11/11] libtracefs/Documentation: Update stream example to have a parameter 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.