aboutsummaryrefslogtreecommitdiffstats
path: root/kernel/trace
diff options
context:
space:
mode:
authorAvadh Patel <avadh4all@gmail.com>2009-04-10 16:04:48 -0400
committerIngo Molnar <mingo@elte.hu>2009-04-17 11:04:12 -0400
commit69abe6a5d18a9394baa325bab8f57748b037c517 (patch)
tree4432c60f73d14af510ab13b9b474e174fd2454c5 /kernel/trace
parentd1b182a8d49ed6416325b4e0a1cb0f17cd4e702a (diff)
tracing: add saved_cmdlines file to show cached task comms
Export the cached task comms to userspace. This allows user apps to translate the pids from a trace into their respective task command lines. [ Impact: let userspace apps reading binary buffer know comm's of pids ] Signed-off-by: Avadh Patel <avadh4all@gmail.com> [ added error checking and use of buf pointer to index file_buf ] Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'kernel/trace')
-rw-r--r--kernel/trace/trace.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
index 2d69b26b3cc9..031c46f11bb9 100644
--- a/kernel/trace/trace.c
+++ b/kernel/trace/trace.c
@@ -2422,6 +2422,56 @@ static const struct file_operations tracing_readme_fops = {
2422}; 2422};
2423 2423
2424static ssize_t 2424static ssize_t
2425tracing_saved_cmdlines_read(struct file *file, char __user *ubuf,
2426 size_t cnt, loff_t *ppos)
2427{
2428 char *buf_comm;
2429 char *file_buf;
2430 char *buf;
2431 int len = 0;
2432 int pid;
2433 int i;
2434
2435 file_buf = kmalloc(SAVED_CMDLINES*(16+TASK_COMM_LEN), GFP_KERNEL);
2436 if (!file_buf)
2437 return -ENOMEM;
2438
2439 buf_comm = kmalloc(TASK_COMM_LEN, GFP_KERNEL);
2440 if (!buf_comm) {
2441 kfree(file_buf);
2442 return -ENOMEM;
2443 }
2444
2445 buf = file_buf;
2446
2447 for (i = 0; i < SAVED_CMDLINES; i++) {
2448 int r;
2449
2450 pid = map_cmdline_to_pid[i];
2451 if (pid == -1 || pid == NO_CMDLINE_MAP)
2452 continue;
2453
2454 trace_find_cmdline(pid, buf_comm);
2455 r = sprintf(buf, "%d %s\n", pid, buf_comm);
2456 buf += r;
2457 len += r;
2458 }
2459
2460 len = simple_read_from_buffer(ubuf, cnt, ppos,
2461 file_buf, len);
2462
2463 kfree(file_buf);
2464 kfree(buf_comm);
2465
2466 return len;
2467}
2468
2469static const struct file_operations tracing_saved_cmdlines_fops = {
2470 .open = tracing_open_generic,
2471 .read = tracing_saved_cmdlines_read,
2472};
2473
2474static ssize_t
2425tracing_ctrl_read(struct file *filp, char __user *ubuf, 2475tracing_ctrl_read(struct file *filp, char __user *ubuf,
2426 size_t cnt, loff_t *ppos) 2476 size_t cnt, loff_t *ppos)
2427{ 2477{
@@ -3973,6 +4023,9 @@ static __init int tracer_init_debugfs(void)
3973 trace_create_file("trace_marker", 0220, d_tracer, 4023 trace_create_file("trace_marker", 0220, d_tracer,
3974 NULL, &tracing_mark_fops); 4024 NULL, &tracing_mark_fops);
3975 4025
4026 trace_create_file("saved_cmdlines", 0444, d_tracer,
4027 NULL, &tracing_saved_cmdlines_fops);
4028
3976#ifdef CONFIG_DYNAMIC_FTRACE 4029#ifdef CONFIG_DYNAMIC_FTRACE
3977 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer, 4030 trace_create_file("dyn_ftrace_total_info", 0444, d_tracer,
3978 &ftrace_update_tot_cnt, &tracing_dyn_info_fops); 4031 &ftrace_update_tot_cnt, &tracing_dyn_info_fops);