diff mbox series

[v2] trace-cmd: Exit the application if runs in "filter test" mode

Message ID 20190417162943.32601-1-tstoyanov@vmware.com (mailing list archive)
State Accepted
Commit 2e7c800f400a0ddeb4aaab57144d7a249c6ea458
Delegated to: Steven Rostedt
Headers show
Series [v2] trace-cmd: Exit the application if runs in "filter test" mode | expand

Commit Message

Tzvetomir Stoyanov April 17, 2019, 4:29 p.m. UTC
Users can use trace-cmd to test specific filters, with the command
  trace-cmd record -F <filter> -T
When trace-cmd runs in this "test filter" mode, after processing the filter
string, the resulting filter will be displayed for each event. It should not run
the actual trace, but exit after all filters are processed. This exit() was
originally performed in the context of libtraceevent, but removed from there as
a library function should not force the application to exit. The logic was
moved to trace-cmd application.

Signed-off-by: Tzvetomir Stoyanov <tstoyanov@vmware.com>
---
 tracecmd/trace-read.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/tracecmd/trace-read.c b/tracecmd/trace-read.c
index a7ffcc5..dbfb3a5 100644
--- a/tracecmd/trace-read.c
+++ b/tracecmd/trace-read.c
@@ -83,6 +83,7 @@  static int instances;
 
 static int *filter_cpus;
 static int nr_filter_cpus;
+static int test_filters_mode;
 
 static int show_wakeup;
 static int wakeup_id;
@@ -489,6 +490,7 @@  static void process_filters(struct handle_list *handles)
 	struct filter_str *filter;
 	struct tep_handle *pevent;
 	char errstr[200];
+	int filters = 0;
 	int ret;
 
 	pevent = tracecmd_get_pevent(handles->handle);
@@ -522,10 +524,12 @@  static void process_filters(struct handle_list *handles)
 			*filter_next = event_filter;
 			filter_next = &event_filter->next;
 		}
-
+		filters++;
 		free(filter->filter);
 		free(filter);
 	}
+	if (filters && test_filters_mode)
+		exit(0);
 }
 
 static void init_wakeup(struct tracecmd_input *handle)
@@ -1426,7 +1430,6 @@  void trace_report (int argc, char **argv)
 	int latency_format = 0;
 	int show_events = 0;
 	int print_events = 0;
-	int test_filters = 0;
 	int nanosec = 0;
 	int no_date = 0;
 	int global = 0;
@@ -1500,7 +1503,7 @@  void trace_report (int argc, char **argv)
 			add_hook(optarg);
 			break;
 		case 'T':
-			test_filters = 1;
+			test_filters_mode = 1;
 			break;
 		case 'f':
 			show_funcs = 1;
@@ -1692,7 +1695,7 @@  void trace_report (int argc, char **argv)
 		if (raw)
 			tep_set_print_raw(pevent, 1);
 
-		if (test_filters)
+		if (test_filters_mode)
 			tep_set_test_filters(pevent, 1);
 
 		if (functions)