Linux-Trace-Devel Archive on lore.kernel.org
 help / color / Atom feed
From: vincent.donnefort@arm.com
To: linux-trace-devel@vger.kernel.org
Cc: Vincent Donnefort <vincent.donnefort@arm.com>
Subject: [PATCH 2/2] trace-cmd: Add an option to set saved_cmdlines_size
Date: Thu,  7 Nov 2019 10:51:06 +0000
Message-ID: <1573123866-348262-2-git-send-email-vincent.donnefort@arm.com> (raw)
In-Reply-To: <1573123866-348262-1-git-send-email-vincent.donnefort@arm.com>

From: Vincent Donnefort <vincent.donnefort@arm.com>

The tracing file saved_cmdlines_size allows setting the number of entries
that saved_cmdlines will contain. The latter is then dumped into the
trace.dat file to map PIDs with comm. The default value is 128.

Signed-off-by: Vincent Donnefort <vincent.donnefort@arm.com>

diff --git a/tracecmd/trace-record.c b/tracecmd/trace-record.c
index 7260d27..a4e10a4 100644
--- a/tracecmd/trace-record.c
+++ b/tracecmd/trace-record.c
@@ -229,6 +229,7 @@ struct common_record_context {
 	int topt;
 	int do_child;
 	int run_command;
+	int saved_cmdlines_size;
 };
 
 static void add_reset_file(const char *file, const char *val, int prio)
@@ -1810,6 +1811,39 @@ static void set_options(void)
 	}
 }
 
+static void set_saved_cmdlines_size(struct common_record_context *ctx)
+{
+	char *path, *str;
+	int fd, len, ret;
+
+	if (!ctx->saved_cmdlines_size)
+		return;
+
+	path = tracecmd_get_tracing_file("saved_cmdlines_size");
+	if (!path)
+		goto err;
+
+	reset_save_file(path, RESET_DEFAULT_PRIO);
+
+	fd = open(path, O_WRONLY);
+	tracecmd_put_tracing_file(path);
+	if (fd < 0)
+		goto err;
+
+	len = asprintf(&str, "%d", ctx->saved_cmdlines_size);
+	if (len < 0)
+		die("%s couldn't allocate memory", __func__);
+
+	if (write(fd, str, len) > 0)
+		ret = 0;
+
+	close(fd);
+	free(str);
+err:
+	if (ret)
+		warning("Couldn't set saved_cmdlines_size");
+}
+
 static int trace_check_file_exists(struct buffer_instance *instance, char *file)
 {
 	struct stat st;
@@ -5480,7 +5514,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:vg:l:n:P:N:tb:R:B:ksSiTm:M:H:q";
+			opts = "+hae:f:FA:p:cC:dDGo:O:s:r:vg:l:n:P:N:tb:R:B:kK:sSiTm:M:H:qK";
 		c = getopt_long (argc-1, argv+1, opts, long_options, &option_index);
 		if (c == -1)
 			break;
@@ -5741,6 +5775,9 @@ static void parse_record_options(int argc,
 		case 'k':
 			keep = 1;
 			break;
+		case 'K':
+			ctx->saved_cmdlines_size = atoi(optarg);
+			break;
 		case 'i':
 			ignore_event_not_found = 1;
 			break;
@@ -5990,6 +6027,7 @@ static void record_trace(int argc, char **argv,
 			enable_events(instance);
 	}
 
+	set_saved_cmdlines_size(ctx);
 	set_buffer_size();
 	update_plugins(type);
 	set_options();
diff --git a/tracecmd/trace-usage.c b/tracecmd/trace-usage.c
index b5788f7..ddfb480 100644
--- a/tracecmd/trace-usage.c
+++ b/tracecmd/trace-usage.c
@@ -47,6 +47,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 change kernel saved_cmdlines_size\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"
-- 
2.7.4


  reply index

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-07 10:51 [PATCH 1/2] trace-cmd: Enable kptr_restrict vincent.donnefort
2019-11-07 10:51 ` vincent.donnefort [this message]
2019-11-11 22:52   ` [PATCH 2/2] trace-cmd: Add an option to set saved_cmdlines_size Steven Rostedt
2019-11-12 12:03     ` Vincent Donnefort
2019-11-12 14:40       ` Steven Rostedt
2019-11-12 19:01         ` Vincent Donnefort
2019-11-12 19:09           ` Steven Rostedt
2019-11-13 12:14             ` [PATCH v2 1/2] trace-cmd: Enable kptr_restrict vincent.donnefort
2019-11-13 12:14               ` [PATCH v2 2/2] trace-cmd: Add an option to set saved_cmdlines_size vincent.donnefort
2019-11-13 12:27             ` [PATCH " Vincent Donnefort
2019-11-13 15:08               ` Steven Rostedt
2019-11-12 12:03     ` [PATCH v2 1/2] trace-cmd: Enable kptr_restrict vincent.donnefort
2019-11-12 12:03       ` [PATCH v2 2/2] trace-cmd: Add an option to set saved_cmdlines_size vincent.donnefort
2019-11-11 22:47 ` [PATCH 1/2] trace-cmd: Enable kptr_restrict Steven Rostedt

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1573123866-348262-2-git-send-email-vincent.donnefort@arm.com \
    --to=vincent.donnefort@arm.com \
    --cc=linux-trace-devel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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