Messages in this thread Patch in this message | | | Date | Fri, 7 Nov 2008 10:38:04 -0800 | Subject | Re: [patch] add /proc/pid/stack to dump task's stack trace | From | Ken Chen <> |
| |
On Fri, Nov 7, 2008 at 12:32 AM, Ingo Molnar <mingo@elte.hu> wrote: > oh well - Ken, could you please switch it to seqfiles?
On Fri, Nov 7, 2008 at 12:49 AM, Alexey Dobriyan wrote: > Or you can do all of this in ->show(), without start/next/stop: > > for (i = 0; i < N; i++) > seq_printf(m, "[<%p>] %pS\n", x, x);
Here is a patch convert to seq_file using proc_single_show() helper. I don't see it to be any superior than what was before using snprintf(). seq_read also allocate one page for printf buffer, so functionally it is the same (perhaps a little bit better because it can use the whole page, compare to PROC_BLOCK_SIZE currently). Ingo, it's your call whether to merge this patch or not.
I also agree that using full blown seqfile start/show/stop won't add value because most valuable stack at the top are already printed.
Signed-off-by: Ken Chen <kenchen@google.com>
diff --git a/fs/proc/base.c b/fs/proc/base.c index 805e514..6d294a4 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -351,11 +351,12 @@ static int proc_pid_wchan
#define MAX_STACK_TRACE_DEPTH 64
-static int proc_pid_stack(struct task_struct *task, char *buffer) +static int proc_pid_stack(struct seq_file *m, struct pid_namespace *ns, + struct pid *pid, struct task_struct *task) { struct stack_trace trace; unsigned long *entries; - int i, len = 0; + int i;
entries = kmalloc(sizeof(*entries)*MAX_STACK_TRACE_DEPTH, GFP_KERNEL); if (!entries) @@ -375,15 +376,12 @@ static int proc_pid_stack read_unlock(&tasklist_lock);
for (i = 0; i < trace.nr_entries; i++) { - len += snprintf(buffer + len, PROC_BLOCK_SIZE - len, - "[<%p>] %pS\n", - (void *)entries[i], (void *)entries[i]); - if (!len) - break; + seq_printf(m, "[<%p>] %pS\n", + (void *)entries[i], (void *)entries[i]); } kfree(entries);
- return len; + return 0; } #endif
@@ -2537,7 +2535,7 @@ static const struct pid_entry tgid_base_stuff[] INF("wchan", S_IRUGO, pid_wchan), #endif #ifdef CONFIG_STACKTRACE - INF("stack", S_IRUSR, pid_stack), + ONE("stack", S_IRUSR, pid_stack), #endif #ifdef CONFIG_SCHEDSTATS INF("schedstat", S_IRUGO, pid_schedstat),
| |