lkml.org 
[lkml]   [2008]   [Nov]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [patch] add /proc/pid/stack to dump task's stack trace
On Thu, Nov 06, 2008 at 11:01:39AM -0800, Ken Chen wrote:
> This patch adds the ability to query a task's stack trace via /proc/pid/stack.
> It is considered to be more useful than /proc/pid/wchan as it provides full
> stack trace instead of single depth.

Please, name handler proc_pid_stack following current convention.
And drop space before casts.

> --- a/fs/proc/base.c
> +++ b/fs/proc/base.c
> @@ -338,6 +339,35 @@ static int proc_pid_wchan
> else
> return sprintf(buffer, "%s", symname);
> }
> +
> +#define MAX_STACK_TRACE_DEPTH 32
> +static int proc_stack_trace(struct task_struct *task, char *buffer)
> +{
> + int i, len = 0;
> + unsigned long *entries;
> + struct stack_trace trace;
> +
> + entries = kmalloc(sizeof(*entries) * MAX_STACK_TRACE_DEPTH, GFP_KERNEL);
> + if (!entries)
> + goto out;
> +
> + trace.nr_entries = 0;
> + trace.max_entries = MAX_STACK_TRACE_DEPTH;
> + trace.entries = entries;
> + trace.skip = 0;
> +
> + read_lock(&tasklist_lock);
> + save_stack_trace_tsk(task, &trace);
> + read_unlock(&tasklist_lock);
> +
> + for (i = 0; i < trace.nr_entries; i++) {
> + len += sprintf(buffer + len, "[<%p>] %pS\n",
> + (void *) entries[i], (void *) entries[i]);
> + }
> + kfree(entries);
> +out:
> + return len;
> +}
> #endif /* CONFIG_KALLSYMS */
>
> #ifdef CONFIG_SCHEDSTATS
> @@ -2489,6 +2519,7 @@ static const struct pid_entry tgid_base_stuff[] = {
> DIR("attr", S_IRUGO|S_IXUGO, attr_dir),
> #endif
> #ifdef CONFIG_KALLSYMS
> + INF("stack", S_IRUSR, stack_trace),
> INF("wchan", S_IRUGO, pid_wchan),
> #endif
> #ifdef CONFIG_SCHEDSTATS


\
 
 \ /
  Last update: 2008-11-06 20:51    [W:0.077 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site