Skip to contentSkip to conversation

libtracefs: Have all man page examples be executable

PATCH New Steven Rostedt 1 participant 12 messages Nov 22, 2021

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover libtracefs: Have all man page examples be executable

From: "Steven Rostedt (VMware)" <[email protected]>

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
Signature · 1 line
2.31.1
#1 lore raw

PATCH 1/11 libtracefs: Move creation of sqlhist into new samples directory

From: "Steven Rostedt (VMware)" <[email protected]>

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.

---
 Makefile         | 13 +++++--------
 samples/Makefile | 27 +++++++++++++++++++++++++++
 2 files changed, 32 insertions(+), 8 deletions(-)
 create mode 100644 samples/Makefile
Makefile +5 -8
index 7f382c3..7c96674 100644
@@ -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
samples/Makefile new file +27 -0
new file mode 100644
index 0000000..aae3e27
@@ -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)/*
Signature · 1 line
2.31.1
#2 lore raw

PATCH 2/11 libtracefs: Fix example in the dynamic events man page to compile

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

---
 Documentation/libtracefs-dynevents.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/libtracefs-dynevents.txt +1 -1
index 25172c3..503bd7e 100644
@@ -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);
Signature · 1 line
2.31.1
#3 lore raw

PATCH 3/11 libtracefs/Documentation: Fix man page examples to include the proper header

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

---
 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(-)
Documentation/libtracefs-dynevents.txt +1 -1
index 503bd7e..89b2e92 100644
@@ -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;
Documentation/libtracefs-eprobes.txt +1 -1
index 3baaea3..65e5b13 100644
@@ -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;
Documentation/libtracefs-error.txt +1 -1
index 3f6a154..33af074 100644
@@ -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)
 {
Documentation/libtracefs-hist-cont.txt +1 -1
index 2ee830d..778b8ee 100644
@@ -51,7 +51,7 @@ EXAMPLE
 [source,c]
 --
 #include <stdlib.h>
-#include <tracefs/tracefs.h>
+#include <tracefs.h>
 
 enum commands {
 	START,
Documentation/libtracefs-hist.txt +1 -1
index cc6b859..c07fe6f 100644
@@ -222,7 +222,7 @@ EXAMPLE
 [source,c]
 --
 #include <stdlib.h>
-#include <tracefs/tracefs.h>
+#include <tracefs.h>
 
 enum commands {
 	START,
Documentation/libtracefs-kprobes.txt +1 -1
index 4a4bf01..e488f9a 100644
@@ -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;
Signature · 1 line
2.31.1
#4 lore raw

PATCH 4/11 tracefs/Documentation: Fix example in libtracefs-eprobes.txt to compile

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

---
 Documentation/libtracefs-eprobes.txt | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)
Documentation/libtracefs-eprobes.txt +1 -3
index 65e5b13..4155544 100644
@@ -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) {
Signature · 1 line
2.31.1
#5 lore raw

PATCH 5/11 libtracefs: Make samples easily extract man page example programs

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

---
 Makefile         |  3 +++
 samples/Makefile | 26 +++++++++++++++++++++-----
 2 files changed, 24 insertions(+), 5 deletions(-)
Makefile +3 -0
index 7c96674..85b3c39 100644
@@ -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
samples/Makefile +21 -5
index aae3e27..53b6630 100644
@@ -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:
Signature · 1 line
2.31.1
#6 lore raw

PATCH 6/11 libtracefs: Add new API tracefs_dynevent_get()

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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

---
 Documentation/libtracefs-dynevents.txt | 10 ++++++
 include/tracefs.h                      |  2 ++
 src/tracefs-dynevents.c                | 45 ++++++++++++++++++++++++++
 3 files changed, 57 insertions(+)
Documentation/libtracefs-dynevents.txt +10 -0
index 89b2e92..a374651 100644
@@ -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*().
include/tracefs.h +2 -0
index 81efe87..2ced45c 100644
@@ -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);
src/tracefs-dynevents.c +45 -0

51 lines not on this page · raw message

Signature · 1 line
2.31.1
#7 lore raw

PATCH 7/11 libtracefs/Documentation: Fix example in libtracefs-error.txt

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

---
 Documentation/libtracefs-error.txt | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
Documentation/libtracefs-error.txt +6 -1
index 33af074..8dd5b42 100644
@@ -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) {
Signature · 1 line
2.31.1
#8 lore raw

PATCH 8/11 libtracefs/Documentation: Fix function-filter call to tracefs_list_free()

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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

---
 Documentation/libtracefs-function-filter.txt | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Documentation/libtracefs-function-filter.txt +1 -1
index ac43d9b..23ba2b8 100644
@@ -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);
Signature · 1 line
2.31.1
#9 lore raw

PATCH 9/11 libtracefs/Documentation: Update libtracefs-hist-cont.txt to new API

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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

---
 Documentation/libtracefs-hist-cont.txt | 27 +++++++++++++++++---------
 1 file changed, 18 insertions(+), 9 deletions(-)
Documentation/libtracefs-hist-cont.txt +18 -9
index 778b8ee..5cdcc0a 100644
@@ -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
Signature · 1 line
2.31.1
#10 lore raw

PATCH 10/11 libtracefs: Add all working man page examples to samples

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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

make samples

build them.

---
 samples/Makefile | 32 +++++++++++++++++++++++++++++---
 1 file changed, 29 insertions(+), 3 deletions(-)
samples/Makefile +29 -3
index 53b6630..6ee57fe 100644
@@ -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)
Signature · 1 line
2.31.1
#11 lore raw

PATCH 11/11 libtracefs/Documentation: Update stream example to have a parameter

In reply to Steven Rostedt

From: "Steven Rostedt (VMware)" <[email protected]>

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.

---
 Documentation/libtracefs-stream.txt | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
Documentation/libtracefs-stream.txt +15 -3
index 48fc8fa..7d723c5 100644
@@ -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);
Signature · 1 line
2.31.1