Skip to content

Commit f1d8983

Browse files
DLPX-88488 profile is missing stack traces (#16)
PR URL: https://www.github.com/delphix/bcc/pull/16
1 parent 7aa2829 commit f1d8983

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

tools/profile.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
# 15-Jul-2016 Brendan Gregg Created this.
2626
# 20-Oct-2016 " " Switched to use the new 4.9 support.
2727
# 26-Jan-2019 " " Changed to exclude CPU idle by default.
28+
# 11-Apr-2023 Rocky Xing Added option to increase hash storage size.
2829

2930
from __future__ import print_function
3031
from bcc import BPF, PerfType, PerfSWConfig
@@ -104,6 +105,9 @@ def stack_id_err(stack_id):
104105
help="include CPU idle stacks")
105106
parser.add_argument("-f", "--folded", action="store_true",
106107
help="output folded format, one line per stack (for flame graphs)")
108+
parser.add_argument("--hash-storage-size", default=40960,
109+
type=positive_nonzero_int,
110+
help="the number of hash keys that can be stored and (default %(default)s)")
107111
parser.add_argument("--stack-storage-size", default=16384,
108112
type=positive_nonzero_int,
109113
help="the number of unique stack traces that can be stored and "
@@ -146,7 +150,7 @@ def stack_id_err(stack_id):
146150
int kernel_stack_id;
147151
char name[TASK_COMM_LEN];
148152
};
149-
BPF_HASH(counts, struct key_t);
153+
BPF_HASH(counts, struct key_t, u64, HASH_STORAGE_SIZE);
150154
BPF_STACK_TRACE(stack_traces, STACK_STORAGE_SIZE);
151155
152156
// This code gets a bit complex. Probably not suitable for casual hacking.
@@ -226,6 +230,7 @@ def stack_id_err(stack_id):
226230
bpf_text = bpf_text.replace('THREAD_FILTER', thread_filter)
227231

228232
# set stack storage size
233+
bpf_text = bpf_text.replace('HASH_STORAGE_SIZE', str(args.hash_storage_size))
229234
bpf_text = bpf_text.replace('STACK_STORAGE_SIZE', str(args.stack_storage_size))
230235

231236
# handle stack args
@@ -306,6 +311,7 @@ def aksym(addr):
306311
missing_stacks = 0
307312
has_collision = False
308313
counts = b.get_table("counts")
314+
htab_full = args.hash_storage_size == len(counts)
309315
stack_traces = b.get_table("stack_traces")
310316
for k, v in sorted(counts.items(), key=lambda counts: counts[1].value):
311317
# handle get_stackid errors
@@ -376,3 +382,8 @@ def aksym(addr):
376382
print("WARNING: %d stack traces could not be displayed.%s" %
377383
(missing_stacks, enomem_str),
378384
file=stderr)
385+
386+
# check whether hash table is full
387+
if htab_full:
388+
print("WARNING: hash table full. Consider increasing --hash-storage-size.",
389+
file=stderr)

tools/profile_example.txt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,7 @@ USAGE message:
715715

716716
# ./profile -h
717717
usage: profile.py [-h] [-p PID | -L TID] [-U | -K] [-F FREQUENCY | -c COUNT]
718-
[-d] [-a] [-I] [-f]
718+
[-d] [-a] [-I] [-f] [--hash-storage-size HASH_STORAGE_SIZE]
719719
[--stack-storage-size STACK_STORAGE_SIZE] [-C CPU]
720720
[--cgroupmap CGROUPMAP] [--mntnsmap MNTNSMAP]
721721
[duration]
@@ -727,8 +727,10 @@ positional arguments:
727727

728728
optional arguments:
729729
-h, --help show this help message and exit
730-
-p PID, --pid PID profile process with this PID only
731-
-L TID, --tid TID profile thread with this TID only
730+
-p PID, --pid PID profile process with one or more comma separated PIDs
731+
only
732+
-L TID, --tid TID profile thread with one or more comma separated TIDs
733+
only
732734
-U, --user-stacks-only
733735
show stacks from user space only (no kernel space
734736
stacks)
@@ -744,6 +746,9 @@ optional arguments:
744746
-I, --include-idle include CPU idle stacks
745747
-f, --folded output folded format, one line per stack (for flame
746748
graphs)
749+
--hash-storage-size HASH_STORAGE_SIZE
750+
the number of hash keys that can be stored and
751+
(default 40960)
747752
--stack-storage-size STACK_STORAGE_SIZE
748753
the number of unique stack traces that can be stored
749754
and displayed (default 16384)

0 commit comments

Comments
 (0)