Skip to content

Commit

Permalink
Make number of stack traces configurable from command line in example… (
Browse files Browse the repository at this point in the history
iovisor#2500)

Make number of stack traces configurable from command line in examples/tracing/mallocstacks.py
  • Loading branch information
johnaohara authored and yonghong-song committed Aug 23, 2019
1 parent 6021958 commit 270d54a
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions examples/tracing/mallocstacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,26 @@
import sys

if len(sys.argv) < 2:
print("USAGE: mallocstacks PID")
print("USAGE: mallocstacks PID [NUM_STACKS=1024]")
exit()
pid = int(sys.argv[1])
if len(sys.argv) == 3:
try:
assert int(sys.argv[2]) > 0, ""
except (ValueError, AssertionError) as e:
print("USAGE: mallocstacks PID [NUM_STACKS=1024]")
print("NUM_STACKS must be a non-zero, positive integer")
exit()
stacks = sys.argv[2]
else:
stacks = "1024"

# load BPF program
b = BPF(text="""
#include <uapi/linux/ptrace.h>
BPF_HASH(calls, int);
BPF_STACK_TRACE(stack_traces, 1024);
BPF_STACK_TRACE(stack_traces, """ + stacks + """);
int alloc_enter(struct pt_regs *ctx, size_t size) {
int key = stack_traces.get_stackid(ctx,
Expand Down

0 comments on commit 270d54a

Please sign in to comment.