Skip to contentSkip to conversation

trace-cmd extract:

PATCH New Steven Rostedt 1 participant 4 messages Feb 4 Documentation

lore
Share & tools
lore
#0 lore raw

cover trace-cmd extract:

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

Some updates for trace-cmd extract:

- Always read the BTF file if it exists, as it isn't known if it is needed or not.

- Do not delete the instance that it is extracting after it extracts the data. That was simply annoying.

- Add a -K flag to trace-cmd record that doesn't reset anything before it starts recording.

Steven Rostedt (Google) (3):
trace-cmd extract: Always read BTF file if available trace-cmd record: Add -K flag to keep current settings trace-cmd extract: Do not delete instances after extraction

 .../trace-cmd/trace-cmd-record.1.txt          |  7 +++-
 tracecmd/trace-record.c                       | 39 +++++++++++--------
 tracecmd/trace-usage.c                        |  1 +
 3 files changed, 30 insertions(+), 17 deletions(-)
Signature · 1 line
2.51.0
#1 lore raw

PATCH 1/3 trace-cmd extract: Always read BTF file if available

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

On extract, always read the btf file as it isn't known yet if it will be needed or not.

---
 tracecmd/trace-record.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)
tracecmd/trace-record.c +9 -9
index 4872d0d77c8e..1cef9a623158 100644
@@ -4666,13 +4666,21 @@ static void check_need_btf(bool *need_btf, struct tracefs_instance *instance)
 	free(current);
 }
 
+#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)
+#define IS_RECORD_AGENT(ctx) ((ctx)->curr_cmd == CMD_record_agent)
+
 static void record_data(struct common_record_context *ctx)
 {
 	struct tracecmd_output *handle;
 	struct buffer_instance *instance;
 	bool have_proxy = false;
 	bool local = false;
-	bool need_btf = false;
+	bool need_btf = IS_EXTRACT(ctx);
 	int max_cpu_count = local_cpu_count;
 	char **temp_files;
 	int i;
@@ -6230,14 +6238,6 @@ static void init_common_record_context(struct common_record_context *ctx,
 	init_top_instance();
 }
 
-#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)
-#define IS_RECORD_AGENT(ctx) ((ctx)->curr_cmd == CMD_record_agent)
-
 static void add_argv(struct buffer_instance *instance, char *arg, bool prepend)
 {
 	instance->argv = realloc(instance->argv,
Signature · 1 line
2.51.0
#2 lore raw

PATCH 2/3 trace-cmd record: Add -K flag to keep current settings

In reply to Steven Rostedt

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

Add a -K flag to keep the current settings and not to reset before executing the record. This makes trace-cmd record act more like trace-cmd set but also record the data.

Also fix typo in trace-cmd record man page.

---
 Documentation/trace-cmd/trace-cmd-record.1.txt |  7 ++++++-
 tracecmd/trace-record.c                        | 18 +++++++++++-------
 tracecmd/trace-usage.c                         |  1 +
 3 files changed, 18 insertions(+), 8 deletions(-)
Documentation/trace-cmd/trace-cmd-record.1.txt +6 -1
index 7cb652bc3c0c..494c5c9f7155 100644
@@ -254,12 +254,17 @@ OPTIONS
 *-k*::
     By default, when trace-cmd is finished tracing, it will reset the buffers
     and disable all the tracing that it enabled. This option keeps trace-cmd
-    from disabling the tracer and reseting the buffer. This option is useful for
+    from disabling the tracer and resetting the buffer. This option is useful for
     debugging trace-cmd.
 
     Note: usually trace-cmd will set the "tracing_on" file back to what it
     was before it was called. This option will leave that file set to zero.
 
+*-K*::
+    By default, when before trace-cmd starts recording, it will reset the buffers
+    and clear events as well as any triggers and such. This option keeps trace-cmd
+    from doing that. It is similar to *trace-cmd set* but still records data.
+
 *-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
tracecmd/trace-record.c +11 -7
index 1cef9a623158..1707345b343f 100644
@@ -73,6 +73,7 @@ static tracecmd_handle_init_func handle_init = NULL;
 static int rt_prio;
 
 static int keep;
+static int Keep; // do not reset before tracing
 
 static int latency;
 static long sleep_time = 1000;
@@ -6438,9 +6439,6 @@ 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;
@@ -6483,7 +6481,7 @@ static void parse_record_options(int argc,
 		if (IS_EXTRACT(ctx))
 			opts = "+haf:Fp:co:O:sr:g:l:n:P:N:tb:B:ksiT";
 		else
-			opts = "+hae:f:FA:p:cC:dDGo:O:s:r:V:vg:l:n:P:N:tb:R:B:ksSiTm:M:H:q";
+			opts = "+hae:f:FA:p:cC:dDGo:O:s:r:V:vg:l:n:P:N:tb:R:B:kKsSiTm:M:H:q";
 		c = getopt_long (argc-1, argv+1, opts, long_options, &option_index);
 		if (c == -1)
 			break;
@@ -6852,6 +6850,9 @@ static void parse_record_options(int argc,
 			if (IS_PROFILE(ctx))
 				ctx->instance->flags |= BUFFER_FL_PROFILE;
 			break;
+		case 'K':
+			Keep = 1;
+			/* fall through */
 		case 'k':
 			cmd_check_die(ctx, CMD_set, *(argv+1), "-k");
 			keep = 1;
@@ -7216,7 +7217,7 @@ static void record_trace(int argc, char **argv,
 		ctx->topt = 1;
 
 	update_first_instance(ctx->instance, ctx->topt);
-	if (!IS_CMDSET(ctx)) {
+	if (!Keep) {
 		check_doing_something();
 		check_function_plugin();
 	}
@@ -7258,7 +7259,7 @@ static void record_trace(int argc, char **argv,
 
 	if (!is_guest(ctx->instance))
 		fset = set_ftrace(ctx->instance, !ctx->disable, ctx->total_disable);
-	if (!IS_CMDSET(ctx))
+	if (!Keep)
 		tracecmd_disable_all_tracing(1);
 
 	for_all_instances(instance)
@@ -7314,7 +7315,7 @@ static void record_trace(int argc, char **argv,
 
 		update_task_filter();
 
-		if (!IS_CMDSET(ctx))
+		if (!Keep)
 			tracecmd_enable_tracing();
 
 		if (type & (TRACE_TYPE_START | TRACE_TYPE_SET))
@@ -7416,6 +7417,9 @@ void trace_set(int argc, char **argv)
 {
 	struct common_record_context ctx;
 
+	/* Keep the current settings */
+	Keep = 1;
+	keep = 1;
 	parse_record_options(argc, argv, CMD_set, &ctx);
 	record_trace_command(argc, argv, &ctx);
 	exit(0);
tracecmd/trace-usage.c +1 -0
index f5a1c74c2ddf..e7b32f800e00 100644
@@ -50,6 +50,7 @@ static struct usage_help usage_help[] = {
 		"          -b change kernel buffersize (in kilobytes per CPU)\n"
 		"          -B create sub buffer and following events will be enabled here\n"
 		"          -k do not reset the buffers after tracing.\n"
+		"          -K do not reset the buffers before tracing.\n"
 		"          -i do not fail if an event is not found\n"
 		"          -q print no output to the screen\n"
 		"          -G when profiling, set soft and hard irqs as global\n"
Signature · 1 line
2.51.0
#3 lore raw

PATCH 3/3 trace-cmd extract: Do not delete instances after extraction

In reply to Steven Rostedt

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

After trace-cmd extract is finished reading an instance, it deletes that instance. That is incorrect behavior.

---
 tracecmd/trace-record.c | 3 +++
 1 file changed, 3 insertions(+)
tracecmd/trace-record.c +3 -0
index 1707345b343f..30727d613492 100644
@@ -7454,6 +7454,9 @@ void trace_extract(int argc, char **argv)
 		/* Some instances may not be created yet */
 		if (instance->tracing_on_init_val < 0)
 			instance->tracing_on_init_val = 1;
+
+		/* Keep all instances */
+		instance->flags |= BUFFER_FL_KEEP;
 	}
 
 	/* Extracting data records all events in the system. */
Signature · 1 line
2.51.0