Skip to contentSkip to conversation

trace-cmd: Update verbose logic

PATCH New Steven Rostedt 1 participant 4 messages Jun 25, 2021 Documentation

lore
Share & tools
lore
#0 lore raw

cover trace-cmd: Update verbose logic

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

- Have verbose not require an argument

- Make -V similar to --verbose (but only for numbers)

- Do not force a limit to the verbosity numbers

Steven Rostedt (VMware) (3):
trace-cmd: Do not require --verbose to have an argument trace-cmd report: Have -V take an optional argument
trace-cmd: Do not enforce upper limit of verbose id

 .../trace-cmd/trace-cmd-check-events.1.txt         |  5 +++--
 Documentation/trace-cmd/trace-cmd-dump.1.txt       |  5 +++--
 Documentation/trace-cmd/trace-cmd-extract.1.txt    |  5 +++--
 Documentation/trace-cmd/trace-cmd-listen.1.txt     |  5 +++--
 Documentation/trace-cmd/trace-cmd-profile.1.txt    |  5 +++--
 Documentation/trace-cmd/trace-cmd-record.1.txt     |  5 +++--
 Documentation/trace-cmd/trace-cmd-report.1.txt     |  9 +++++----
 Documentation/trace-cmd/trace-cmd-set.1.txt        |  5 +++--
 Documentation/trace-cmd/trace-cmd-stack.1.txt      |  5 +++--
 tracecmd/trace-agent.c                             |  2 +-
 tracecmd/trace-check-events.c                      |  2 +-
 tracecmd/trace-cmd.c                               |  7 +++++--
 tracecmd/trace-dump.c                              |  2 +-
 tracecmd/trace-listen.c                            |  2 +-
 tracecmd/trace-read.c                              | 10 ++++------
 tracecmd/trace-record.c                            |  2 +-
 tracecmd/trace-stack.c                             |  2 +-
 tracecmd/trace-usage.c                             | 14 +++++++++++---
 18 files changed, 55 insertions(+), 37 deletions(-)
Signature · 1 line
2.30.2
#1 lore raw

PATCH 1/3 trace-cmd: Do not require --verbose to have an argument

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

In most applications, when specifying a "verbose" argument, they do not require adding a level of verbosity. Just saying "--verbose" should be sufficient, unless they want a specific type of verbosity.

Have --verbose be acceptable as an argument without specifying a level. Unfortunately, it appears that getopt_long() does not recognize the next argument on the command line as an optional argument, but requires an equal sign between the "--verbose" and the level. That is, when the user wants to specify a specific level, they need to do it like so:

  trace-cmd report --verbose=debug

And not like

  trace-cmd report --verbose debug

The man pages are updated to reflect this.

---
 Documentation/trace-cmd/trace-cmd-check-events.1.txt | 5 +++--
 Documentation/trace-cmd/trace-cmd-dump.1.txt         | 5 +++--
 Documentation/trace-cmd/trace-cmd-extract.1.txt      | 5 +++--
 Documentation/trace-cmd/trace-cmd-listen.1.txt       | 5 +++--
 Documentation/trace-cmd/trace-cmd-profile.1.txt      | 5 +++--
 Documentation/trace-cmd/trace-cmd-record.1.txt       | 5 +++--
 Documentation/trace-cmd/trace-cmd-report.1.txt       | 5 +++--
 Documentation/trace-cmd/trace-cmd-set.1.txt          | 5 +++--
 Documentation/trace-cmd/trace-cmd-stack.1.txt        | 5 +++--
 tracecmd/trace-agent.c                               | 2 +-
 tracecmd/trace-check-events.c                        | 2 +-
 tracecmd/trace-cmd.c                                 | 3 ++-
 tracecmd/trace-dump.c                                | 2 +-
 tracecmd/trace-listen.c                              | 2 +-
 tracecmd/trace-read.c                                | 2 +-
 tracecmd/trace-record.c                              | 2 +-
 tracecmd/trace-stack.c                               | 2 +-
 17 files changed, 36 insertions(+), 26 deletions(-)
Documentation/trace-cmd/trace-cmd-check-events.1.txt +3 -2
index 40c3c8cd..debab6c5 100644
@@ -24,14 +24,15 @@ OPTIONS
 -------
 *-N* - Don't load plugins
 
-*--verbose* 'level'::
+*--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.
+     The level will default to "info" if one is not specified.
 
      Example: enable all critical, error and warning logs
 
-      trace-cmd check-events --verbose warning
+      trace-cmd check-events --verbose=warning
 
 SEE ALSO
 --------
Documentation/trace-cmd/trace-cmd-dump.1.txt +3 -2
index b1a3f90d..9c95244b 100644
@@ -52,14 +52,15 @@ OPTIONS
     Print all meta data from the file.
 *--help*::
     Print usage information.
-*--verbose* 'level'::
+*--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.
+     The level will default to "info" if one is not specified.
 
      Example: enable all critical, error and warning logs
 
-      trace-cmd report --verbose warning
+      trace-cmd report --verbose=warning
 
 EXAMPLES
 --------
Documentation/trace-cmd/trace-cmd-extract.1.txt +3 -2
index 88749da7..776da6e1 100644
@@ -67,14 +67,15 @@ OPTIONS
     this is the same as the default. But if *-B* or *-a* is used, this is
     required if the top level instance buffer should also be extracted.
 
-*--verbose* 'level'::
+*--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.
+     The level will default to "info" if one is not specified.
 
      Example: enable all critical, error and warning logs
 
-      trace-cmd extract --verbose warning
+      trace-cmd extract --verbose=warning
 
 SEE ALSO
 --------
Documentation/trace-cmd/trace-cmd-listen.1.txt +3 -2
index da841867..aa6a307f 100644
@@ -36,14 +36,15 @@ OPTIONS
 *-l* 'filename'::
     This option writes the output messages to a log file instead of standard output.
 
-*--verbose* 'level'::
+*--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.
+     The level will default to "info" if one is not specified.
 
      Example: enable all critical, error and warning logs
 
-      trace-cmd listen --verbose warning
+      trace-cmd listen --verbose=warning
 
 SEE ALSO
 --------
Documentation/trace-cmd/trace-cmd-profile.1.txt +3 -2
index 0d285ff7..078ae9e0 100644
@@ -90,14 +90,15 @@ These are the same as trace-cmd-record(1) with the *--profile* option.
     is not changed. This allows watching the command execute and saving the
     output of the profile to another file.
 
-*--verbose* 'level'::
+*--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.
+     The level will default to "info" if one is not specified.
 
      Example: enable all critical, error and warning logs
 
-      trace-cmd profile --verbose warning
+      trace-cmd profile --verbose=warning
 
 EXAMPLES
 --------
Documentation/trace-cmd/trace-cmd-record.1.txt +3 -2
index d8065641..96c27108 100644
@@ -367,14 +367,15 @@ OPTIONS
     Traces are extracted by busy waiting, which will hog the CPUs, so only use
     when really needed.
 
-*--verbose* 'level'::
+*--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.
+     The level will default to "info" if one is not specified.
 
      Example: enable all critical, error and warning logs
 
-      trace-cmd record --verbose warning
+      trace-cmd record --verbose=warning
 
 EXAMPLES
 --------
Documentation/trace-cmd/trace-cmd-report.1.txt +3 -2
index 3b801a1c..a6c863a8 100644
@@ -315,14 +315,15 @@ OPTIONS
 *--align-ts*::
      Display timestamps aligned to the first event.
 
-*--verbose* 'level'::
+*--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.
+     The level will default to "info" if one is not specified.
 
      Example: enable all critical, error and warning logs
 
-      trace-cmd report --verbose warning
+      trace-cmd report --verbose=warning
 
 EXAMPLES
 --------
Documentation/trace-cmd/trace-cmd-set.1.txt +3 -2
index 50af7677..a182d191 100644
@@ -227,14 +227,15 @@ OPTIONS
     unless the *--fork* option is specified. Then it will fork the command and
     return immediately.
 
-*--verbose* 'level'::
+*--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.
+     The level will default to "info" if one is not specified.
 
      Example: enable all critical, error and warning logs
 
-      trace-cmd set --verbose warning
+      trace-cmd set --verbose=warning
 
 EXAMPLES
 --------
Documentation/trace-cmd/trace-cmd-stack.1.txt +3 -2
index 75bd50ba..20752407 100644
@@ -24,9 +24,10 @@ stack found since the start was enabled.
 
 Use *--reset* to reset the stack counter to zero.
 
-User *--verbose* 'level' to set the log level. Supported log levels are "none", "critical", "error",
+User *--verbose*[='level'] to 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.
+the log level to specific value enables all logs from that and all previous levels. The level will
+default to "info" if one is not specified.
 
 SEE ALSO
 --------
tracecmd/trace-agent.c +1 -1
index 0dc339b4..b83d3ac1 100644
@@ -302,7 +302,7 @@ void trace_agent(int argc, char **argv)
 			{"port", required_argument, NULL, 'p'},
 			{"help", no_argument, NULL, '?'},
 			{"debug", no_argument, NULL, DO_DEBUG},
-			{"verbose", required_argument, NULL, OPT_verbose},
+			{"verbose", optional_argument, NULL, OPT_verbose},
 			{NULL, 0, NULL, 0}
 		};
 
tracecmd/trace-check-events.c +1 -1
index cf34912a..46f57e17 100644
@@ -24,7 +24,7 @@ void trace_check_events(int argc, char **argv)
 	int open_flags = 0;
 	int option_index = 0;
 	static struct option long_options[] = {
-		{"verbose", required_argument, NULL, OPT_verbose},
+		{"verbose", optional_argument, NULL, OPT_verbose},
 		{NULL, 0, NULL, 0}
 	};
 
tracecmd/trace-cmd.c +2 -1
index 00cdaa37..7f5d1ffd 100644
@@ -62,8 +62,9 @@ int trace_set_verbose(char *level)
 {
 	int id;
 
+	/* Default level is info */
 	if (!level)
-		return -1;
+		level = "info";
 
 	if (isdigit(level[0])) {
 		id = atoi(level);
tracecmd/trace-dump.c +1 -1
index cf47e7fb..2334b57e 100644
@@ -730,7 +730,7 @@ void trace_dump(int argc, char **argv)
 			{"clock", no_argument, NULL, OPT_clock},
 			{"validate", no_argument, NULL, 'v'},
 			{"help", no_argument, NULL, '?'},
-			{"verbose", required_argument, NULL, OPT_verbose},
+			{"verbose", optional_argument, NULL, OPT_verbose},
 			{NULL, 0, NULL, 0}
 		};
 
tracecmd/trace-listen.c +1 -1
index a72365a2..0cb70b7d 100644
@@ -939,7 +939,7 @@ void trace_listen(int argc, char **argv)
 			{"port", required_argument, NULL, 'p'},
 			{"help", no_argument, NULL, '?'},
 			{"debug", no_argument, NULL, OPT_debug},
-			{"verbose", required_argument, NULL, OPT_verbose},
+			{"verbose", optional_argument, NULL, OPT_verbose},
 			{NULL, 0, NULL, 0}
 		};
 
tracecmd/trace-read.c +1 -1
index d5687f03..8695f0a4 100644
@@ -1603,7 +1603,7 @@ void trace_report (int argc, char **argv)
 			{"ts-check", no_argument, NULL, OPT_tscheck},
 			{"raw-ts", no_argument, NULL, OPT_raw_ts},
 			{"align-ts", no_argument, NULL, OPT_align_ts},
-			{"verbose", required_argument, NULL, OPT_verbose},
+			{"verbose", optional_argument, NULL, OPT_verbose},
 			{"help", no_argument, NULL, '?'},
 			{NULL, 0, NULL, 0}
 		};
tracecmd/trace-record.c +1 -1
index b5f9c5a0..1767a6c6 100644
@@ -6175,7 +6175,7 @@ static void parse_record_options(int argc,
 			{"fork", no_argument, NULL, OPT_fork},
 			{"tsc2nsec", no_argument, NULL, OPT_tsc2nsec},
 			{"poll", no_argument, NULL, OPT_poll},
-			{"verbose", required_argument, NULL, OPT_verbose},
+			{"verbose", optional_argument, NULL, OPT_verbose},
 			{NULL, 0, NULL, 0}
 		};
 
tracecmd/trace-stack.c +1 -1
index 6f57387a..80364949 100644
@@ -164,7 +164,7 @@ void trace_stack (int argc, char **argv)
 			{"stop", no_argument, NULL, OPT_stop},
 			{"reset", no_argument, NULL, OPT_reset},
 			{"help", no_argument, NULL, '?'},
-			{"verbose", required_argument, NULL, OPT_verbose},
+			{"verbose", optional_argument, NULL, OPT_verbose},
 			{NULL, 0, NULL, 0}
 		};
 
Signature · 1 line
2.30.2
#2 lore raw

PATCH 2/3 trace-cmd report: Have -V take an optional argument

In reply to Steven Rostedt

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

By default "-V" will be the same as --verbose=info, but since we allow --verbose to have an option, do the same with -V. -V will only take a integer arguments though.

Also updated the documentation of --verbose to the names that are actually used, and not the extended names ("crit" and not "critical", etc).

---
 Documentation/trace-cmd/trace-cmd-report.1.txt |  4 ++--
 tracecmd/trace-read.c                          |  8 +++-----
 tracecmd/trace-usage.c                         | 14 +++++++++++---
 3 files changed, 16 insertions(+), 10 deletions(-)
Documentation/trace-cmd/trace-cmd-report.1.txt +2 -2
index a6c863a8..501994a4 100644
@@ -164,7 +164,7 @@ OPTIONS
     *-T* is ignored if *-F* is not specified.
 
 *-V*::
-    Show the plugins that are loaded.
+    Show verbose messages (see *--verbose* but only for the numbers)
 
 *-L*::
     This will not load system wide plugins. It loads "local only". That is
@@ -316,7 +316,7 @@ OPTIONS
      Display timestamps aligned to the first event.
 
 *--verbose*[='level']::
-     Set the log level. Supported log levels are "none", "critical", "error", "warning",
+     Set the log level. Supported log levels are "none", "crit", "err", "warn",
      "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.
      The level will default to "info" if one is not specified.
tracecmd/trace-read.c +3 -5
index 8695f0a4..6f43c1d2 100644
@@ -1608,7 +1608,7 @@ void trace_report (int argc, char **argv)
 			{NULL, 0, NULL, 0}
 		};
 
-		c = getopt_long (argc-1, argv+1, "+hSIi:H:feGpRr:tPNn:LlEwF:VvTqO:",
+		c = getopt_long (argc-1, argv+1, "+hSIi:H:feGpRr:tPNn:LlEwF:V::vTqO:",
 			long_options, &option_index);
 		if (c == -1)
 			break;
@@ -1703,10 +1703,6 @@ void trace_report (int argc, char **argv)
 				die("Only 1 -v can be used");
 			neg = 1;
 			break;
-		case 'V':
-			show_status = 1;
-			tracecmd_set_loglevel(TEP_LOG_INFO);
-			break;
 		case 'q':
 			silence_warnings = 1;
 			tracecmd_set_loglevel(TEP_LOG_NONE);
@@ -1784,7 +1780,9 @@ void trace_report (int argc, char **argv)
 		case OPT_align_ts:
 			align_ts = 1;
 			break;
+		case 'V':
 		case OPT_verbose:
+			show_status = 1;
 			if (trace_set_verbose(optarg) < 0)
 				die("invalid verbose level %s", optarg);
 			break;
tracecmd/trace-usage.c +11 -3
index da0266c6..32b38bfd 100644
@@ -196,7 +196,7 @@ static struct usage_help usage_help[] = {
 		"report",
 		"read out the trace stored in a trace.dat file",
 		" %s report [-i file] [--cpu cpu] [-e][-f][-l][-P][-L][-N][-R][-E]\\\n"
-		"           [-r events][-n events][-F filter][-v][-V][-T][-O option]\n"
+		"           [-r events][-n events][-F filter][-v][-V[1-6]][-T][-O option]\n"
 		"           [-H [start_system:]start_event,start_match[,pid]/[end_system:]end_event,end_match[,flags]\n"
 		"           [-G]\n"
 		"          -i input file [default trace.dat]\n"
@@ -212,7 +212,8 @@ static struct usage_help usage_help[] = {
 		"          -r raw format the events that match the option\n"
 		"          -v will negate all -F after it (Not show matches)\n"
 		"          -T print out the filter strings created and exit\n"
-		"          -V verbose (shows plugins being loaded)\n"
+		"          -V[level] verbose (shows plugins being loaded)\n"
+		"              With optional level (see --verbose numbers)\n"
 		"          -L load only local (~/.trace-cmd/plugins) plugins\n"
 		"          -N do not load any plugins\n"
 		"          -n ignore plugin handlers for events that match the option\n"
@@ -240,7 +241,14 @@ static struct usage_help usage_help[] = {
 		"          --ts-check Check to make sure no time stamp on any CPU goes backwards.\n"
 		"          --raw-ts Display raw timestamps, without any corrections.\n"
 		"          --align-ts Display timestamps aligned to the first event.\n"
-		"          --verbose 'level' Set the desired log level\n"
+		"          --verbose[=level] Set the desired log level\n"
+		"                0 or none  - no error messages\n"
+		"                1 or crit  - only critical messages\n"
+		"                2 or err   - 'crit' and error messages\n"
+		"                3 or warn  - 'err' and warning messages\n"
+		"                4 or info  - 'warn' and informational messages\n"
+		"                5 or debug - 'info' and debugging messages\n"
+		"                6 or all   - same as debug\n"
 	},
 	{
 		"stream",
Signature · 1 line
2.30.2
#3 lore raw

PATCH 3/3 trace-cmd: Do not enforce upper limit of verbose id

In reply to Steven Rostedt

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

Applications that have a "verbose" option, do not usually set an upper limit of what can be passed in. If the max is -V6, trace-cmd should not error if someone passes in -V7. The way this is handled, is just set the verbosity to the highest level if the number supplied is above the highest level.

---
 tracecmd/trace-cmd.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
tracecmd/trace-cmd.c +3 -1
index 7f5d1ffd..9fc126e4 100644
@@ -68,7 +68,9 @@ int trace_set_verbose(char *level)
 
 	if (isdigit(level[0])) {
 		id = atoi(level);
-		if (id >= TEP_LOG_NONE && id <= TEP_LOG_ALL) {
+		if (id >= TEP_LOG_NONE) {
+			if (id > TEP_LOG_ALL)
+				id = TEP_LOG_ALL;
 			tracecmd_set_loglevel(id);
 			return 0;
 		}
Signature · 1 line
2.30.2