Messages in this thread | | | Date | Thu, 6 Nov 2008 22:51:07 +0300 | From | Alexey Dobriyan <> | Subject | Re: [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
| |