Skip to content

Commit

Permalink
tools/stackcount: Fix address resolution for user-space stack
Browse files Browse the repository at this point in the history
This patch fixes issue #2748. The bug was that address-to-symbol resolution
didn't work for user-space stacks without the `-P` (per-pid) flag when tracing
single, isolated processes. The current documentation of the `-P` option
indicates that it's used to "display stacks separately for each process",
and this doesn't match with the intended usage.

This patch has two parts:

 - Fix `tools/stackcount.py` to explicitly set perpid to True if `-p <pid>`
   is used
 - Remove the `-P` option from the example of tracing single, isolated process
   in `tools/stackcount_example.txt`, since the usage of the option can
   be confusing (and unnecessary after the current change)
  • Loading branch information
rohgarg authored and yonghong-song committed Feb 18, 2020
1 parent a28ad05 commit 9b6a0e3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
6 changes: 6 additions & 0 deletions tools/stackcount.py
Expand Up @@ -275,6 +275,12 @@ def __init__(self):
self.kernel_stack = self.args.kernel_stacks_only
self.user_stack = self.args.user_stacks_only

# For tracing single processes in isolation, explicitly set perpid
# to True, if not already set. This is required to generate the correct
# BPF program that can store pid in the tgid field of the key_t object.
if self.args.pid is not None and self.args.pid > 0:
self.args.perpid = True

self.probe = Probe(self.args.pattern,
self.kernel_stack, self.user_stack,
self.args.regexp, self.args.pid, self.args.perpid, self.args.cpu)
Expand Down
2 changes: 1 addition & 1 deletion tools/stackcount_example.txt
Expand Up @@ -487,7 +487,7 @@ User-space functions can also be traced if a library name is provided. For
example, to quickly identify code locations that allocate heap memory for
PID 4902 (using -p), by tracing malloc from libc ("c:malloc"):

# ./stackcount -P -p 4902 c:malloc
# ./stackcount -p 4902 c:malloc
Tracing 1 functions for "malloc"... Hit Ctrl-C to end.
^C
malloc
Expand Down

0 comments on commit 9b6a0e3

Please sign in to comment.