Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
* [PATCH 1/2] trace-cmd: Add new subcommand "set"
@ 2020-05-29  7:02 Tzvetomir Stoyanov (VMware)
  2020-05-29  7:02 ` [PATCH 2/2] trace-cmd: Man page for "set" subcommand Tzvetomir Stoyanov (VMware)
  2020-05-31 21:52 ` [PATCH 1/2] trace-cmd: Add new subcommand "set" Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-05-29  7:02 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

The command "set" configures various ftarce parameters, like "record"
and "start" commands, but does not reset ftrace state on exit.

Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=207781
Reported-by: Steven Rostedt (VMware) <rostedt@goodmis.org>
Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 tracecmd/include/trace-local.h |  2 ++
 tracecmd/trace-cmd.c           |  1 +
 tracecmd/trace-record.c        | 64 ++++++++++++++++++++++++++++++----
 tracecmd/trace-usage.c         | 33 ++++++++++++++++++
 4 files changed, 93 insertions(+), 7 deletions(-)

diff --git a/tracecmd/include/trace-local.h b/tracecmd/include/trace-local.h
index 5d585509..5ec05149 100644
--- a/tracecmd/include/trace-local.h
+++ b/tracecmd/include/trace-local.h
@@ -57,6 +57,8 @@ void trace_reset(int argc, char **argv);
 
 void trace_start(int argc, char **argv);
 
+void trace_set(int argc, char **argv);
+
 void trace_extract(int argc, char **argv);
 
 void trace_stream(int argc, char **argv);
diff --git a/tracecmd/trace-cmd.c b/tracecmd/trace-cmd.c
index dbfcc974..7376c5a5 100644
--- a/tracecmd/trace-cmd.c
+++ b/tracecmd/trace-cmd.c
@@ -90,6 +90,7 @@ struct command commands[] = {
 	{"check-events", trace_check_events},
 	{"record", trace_record},
 	{"start", trace_start},
+	{"set", trace_set},
 	{"extract", trace_extract},
 	{"stop", trace_stop},
 	{"stream", trace_stream},
diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 3242368e..03c31b2b 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -63,6 +63,7 @@ enum trace_type {
 	TRACE_TYPE_START	= (1 << 1),
 	TRACE_TYPE_STREAM	= (1 << 2),
 	TRACE_TYPE_EXTRACT	= (1 << 3),
+	TRACE_TYPE_SET		= (1 << 4),
 };
 
 static tracecmd_handle_init_func handle_init = NULL;
@@ -185,6 +186,7 @@ enum trace_cmd {
 	CMD_profile,
 	CMD_record,
 	CMD_record_agent,
+	CMD_set,
 };
 
 struct common_record_context {
@@ -5719,6 +5721,7 @@ static void init_common_record_context(struct common_record_context *ctx,
 
 #define IS_EXTRACT(ctx) ((ctx)->curr_cmd == CMD_extract)
 #define IS_START(ctx) ((ctx)->curr_cmd == CMD_start)
+#define IS_CMDSET(ctx) ((ctx)->curr_cmd == CMD_set)
 #define IS_STREAM(ctx) ((ctx)->curr_cmd == CMD_stream)
 #define IS_PROFILE(ctx) ((ctx)->curr_cmd == CMD_profile)
 #define IS_RECORD(ctx) ((ctx)->curr_cmd == CMD_record)
@@ -5782,6 +5785,14 @@ static void add_arg(struct buffer_instance *instance,
 	/* Not found? */
 }
 
+static void set_cmd_check(struct common_record_context *ctx, char *param)
+{
+	if (IS_CMDSET(ctx)) {
+		die("%s has no effect with set command\n"
+		    "Did you mean 'record'?", param);
+	}
+}
+
 static void parse_record_options(int argc,
 				 char **argv,
 				 enum trace_cmd curr_cmd,
@@ -5803,6 +5814,9 @@ static void parse_record_options(int argc,
 
 	init_common_record_context(ctx, curr_cmd);
 
+	if (IS_CMDSET(ctx))
+		keep = 1;
+
 	for (;;) {
 		int option_index = 0;
 		int ret;
@@ -5854,6 +5868,7 @@ static void parse_record_options(int argc,
 			usage(argv);
 			break;
 		case 'a':
+			set_cmd_check(ctx, "-a");
 			if (IS_EXTRACT(ctx)) {
 				add_all_instances();
 			} else {
@@ -5927,10 +5942,12 @@ static void parse_record_options(int argc,
 			break;
 		}
 		case 'F':
+			set_cmd_check(ctx, "-F");
 			test_set_event_pid(ctx->instance);
 			filter_task = 1;
 			break;
 		case 'G':
+			set_cmd_check(ctx, "-G");
 			ctx->global = 1;
 			break;
 		case 'P':
@@ -6006,6 +6023,7 @@ static void parse_record_options(int argc,
 			ctx->disable = 1;
 			break;
 		case 'o':
+			set_cmd_check(ctx, "-o");
 			if (IS_RECORD_AGENT(ctx))
 				die("-o incompatible with agent recording");
 			if (host)
@@ -6043,10 +6061,12 @@ static void parse_record_options(int argc,
 			save_option(ctx->instance, "stacktrace");
 			break;
 		case 'H':
+			set_cmd_check(ctx, "-H");
 			add_hook(ctx->instance, optarg);
 			ctx->events = 1;
 			break;
 		case 's':
+			set_cmd_check(ctx, "-s");
 			if (IS_EXTRACT(ctx)) {
 				if (optarg)
 					usage(argv);
@@ -6058,15 +6078,18 @@ static void parse_record_options(int argc,
 			sleep_time = atoi(optarg);
 			break;
 		case 'S':
+			set_cmd_check(ctx, "-S");
 			ctx->manual = 1;
 			/* User sets events for profiling */
 			if (!event)
 				ctx->events = 0;
 			break;
 		case 'r':
+			set_cmd_check(ctx, "-r");
 			rt_prio = atoi(optarg);
 			break;
 		case 'N':
+			set_cmd_check(ctx, "-N");
 			if (!IS_RECORD(ctx))
 				die("-N only available with record");
 			if (IS_RECORD_AGENT(ctx))
@@ -6086,6 +6109,7 @@ static void parse_record_options(int argc,
 			ctx->instance->cpumask = alloc_mask_from_hex(ctx->instance, optarg);
 			break;
 		case 't':
+			set_cmd_check(ctx, "-t");
 			if (IS_EXTRACT(ctx))
 				ctx->topt = 1; /* Extract top instance also */
 			else
@@ -6103,20 +6127,24 @@ static void parse_record_options(int argc,
 				ctx->instance->flags |= BUFFER_FL_PROFILE;
 			break;
 		case 'k':
+			set_cmd_check(ctx, "-k");
 			keep = 1;
 			break;
 		case 'i':
 			ignore_event_not_found = 1;
 			break;
 		case OPT_user:
+			set_cmd_check(ctx, "--user");
 			ctx->user = strdup(optarg);
 			if (!ctx->user)
 				die("Failed to allocate user name");
 			break;
 		case OPT_procmap:
+			set_cmd_check(ctx, "--proc-map");
 			ctx->instance->get_procmap = 1;
 			break;
 		case OPT_date:
+			set_cmd_check(ctx, "--date");
 			ctx->date = 1;
 			if (ctx->data_flags & DATA_FL_OFFSET)
 				die("Can not use both --date and --ts-offset");
@@ -6126,12 +6154,15 @@ static void parse_record_options(int argc,
 			func_stack = 1;
 			break;
 		case OPT_nosplice:
+			set_cmd_check(ctx, "--nosplice");
 			recorder_flags |= TRACECMD_RECORD_NOSPLICE;
 			break;
 		case OPT_nofifos:
+			set_cmd_check(ctx, "--nofifos");
 			no_fifos = true;
 			break;
 		case OPT_profile:
+			set_cmd_check(ctx, "--profile");
 			handle_init = trace_init_profile;
 			ctx->instance->flags |= BUFFER_FL_PROFILE;
 			ctx->events = 1;
@@ -6145,9 +6176,11 @@ static void parse_record_options(int argc,
 			dup2(2, 1);
 			break;
 		case OPT_bycomm:
+			set_cmd_check(ctx, "--by-comm");
 			trace_profile_set_merge_like_comms();
 			break;
 		case OPT_tsoffset:
+			set_cmd_check(ctx, "--ts-offset");
 			ctx->date2ts = strdup(optarg);
 			if (ctx->data_flags & DATA_FL_DATE)
 				die("Can not use both --date and --ts-offset");
@@ -6160,9 +6193,11 @@ static void parse_record_options(int argc,
 				die("Could not allocate option");
 			break;
 		case OPT_cmdlines_size:
+			set_cmd_check(ctx, "--cmdlines-size");
 			ctx->saved_cmdlines_size = atoi(optarg);
 			break;
 		case OPT_no_filter:
+			set_cmd_check(ctx, "--no-filter");
 			no_filter = true;
 			break;
 		case OPT_debug:
@@ -6176,6 +6211,7 @@ static void parse_record_options(int argc,
 			ctx->filtered = 0;
 			break;
 		case OPT_tsyncinterval:
+			set_cmd_check(ctx, "--tsync-interval");
 			top_instance.tsync.loop_interval = atoi(optarg);
 			guest_sync_set = true;
 			break;
@@ -6221,8 +6257,8 @@ static void parse_record_options(int argc,
 		die(" -c can only be used with -F (or -P with event-fork support)");
 
 	if ((argc - optind) >= 2) {
-		if (IS_START(ctx))
-			die("Command start does not take any commands\n"
+		if (IS_START(ctx) || IS_CMDSET(ctx))
+			die("Commands start and set do not take any commands\n"
 			    "Did you mean 'record'?");
 		if (IS_EXTRACT(ctx))
 			die("Command extract does not take any commands\n"
@@ -6265,7 +6301,8 @@ static enum trace_type get_trace_cmd_type(enum trace_cmd cmd)
 		{CMD_extract, TRACE_TYPE_EXTRACT},
 		{CMD_profile, TRACE_TYPE_STREAM},
 		{CMD_start, TRACE_TYPE_START},
-		{CMD_record_agent, TRACE_TYPE_RECORD}
+		{CMD_record_agent, TRACE_TYPE_RECORD},
+		{CMD_set, TRACE_TYPE_SET}
 	};
 
 	for (int i = 0; i < ARRAY_SIZE(trace_type_per_command); i++) {
@@ -6342,8 +6379,10 @@ static void record_trace(int argc, char **argv,
 		ctx->topt = 1;
 
 	update_first_instance(ctx->instance, ctx->topt);
-	check_doing_something();
-	check_function_plugin();
+	if (!IS_CMDSET(ctx)) {
+		check_doing_something();
+		check_function_plugin();
+	}
 
 	if (!ctx->output)
 		ctx->output = DEFAULT_INPUT_FILE;
@@ -6371,7 +6410,8 @@ static void record_trace(int argc, char **argv,
 
 	if (!is_guest(ctx->instance))
 		fset = set_ftrace(!ctx->disable, ctx->total_disable);
-	tracecmd_disable_all_tracing(1);
+	if (!IS_CMDSET(ctx))
+		tracecmd_disable_all_tracing(1);
 
 	for_all_instances(instance)
 		set_clock(instance);
@@ -6412,7 +6452,8 @@ static void record_trace(int argc, char **argv,
 			start_threads(type, ctx);
 	} else {
 		update_task_filter();
-		tracecmd_enable_tracing();
+		if (!IS_CMDSET(ctx))
+			tracecmd_enable_tracing();
 		exit(0);
 	}
 
@@ -6486,6 +6527,15 @@ void trace_start(int argc, char **argv)
 	exit(0);
 }
 
+void trace_set(int argc, char **argv)
+{
+	struct common_record_context ctx;
+
+	parse_record_options(argc, argv, CMD_set, &ctx);
+	record_trace(argc, argv, &ctx);
+	exit(0);
+}
+
 void trace_extract(int argc, char **argv)
 {
 	struct common_record_context ctx;
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index d43ca490..83b0dc57 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -65,6 +65,39 @@ static struct usage_help usage_help[] = {
 		"               If 0 is specified, no loop is performed - timestamps offset is calculated only twice,"
 		"                                                         at the beginnig and at the end of the trace\n"
 	},
+	{
+		"set",
+		"set a ftarce configuration parameter",
+		" %s set [-v][-e event [-f filter]][-p plugin][-d][-D] \\\n"
+		"           [-q][-s usecs][-O option ][-l func][-g func][-n func] \\\n"
+		"           [-P pid][-b size][-B buf][-m max][-C clock]\n"
+		"          -e enable event\n"
+		"          -f filter for previous -e event\n"
+		"          -R trigger for previous -e event\n"
+		"          -p set ftrace plugin\n"
+		"          -P set PIDs to be traced\n"
+		"          -c also trace the children of -P, if kernel supports it\n"
+		"          -C set the trace clock\n"
+		"          -T do a stacktrace on all events\n"
+		"          -l filter function name\n"
+		"          -g set graph function\n"
+		"          -n do not trace function\n"
+		"          -m max size per CPU in kilobytes\n"
+		"          -M set CPU mask to trace\n"
+		"          -v will negate all -e after it (disable those events)\n"
+		"          -d disable function tracer when running\n"
+		"          -D Full disable of function tracing (for all users)\n"
+		"          -O option to enable (or disable)\n"
+		"          -b change kernel buffersize (in kilobytes per CPU)\n"
+		"          -B create sub buffer and following events will be enabled here\n"
+		"          -i do not fail if an event is not found\n"
+		"          -q print no output to the screen\n"
+		"          --quiet print no output to the screen\n"
+		"          --module filter module name\n"
+		"          --func-stack perform a stack trace for function tracer\n"
+		"             (use with caution)\n"
+		"          --max-graph-depth limit function_graph depth\n"
+	},
 	{
 		"start",
 		"start tracing without recording into a file",
-- 
2.26.2


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

* [PATCH 2/2] trace-cmd: Man page for "set" subcommand
  2020-05-29  7:02 [PATCH 1/2] trace-cmd: Add new subcommand "set" Tzvetomir Stoyanov (VMware)
@ 2020-05-29  7:02 ` Tzvetomir Stoyanov (VMware)
  2020-05-31 21:52 ` [PATCH 1/2] trace-cmd: Add new subcommand "set" Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Tzvetomir Stoyanov (VMware) @ 2020-05-29  7:02 UTC (permalink / raw)
  To: rostedt; +Cc: linux-trace-devel

Man page, describing the new "trace-cmd set" subcommand

Signed-off-by: Tzvetomir Stoyanov (VMware) <tz.stoyanov@gmail.com>
---
 Documentation/trace-cmd-set.1.txt | 244 ++++++++++++++++++++++++++++++
 1 file changed, 244 insertions(+)
 create mode 100644 Documentation/trace-cmd-set.1.txt

diff --git a/Documentation/trace-cmd-set.1.txt b/Documentation/trace-cmd-set.1.txt
new file mode 100644
index 00000000..c4217f0c
--- /dev/null
+++ b/Documentation/trace-cmd-set.1.txt
@@ -0,0 +1,244 @@
+TRACE-CMD-SET(1)
+================
+
+NAME
+----
+trace-cmd-set - set a configuration parameter of the Ftrace Linux internal tracer
+
+SYNOPSIS
+--------
+*trace-cmd set* ['OPTIONS']
+
+DESCRIPTION
+-----------
+The trace-cmd(1) set command will set a configuration parameter of the Ftrace
+Linux kernel tracer. The configured ftrace state can be restored to default
+using the trace-cmd-reset(1) command.
+
+OPTIONS
+-------
+*-p* 'tracer'::
+    Specify a tracer. Tracers usually do more than just trace an event.
+    Common tracers are: *function*, *function_graph*, *preemptirqsoff*,
+    *irqsoff*, *preemptoff* and *wakeup*. A tracer must be supported by the
+    running kernel. To see a list of available tracers, see trace-cmd-list(1).
+
+*-e* 'event'::
+    Specify an event to trace. Various static trace points have been added to
+    the Linux kernel. They are grouped by subsystem where you can enable all
+    events of a given subsystem or specify specific events to be enabled. The
+    'event' is of the format "subsystem:event-name". You can also just specify
+    the subsystem without the ':event-name' or the event-name without the
+    "subsystem:". Using "-e sched_switch" will enable the "sched_switch" event
+    where as, "-e sched" will enable all events under the "sched" subsystem.
+
+    The 'event' can also contain glob expressions. That is, "*stat*" will
+    select all events (or subsystems) that have the characters "stat" in their
+    names.
+
+    The keyword 'all' can be used to enable all events.
+
+*-T*::
+    Enable a stacktrace on each event. For example:
+
+          <idle>-0     [003] 58549.289091: sched_switch:         kworker/0:1:0 [120] R ==> trace-cmd:2603 [120]
+          <idle>-0     [003] 58549.289092: kernel_stack:         <stack trace>
+=> schedule (ffffffff814b260e)
+=> cpu_idle (ffffffff8100a38c)
+=> start_secondary (ffffffff814ab828)
+
+*--func-stack*::
+    Enable a stack trace on all functions. Note this is only applicable
+    for the "function" plugin tracer, and will only take effect if the
+    -l option is used and succeeds in limiting functions. If the function
+    tracer is not filtered, and the stack trace is enabled, you can live
+    lock the machine.
+
+*-f* 'filter'::
+    Specify a filter for the previous event. This must come after a *-e*. This
+    will filter what events get recorded based on the content of the event.
+    Filtering is passed to the kernel directly so what filtering is allowed
+    may depend on what version of the kernel you have. Basically, it will
+    let you use C notation to check if an event should be processed or not.
+
+----------------------------------------
+    ==, >=, <=, >, <, &, |, && and ||
+----------------------------------------
+
+    The above are usually safe to use to compare fields.
+
+*-R* 'trigger'::
+    Specify a trigger for the previous event. This must come after a *-e*.
+    This will add a given trigger to the given event. To only enable the trigger
+    and not the event itself, then place the event after the *-v* option.
+
+    See Documentation/trace/events.txt in the Linux kernel source for more
+    information on triggers.
+
+*-v*::
+    This will cause all events specified after it on the command line to not
+    be traced. This is useful for selecting a subsystem to be traced but to
+    leave out various events. For Example: "-e sched -v -e "\*stat\*"" will
+    enable all events in the sched subsystem except those that have "stat" in
+    their names.
+
+    Note: the *-v* option was taken from the way grep(1) inverts the following
+    matches.
+
+*-P* 'pid'::
+    This will filter only the specified process IDs. Using *-P* will let you
+    trace only events that are caused by the process.
+
+*-c*::
+     Used *-P* to trace the process' children too (if kernel supports it).
+
+*-C* 'clock'::
+     Set the trace clock to "clock".
+
+     Use trace-cmd(1) list -C to see what clocks are available.
+
+*-l* 'function-name'::
+    This will limit the 'function' and 'function_graph' tracers to only trace
+    the given function name. More than one *-l* may be specified on the
+    command line to trace more than one function. The limited use of glob
+    expressions are also allowed. These are 'match\*' to only filter functions
+    that start with 'match'. '\*match' to only filter functions that end with
+    'match'. '\*match\*' to only filter on functions that contain 'match'.
+
+*-g* 'function-name'::
+    This option is for the function_graph plugin. It will graph the given
+    function. That is, it will only trace the function and all functions that
+    it calls. You can have more than one *-g* on the command line.
+
+*-n* 'function-name'::
+    This has the opposite effect of *-l*. The function given with the *-n*
+    option will not be traced. This takes precedence, that is, if you include
+    the same function for both *-n* and *-l*, it will not be traced.
+
+*-d*::
+    Some tracer plugins enable the function tracer by default. Like the
+    latency tracers. This option prevents the function tracer from being
+    enabled at start up.
+
+*-D*::
+    The option *-d* will try to use the function-trace option to disable the
+    function tracer (if available), otherwise it defaults to the proc file:
+    /proc/sys/kernel/ftrace_enabled, but will not touch it if the function-trace
+    option is available.  The *-D* option will disable both the ftrace_enabled
+    proc file as well as the function-trace option if it exists.
+
+    Note, this disable function tracing for all users, which includes users
+    outside of ftrace tracers (stack_tracer, perf, etc).
+
+*-O* 'option'::
+    Ftrace has various options that can be enabled or disabled. This allows
+    you to set them. Appending the text 'no' to an option disables it.
+    For example: "-O nograph-time" will disable the "graph-time" Ftrace
+    option.
+
+*-b* 'size'::
+    This sets the ring buffer size to 'size' kilobytes. Because the Ftrace
+    ring buffer is per CPU, this size is the size of each per CPU ring buffer
+    inside the kernel. Using "-b 10000" on a machine with 4 CPUs will make
+    Ftrace have a total buffer size of 40 Megs.
+
+*-B* 'buffer-name'::
+    If the kernel supports multiple buffers, this will add a buffer with
+    the given name. If the buffer name already exists, that buffer is just
+    reset.
+
+    After a buffer name is stated, all events added after that will be
+    associated with that buffer. If no buffer is specified, or an event
+    is specified before a buffer name, it will be associated with the
+    main (toplevel) buffer.
+
+     trace-cmd set -e sched -B block -e block -B time -e timer sleep 1
+
+    The above is will enable all sched events in the main buffer. It will
+    then create a 'block' buffer instance and enable all block events within
+    that buffer. A 'time' buffer instance is created and all timer events
+    will be enabled for that event.
+
+*-m* 'size'::
+    The max size in kilobytes that a per cpu buffer should be. Note, due
+    to rounding to page size, the number may not be totally correct.
+    Also, this is performed by switching between two buffers that are half
+    the given size thus the output may not be of the given size even if
+    much more was written.
+
+    Use this to prevent running out of diskspace for long runs.
+
+*-M* 'cpumask'::
+    Set the cpumask for to trace. It only affects the last buffer instance
+    given. If supplied before any buffer instance, then it affects the
+    main buffer. The value supplied must be a hex number.
+
+     trace-cmd record -p function -M c -B events13 -e all -M 5
+
+    If the -M is left out, then the mask stays the same. To enable all
+    CPUs, pass in a value of '-1'.
+
+*-i*::
+    By default, if an event is listed that trace-cmd does not find, it
+    will exit with an error. This option will just ignore events that are
+    listed on the command line but are not found on the system.
+
+*-q* | *--quiet*::
+    Suppresses normal output, except for errors.
+
+*--max-graph-depth* 'depth'::
+    Set the maximum depth the function_graph tracer will trace into a function.
+    A value of one will only show where userspace enters the kernel but not any
+    functions called in the kernel. The default is zero, which means no limit.
+
+*--module* 'module'::
+    Filter a module's name in function tracing. It is equivalent to adding
+    ':mod:module' after all other functions being filtered. If no other function
+    filter is listed, then all modules functions will be filtered in the filter.
+
+    '--module snd'  is equivalent to  '-l :mod:snd'
+
+    '--module snd -l "*jack*"' is equivalent to '-l "*jack*:mod:snd"'
+
+    '--module snd -n "*"' is equivalent to '-n :mod:snd'
+
+*--stderr*::
+    Have output go to stderr instead of stdout, but the output of the command
+    executed will not be changed. This is useful if you want to monitor the
+    output of the command being executed, but not see the output from trace-cmd.
+
+EXAMPLES
+--------
+
+Enable all events for tracing:
+
+------------------------------
+ # trace-cmd set -e all
+------------------------------
+
+Set the function tracer:
+
+------------------------------
+ # trace-cmd set -p function
+------------------------------
+
+
+SEE ALSO
+--------
+trace-cmd(1), trace-cmd-report(1), trace-cmd-start(1), trace-cmd-stop(1),
+trace-cmd-extract(1), trace-cmd-reset(1), trace-cmd-split(1),
+trace-cmd-list(1), trace-cmd-listen(1), trace-cmd-profile(1)
+
+AUTHOR
+------
+Written by Steven Rostedt, <rostedt@goodmis.org>
+
+RESOURCES
+---------
+git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/trace-cmd.git
+
+COPYING
+-------
+Copyright \(C) 2010 Red Hat, Inc. Free use of this software is granted under
+the terms of the GNU Public License (GPL).
+
-- 
2.26.2


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

* Re: [PATCH 1/2] trace-cmd: Add new subcommand "set"
  2020-05-29  7:02 [PATCH 1/2] trace-cmd: Add new subcommand "set" Tzvetomir Stoyanov (VMware)
  2020-05-29  7:02 ` [PATCH 2/2] trace-cmd: Man page for "set" subcommand Tzvetomir Stoyanov (VMware)
@ 2020-05-31 21:52 ` Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Steven Rostedt @ 2020-05-31 21:52 UTC (permalink / raw)
  To: Tzvetomir Stoyanov (VMware); +Cc: linux-trace-devel

On Fri, 29 May 2020 10:02:19 +0300
"Tzvetomir Stoyanov (VMware)" <tz.stoyanov@gmail.com> wrote:

>  
> +static void set_cmd_check(struct common_record_context *ctx, char *param)
> +{
> +	if (IS_CMDSET(ctx)) {
> +		die("%s has no effect with set command\n"
> +		    "Did you mean 'record'?", param);
> +	}
> +}
> +
>  static void parse_record_options(int argc,
>  				 char **argv,
>  				 enum trace_cmd curr_cmd,
> @@ -5803,6 +5814,9 @@ static void parse_record_options(int argc,
>  
>  	init_common_record_context(ctx, curr_cmd);
>  
> +	if (IS_CMDSET(ctx))
> +		keep = 1;
> +
>  	for (;;) {
>  		int option_index = 0;
>  		int ret;
> @@ -5854,6 +5868,7 @@ static void parse_record_options(int argc,
>  			usage(argv);
>  			break;
>  		case 'a':
> +			set_cmd_check(ctx, "-a");
>  			if (IS_EXTRACT(ctx)) {
>  				add_all_instances();
>  			} else {
> @@ -5927,10 +5942,12 @@ static void parse_record_options(int argc,
>  			break;
>  		}
>  		case 'F':
> +			set_cmd_check(ctx, "-F");
>  			test_set_event_pid(ctx->instance);
>  			filter_task = 1;
>  			break;

I was thinking that perhaps we should have -F stay, and that way
anything we add can be filtered with the command. I think the same
should be allowed for start too. There's been several times I wanted
the code to just trace a command (not record it though), but couldn't
do it with trace-cmd.

>  		case 'G':
> +			set_cmd_check(ctx, "-G");

Hmm, I just realized that we don't have -G documented.


>  			ctx->global = 1;
>  			break;
>  		case 'P':
> @@ -6006,6 +6023,7 @@ static void parse_record_options(int argc,
>  			ctx->disable = 1;
>  			break;
>  		case 'o':
> +			set_cmd_check(ctx, "-o");
>  			if (IS_RECORD_AGENT(ctx))
>  				die("-o incompatible with agent recording");
>  			if (host)
> @@ -6043,10 +6061,12 @@ static void parse_record_options(int argc,
>  			save_option(ctx->instance, "stacktrace");
>  			break;
>  		case 'H':
> +			set_cmd_check(ctx, "-H");
>  			add_hook(ctx->instance, optarg);
>  			ctx->events = 1;
>  			break;
>  		case 's':
> +			set_cmd_check(ctx, "-s");
>  			if (IS_EXTRACT(ctx)) {
>  				if (optarg)
>  					usage(argv);
> @@ -6058,15 +6078,18 @@ static void parse_record_options(int argc,
>  			sleep_time = atoi(optarg);
>  			break;
>  		case 'S':
> +			set_cmd_check(ctx, "-S");
>  			ctx->manual = 1;
>  			/* User sets events for profiling */
>  			if (!event)
>  				ctx->events = 0;
>  			break;
>  		case 'r':
> +			set_cmd_check(ctx, "-r");
>  			rt_prio = atoi(optarg);
>  			break;
>  		case 'N':
> +			set_cmd_check(ctx, "-N");
>  			if (!IS_RECORD(ctx))
>  				die("-N only available with record");
>  			if (IS_RECORD_AGENT(ctx))
> @@ -6086,6 +6109,7 @@ static void parse_record_options(int argc,
>  			ctx->instance->cpumask = alloc_mask_from_hex(ctx->instance, optarg);
>  			break;
>  		case 't':
> +			set_cmd_check(ctx, "-t");
>  			if (IS_EXTRACT(ctx))
>  				ctx->topt = 1; /* Extract top instance also */
>  			else
> @@ -6103,20 +6127,24 @@ static void parse_record_options(int argc,
>  				ctx->instance->flags |= BUFFER_FL_PROFILE;
>  			break;
>  		case 'k':
> +			set_cmd_check(ctx, "-k");
>  			keep = 1;
>  			break;
>  		case 'i':
>  			ignore_event_not_found = 1;
>  			break;
>  		case OPT_user:
> +			set_cmd_check(ctx, "--user");

If we allow commands, then perhaps we can keep this too.

>  			ctx->user = strdup(optarg);
>  			if (!ctx->user)
>  				die("Failed to allocate user name");
>  			break;
>  		case OPT_procmap:
> +			set_cmd_check(ctx, "--proc-map");
>  			ctx->instance->get_procmap = 1;
>  			break;
>  		case OPT_date:
> +			set_cmd_check(ctx, "--date");
>  			ctx->date = 1;
>  			if (ctx->data_flags & DATA_FL_OFFSET)
>  				die("Can not use both --date and --ts-offset");
> @@ -6126,12 +6154,15 @@ static void parse_record_options(int argc,
>  			func_stack = 1;
>  			break;
>  		case OPT_nosplice:
> +			set_cmd_check(ctx, "--nosplice");
>  			recorder_flags |= TRACECMD_RECORD_NOSPLICE;
>  			break;
>  		case OPT_nofifos:
> +			set_cmd_check(ctx, "--nofifos");
>  			no_fifos = true;
>  			break;
>  		case OPT_profile:
> +			set_cmd_check(ctx, "--profile");
>  			handle_init = trace_init_profile;
>  			ctx->instance->flags |= BUFFER_FL_PROFILE;
>  			ctx->events = 1;
> @@ -6145,9 +6176,11 @@ static void parse_record_options(int argc,
>  			dup2(2, 1);
>  			break;
>  		case OPT_bycomm:
> +			set_cmd_check(ctx, "--by-comm");
>  			trace_profile_set_merge_like_comms();
>  			break;
>  		case OPT_tsoffset:
> +			set_cmd_check(ctx, "--ts-offset");
>  			ctx->date2ts = strdup(optarg);
>  			if (ctx->data_flags & DATA_FL_DATE)
>  				die("Can not use both --date and --ts-offset");
> @@ -6160,9 +6193,11 @@ static void parse_record_options(int argc,
>  				die("Could not allocate option");
>  			break;
>  		case OPT_cmdlines_size:
> +			set_cmd_check(ctx, "--cmdlines-size");

--cmdlines-size is something we definitely want to keep here. It's a
file in the tracefs directory, and something that we should allow
trace-cmd set to modify.


>  			ctx->saved_cmdlines_size = atoi(optarg);
>  			break;
>  		case OPT_no_filter:
> +			set_cmd_check(ctx, "--no-filter");
>  			no_filter = true;
>  			break;
>  		case OPT_debug:
> @@ -6176,6 +6211,7 @@ static void parse_record_options(int argc,
>  			ctx->filtered = 0;
>  			break;
>  		case OPT_tsyncinterval:
> +			set_cmd_check(ctx, "--tsync-interval");
>  			top_instance.tsync.loop_interval = atoi(optarg);
>  			guest_sync_set = true;
>  			break;
> @@ -6221,8 +6257,8 @@ static void parse_record_options(int argc,
>  		die(" -c can only be used with -F (or -P with event-fork support)");
>  
>  	if ((argc - optind) >= 2) {
> -		if (IS_START(ctx))
> -			die("Command start does not take any commands\n"
> +		if (IS_START(ctx) || IS_CMDSET(ctx))
> +			die("Commands start and set do not take any commands\n"

Perhaps we should add a patch first that lets trace-cmd start run commands?

-- Steve

>  			    "Did you mean 'record'?");
>  		if (IS_EXTRACT(ctx))
>  			die("Command extract does not take any commands\n"
> @@ -6265,7 +6301,8 @@ static enum trace_type get_trace_cmd_type(enum trace_cmd cmd)
>  		{CMD_extract, TRACE_TYPE_EXTRACT},
>  		{CMD_profile, TRACE_TYPE_STREAM},
>  		{CMD_start, TRACE_TYPE_START},
> -		{CMD_record_agent, TRACE_TYPE_RECORD}
> +		{CMD_record_agent, TRACE_TYPE_RECORD},
> +		{CMD_set, TRACE_TYPE_SET}
>  	};
>  
>  	for (int i = 0; i < ARRAY_SIZE(trace_type_per_command); i++) {
> @@ -6342,8 +6379,10 @@ static void record_trace(int argc, char **argv,
>  		ctx->topt = 1;
>  
>  	update_first_instance(ctx->instance, ctx->topt);
> -	check_doing_something();
> -	check_function_plugin();
> +	if (!IS_CMDSET(ctx)) {
> +		check_doing_something();
> +		check_function_plugin();
> +	}
>  
>  	if (!ctx->output)
>  		ctx->output = DEFAULT_INPUT_FILE;
> @@ -6371,7 +6410,8 @@ static void record_trace(int argc, char **argv,
>  
>  	if (!is_guest(ctx->instance))
>  		fset = set_ftrace(!ctx->disable, ctx->total_disable);
> -	tracecmd_disable_all_tracing(1);
> +	if (!IS_CMDSET(ctx))
> +		tracecmd_disable_all_tracing(1);
>  
>  	for_all_instances(instance)
>  		set_clock(instance);
> @@ -6412,7 +6452,8 @@ static void record_trace(int argc, char **argv,
>  			start_threads(type, ctx);
>  	} else {
>  		update_task_filter();
> -		tracecmd_enable_tracing();
> +		if (!IS_CMDSET(ctx))
> +			tracecmd_enable_tracing();
>  		exit(0);
>  	}
>  
> @@ -6486,6 +6527,15 @@ void trace_start(int argc, char **argv)
>  	exit(0);
>  }
>  

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

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-05-29  7:02 [PATCH 1/2] trace-cmd: Add new subcommand "set" Tzvetomir Stoyanov (VMware)
2020-05-29  7:02 ` [PATCH 2/2] trace-cmd: Man page for "set" subcommand Tzvetomir Stoyanov (VMware)
2020-05-31 21:52 ` [PATCH 1/2] trace-cmd: Add new subcommand "set" Steven Rostedt

Linux-Trace-Devel Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-trace-devel/0 linux-trace-devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-trace-devel linux-trace-devel/ https://lore.kernel.org/linux-trace-devel \
		linux-trace-devel@vger.kernel.org
	public-inbox-index linux-trace-devel

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-trace-devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git