public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Avadh Patel <avadh4all@gmail.com>
Subject: [PATCH v2 4/5] tracing: add saved_cmdlines file to show cached task comms
Date: Fri, 17 Apr 2009 10:40:59 -0400	[thread overview]
Message-ID: <20090417144332.227759396@goodmis.org> (raw)
In-Reply-To: 20090417144055.857407604@goodmis.org

[-- Attachment #1: 0004-tracing-add-saved_cmdlines-file-to-show-cached-task.patch --]
[-- Type: text/plain, Size: 2329 bytes --]

From: Avadh Patel <avadh4all@gmail.com>

Export the cached task comms to userspace. This allows user apps to translate
the pids from a trace into their respective task command lines.

[ added error checking and use of buf pointer to index file_buf
    - Steven Rostedt ]

Impact: let userspace apps reading binary buffer know comm's of pids
Signed-off-by: Avadh Patel <avadh4all@gmail.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace.c |   53 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 2d69b26..031c46f 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2422,6 +2422,56 @@ static const struct file_operations tracing_readme_fops = {
 };
 
 static ssize_t
+tracing_saved_cmdlines_read(struct file *file, char __user *ubuf,
+				size_t cnt, loff_t *ppos)
+{
+	char *buf_comm;
+	char *file_buf;
+	char *buf;
+	int len = 0;
+	int pid;
+	int i;
+
+	file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL);
+	if (!file_buf)
+		return -ENOMEM;
+
+	buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL);
+	if (!buf_comm) {
+		kfree(file_buf);
+		return -ENOMEM;
+	}
+
+	buf = file_buf;
+
+	for (i = 0; i < SAVED_CMDLINES; i++) {
+		int r;
+
+		pid = map_cmdline_to_pid[i];
+		if (pid == -1 || pid == NO_CMDLINE_MAP)
+			continue;
+
+		trace_find_cmdline(pid, buf_comm);
+		r = sprintf(buf, "%d %s\n", pid, buf_comm);
+		buf += r;
+		len += r;
+	}
+
+	len = simple_read_from_buffer(ubuf, cnt, ppos,
+				      file_buf, len);
+
+	kfree(file_buf);
+	kfree(buf_comm);
+
+	return len;
+}
+
+static const struct file_operations tracing_saved_cmdlines_fops = {
+    .open       = tracing_open_generic,
+    .read       = tracing_saved_cmdlines_read,
+};
+
+static ssize_t
 tracing_ctrl_read(struct file *filp, char __user *ubuf,
 		  size_t cnt, loff_t *ppos)
 {
@@ -3973,6 +4023,9 @@ static __init int tracer_init_debugfs(void)
 	trace_create_file("trace_marker", 0220, d_tracer,
 			NULL, &tracing_mark_fops);
 
+	trace_create_file("saved_cmdlines", 0444, d_tracer,
+			NULL, &tracing_saved_cmdlines_fops);
+
 #ifdef CONFIG_DYNAMIC_FTRACE
 	trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
 			&ftrace_update_tot_cnt, &tracing_dyn_info_fops);
-- 
1.6.2.1

-- 

  parent reply	other threads:[~2009-04-17 14:45 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-04-17 14:40 [PATCH v2 0/5] [GIT PULL] ftrace,tracing/events rebase updates Steven Rostedt
2009-04-17 14:40 ` [PATCH v2 1/5] ftrace: use module notifier for function tracer Steven Rostedt
2009-04-17 14:40 ` [PATCH v2 2/5] tracing/events: add startup tests for events Steven Rostedt
2009-04-17 14:40 ` [PATCH v2 3/5] tracing/events/ring-buffer: expose format of ring buffer headers to users Steven Rostedt
2009-04-17 14:40 ` Steven Rostedt [this message]
2009-04-17 14:41 ` [PATCH v2 5/5] tracing/events: perform function tracing in event selftests Steven Rostedt
2009-04-17 15:11 ` [PATCH v2 0/5] [GIT PULL] ftrace,tracing/events rebase updates Ingo Molnar
2009-04-17 15:13   ` Ingo Molnar
2009-04-28 11:12     ` BUG: Function graph tracer hang Ingo Molnar
2009-04-28 20:32       ` Frederic Weisbecker
2009-04-28 20:47         ` Steven Rostedt
2009-04-29 10:40           ` Ingo Molnar
2009-04-29 12:24             ` Steven Rostedt
2009-05-03  9:02               ` Ingo Molnar

Reply instructions:

You may reply publicly 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=20090417144332.227759396@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=akpm@linux-foundation.org \
    --cc=avadh4all@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox