|
25 | 25 | # 15-Jul-2016 Brendan Gregg Created this. |
26 | 26 | # 20-Oct-2016 " " Switched to use the new 4.9 support. |
27 | 27 | # 26-Jan-2019 " " Changed to exclude CPU idle by default. |
| 28 | +# 11-Apr-2023 Rocky Xing Added option to increase hash storage size. |
28 | 29 |
|
29 | 30 | from __future__ import print_function |
30 | 31 | from bcc import BPF, PerfType, PerfSWConfig |
@@ -104,6 +105,9 @@ def stack_id_err(stack_id): |
104 | 105 | help="include CPU idle stacks") |
105 | 106 | parser.add_argument("-f", "--folded", action="store_true", |
106 | 107 | 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)") |
107 | 111 | parser.add_argument("--stack-storage-size", default=16384, |
108 | 112 | type=positive_nonzero_int, |
109 | 113 | help="the number of unique stack traces that can be stored and " |
@@ -146,7 +150,7 @@ def stack_id_err(stack_id): |
146 | 150 | int kernel_stack_id; |
147 | 151 | char name[TASK_COMM_LEN]; |
148 | 152 | }; |
149 | | -BPF_HASH(counts, struct key_t); |
| 153 | +BPF_HASH(counts, struct key_t, u64, HASH_STORAGE_SIZE); |
150 | 154 | BPF_STACK_TRACE(stack_traces, STACK_STORAGE_SIZE); |
151 | 155 |
|
152 | 156 | // This code gets a bit complex. Probably not suitable for casual hacking. |
@@ -226,6 +230,7 @@ def stack_id_err(stack_id): |
226 | 230 | bpf_text = bpf_text.replace('THREAD_FILTER', thread_filter) |
227 | 231 |
|
228 | 232 | # set stack storage size |
| 233 | +bpf_text = bpf_text.replace('HASH_STORAGE_SIZE', str(args.hash_storage_size)) |
229 | 234 | bpf_text = bpf_text.replace('STACK_STORAGE_SIZE', str(args.stack_storage_size)) |
230 | 235 |
|
231 | 236 | # handle stack args |
@@ -306,6 +311,7 @@ def aksym(addr): |
306 | 311 | missing_stacks = 0 |
307 | 312 | has_collision = False |
308 | 313 | counts = b.get_table("counts") |
| 314 | +htab_full = args.hash_storage_size == len(counts) |
309 | 315 | stack_traces = b.get_table("stack_traces") |
310 | 316 | for k, v in sorted(counts.items(), key=lambda counts: counts[1].value): |
311 | 317 | # handle get_stackid errors |
@@ -376,3 +382,8 @@ def aksym(addr): |
376 | 382 | print("WARNING: %d stack traces could not be displayed.%s" % |
377 | 383 | (missing_stacks, enomem_str), |
378 | 384 | 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) |
0 commit comments