diff mbox series

[3/7] trace-cmd check-events: Add --verbose

Message ID 20210428074630.757694-4-tz.stoyanov@gmail.com (mailing list archive)
State Accepted
Headers show
Series Add --verbose option to bunch of trace-cmd commands | expand

Commit Message

Tzvetomir Stoyanov (VMware) April 28, 2021, 7:46 a.m. UTC
Add new "trace-cmd check-events --verbose" argument for setting the desired
log level.

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 .../trace-cmd/trace-cmd-check-events.1.txt       |  9 +++++++++
 tracecmd/trace-check-events.c                    | 16 +++++++++++++++-
 tracecmd/trace-usage.c                           |  1 +
 3 files changed, 25 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/Documentation/trace-cmd/trace-cmd-check-events.1.txt b/Documentation/trace-cmd/trace-cmd-check-events.1.txt
index c98ff3c6..40c3c8cd 100644
--- a/Documentation/trace-cmd/trace-cmd-check-events.1.txt
+++ b/Documentation/trace-cmd/trace-cmd-check-events.1.txt
@@ -24,6 +24,15 @@  OPTIONS
 -------
 *-N* - Don't load plugins
 
+*--verbose* 'level'::
+     Set the log level. Supported log levels are "none", "critical", "error", "warning",
+     "info", "debug", "all" or their identifiers "0", "1", "2", "3", "4", "5", "6". Setting the log
+     level to specific value enables all logs from that and all previous levels.
+
+     Example: enable all critical, error and warning logs
+
+      trace-cmd check-events --verbose warning
+
 SEE ALSO
 --------
 trace-cmd(1), trace-cmd-record(1), trace-cmd-report(1), trace-cmd-stop(1),
diff --git a/tracecmd/trace-check-events.c b/tracecmd/trace-check-events.c
index bd19feca..cf34912a 100644
--- a/tracecmd/trace-check-events.c
+++ b/tracecmd/trace-check-events.c
@@ -10,6 +10,10 @@ 
 #include "tracefs.h"
 #include "trace-local.h"
 
+enum {
+	OPT_verbose	= 255,
+};
+
 void trace_check_events(int argc, char **argv)
 {
 	const char *tracing;
@@ -18,8 +22,14 @@  void trace_check_events(int argc, char **argv)
 	struct tep_handle *pevent = NULL;
 	struct tep_plugin_list *list = NULL;
 	int open_flags = 0;
+	int option_index = 0;
+	static struct option long_options[] = {
+		{"verbose", required_argument, NULL, OPT_verbose},
+		{NULL, 0, NULL, 0}
+	};
+
 
-	while ((c = getopt(argc-1, argv+1, "+hN")) >= 0) {
+	while ((c = getopt_long(argc-1, argv+1, "+hN", long_options, &option_index)) >= 0) {
 		switch (c) {
 		case 'h':
 		default:
@@ -28,6 +38,10 @@  void trace_check_events(int argc, char **argv)
 		case 'N':
 			open_flags |= TRACECMD_FL_LOAD_NO_PLUGINS;
 			break;
+		case OPT_verbose:
+			if (trace_set_verbose(optarg) < 0)
+				die("invalid verbose level %s", optarg);
+			break;
 		}
 	}
 	tracing = tracefs_tracing_dir();
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index 7019ab97..cacec3c5 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -363,6 +363,7 @@  static struct usage_help usage_help[] = {
 		"parse trace event formats",
 		" %s check-events [-N]\n"
 		"          -N do not load any plugins\n"
+		"          --verbose 'level' Set the desired log level\n"
 	},
 	{
 		"dump",