blob: 88dc68c1505d41a6a8a2a4cd240c67735c778cc3 [file] [log] [blame]
Alexey Ivanovcc01a9c2019-01-16 09:50:46 -08001#!/usr/bin/python
Brendan Greggaf2b46a2016-01-30 11:02:29 -08002#
3# offwaketime Summarize blocked time by kernel off-CPU stack + waker stack
4# For Linux, uses BCC, eBPF.
5#
ceeaspb47cecb62016-11-26 22:36:10 +00006# USAGE: offwaketime [-h] [-p PID | -u | -k] [-U | -K] [-f] [duration]
Brendan Greggaf2b46a2016-01-30 11:02:29 -08007#
8# Copyright 2016 Netflix, Inc.
9# Licensed under the Apache License, Version 2.0 (the "License")
10#
Alexei Starovoitov7583a4e2016-02-03 21:25:43 -080011# 20-Jan-2016 Brendan Gregg Created this.
Brendan Greggaf2b46a2016-01-30 11:02:29 -080012
13from __future__ import print_function
14from bcc import BPF
Alexei Starovoitov7583a4e2016-02-03 21:25:43 -080015from time import sleep
Brendan Greggaf2b46a2016-01-30 11:02:29 -080016import argparse
17import signal
ceeaspb47cecb62016-11-26 22:36:10 +000018import errno
19from sys import stderr
20
21# arg validation
22def positive_int(val):
23 try:
24 ival = int(val)
25 except ValueError:
26 raise argparse.ArgumentTypeError("must be an integer")
27
28 if ival < 0:
29 raise argparse.ArgumentTypeError("must be positive")
30 return ival
31
32def positive_nonzero_int(val):
33 ival = positive_int(val)
34 if ival == 0:
35 raise argparse.ArgumentTypeError("must be nonzero")
36 return ival
Brendan Greggaf2b46a2016-01-30 11:02:29 -080037
Teng Qine778db02018-04-24 16:11:49 -070038def stack_id_err(stack_id):
Michael Prokopc14d02a2020-01-09 02:29:18 +010039 # -EFAULT in get_stackid normally means the stack-trace is not available,
Teng Qine778db02018-04-24 16:11:49 -070040 # Such as getting kernel stack trace in userspace code
41 return (stack_id < 0) and (stack_id != -errno.EFAULT)
42
Brendan Greggaf2b46a2016-01-30 11:02:29 -080043# arguments
44examples = """examples:
45 ./offwaketime # trace off-CPU + waker stack time until Ctrl-C
46 ./offwaketime 5 # trace for 5 seconds only
47 ./offwaketime -f 5 # 5 seconds, and output in folded format
ceeaspb47cecb62016-11-26 22:36:10 +000048 ./offwaketime -m 1000 # trace only events that last more than 1000 usec
49 ./offwaketime -M 9000 # trace only events that last less than 9000 usec
50 ./offwaketime -p 185 # only trace threads for PID 185
51 ./offwaketime -t 188 # only trace thread 188
52 ./offwaketime -u # only trace user threads (no kernel)
53 ./offwaketime -k # only trace kernel threads (no user)
54 ./offwaketime -U # only show user space stacks (no kernel)
55 ./offwaketime -K # only show kernel space stacks (no user)
Brendan Greggaf2b46a2016-01-30 11:02:29 -080056"""
57parser = argparse.ArgumentParser(
58 description="Summarize blocked time by kernel stack trace + waker stack",
59 formatter_class=argparse.RawDescriptionHelpFormatter,
60 epilog=examples)
ceeaspb47cecb62016-11-26 22:36:10 +000061thread_group = parser.add_mutually_exclusive_group()
62# Note: this script provides --pid and --tid flags but their arguments are
63# referred to internally using kernel nomenclature: TGID and PID.
64thread_group.add_argument("-p", "--pid", metavar="PID", dest="tgid",
65 help="trace this PID only", type=positive_int)
66thread_group.add_argument("-t", "--tid", metavar="TID", dest="pid",
67 help="trace this TID only", type=positive_int)
68thread_group.add_argument("-u", "--user-threads-only", action="store_true",
Brendan Greggaf2b46a2016-01-30 11:02:29 -080069 help="user threads only (no kernel threads)")
ceeaspb47cecb62016-11-26 22:36:10 +000070thread_group.add_argument("-k", "--kernel-threads-only", action="store_true",
71 help="kernel threads only (no user threads)")
72stack_group = parser.add_mutually_exclusive_group()
73stack_group.add_argument("-U", "--user-stacks-only", action="store_true",
74 help="show stacks from user space only (no kernel space stacks)")
75stack_group.add_argument("-K", "--kernel-stacks-only", action="store_true",
76 help="show stacks from kernel space only (no user space stacks)")
77parser.add_argument("-d", "--delimited", action="store_true",
78 help="insert delimiter between kernel/user stacks")
Brendan Greggaf2b46a2016-01-30 11:02:29 -080079parser.add_argument("-f", "--folded", action="store_true",
80 help="output folded format")
ceeaspb47cecb62016-11-26 22:36:10 +000081parser.add_argument("--stack-storage-size", default=1024,
82 type=positive_nonzero_int,
83 help="the number of unique stack traces that can be stored and "
84 "displayed (default 1024)")
Brendan Greggaf2b46a2016-01-30 11:02:29 -080085parser.add_argument("duration", nargs="?", default=99999999,
ceeaspb47cecb62016-11-26 22:36:10 +000086 type=positive_nonzero_int,
Brendan Greggaf2b46a2016-01-30 11:02:29 -080087 help="duration of trace, in seconds")
ceeaspb47cecb62016-11-26 22:36:10 +000088parser.add_argument("-m", "--min-block-time", default=1,
89 type=positive_nonzero_int,
90 help="the amount of time in microseconds over which we " +
91 "store traces (default 1)")
92parser.add_argument("-M", "--max-block-time", default=(1 << 64) - 1,
93 type=positive_nonzero_int,
94 help="the amount of time in microseconds under which we " +
95 "store traces (default U64_MAX)")
lorddoskiasb20f5e72020-05-30 19:17:33 +030096parser.add_argument("--state", type=positive_int,
97 help="filter on this thread state bitmask (eg, 2 == TASK_UNINTERRUPTIBLE" +
98 ") see include/linux/sched.h")
Nathan Scottcf0792f2018-02-02 16:56:50 +110099parser.add_argument("--ebpf", action="store_true",
100 help=argparse.SUPPRESS)
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800101args = parser.parse_args()
102folded = args.folded
103duration = int(args.duration)
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800104
105# signal handler
106def signal_ignore(signal, frame):
107 print()
108
109# define BPF program
110bpf_text = """
111#include <uapi/linux/ptrace.h>
112#include <linux/sched.h>
113
ceeaspb47cecb62016-11-26 22:36:10 +0000114#define MINBLOCK_US MINBLOCK_US_VALUEULL
115#define MAXBLOCK_US MAXBLOCK_US_VALUEULL
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800116
117struct key_t {
118 char waker[TASK_COMM_LEN];
119 char target[TASK_COMM_LEN];
ceeaspb47cecb62016-11-26 22:36:10 +0000120 int w_k_stack_id;
121 int w_u_stack_id;
122 int t_k_stack_id;
123 int t_u_stack_id;
124 u32 t_pid;
Teng Qine7432d42018-04-19 14:45:18 -0700125 u32 t_tgid;
ceeaspb47cecb62016-11-26 22:36:10 +0000126 u32 w_pid;
Teng Qine7432d42018-04-19 14:45:18 -0700127 u32 w_tgid;
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800128};
129BPF_HASH(counts, struct key_t);
Teng Qine7432d42018-04-19 14:45:18 -0700130
131// Key of this hash is PID of waiting Process,
132// value is timestamp when it went into waiting
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800133BPF_HASH(start, u32);
Teng Qine7432d42018-04-19 14:45:18 -0700134
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800135struct wokeby_t {
136 char name[TASK_COMM_LEN];
ceeaspb47cecb62016-11-26 22:36:10 +0000137 int k_stack_id;
138 int u_stack_id;
139 int w_pid;
Teng Qine7432d42018-04-19 14:45:18 -0700140 int w_tgid;
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800141};
Teng Qine7432d42018-04-19 14:45:18 -0700142// Key of the hash is PID of the Process to be waken, value is information
143// of the Process who wakes it
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800144BPF_HASH(wokeby, u32, struct wokeby_t);
145
Vladislav Bogdanov0a7da742020-02-07 15:22:42 +0300146BPF_STACK_TRACE(stack_traces, STACK_STORAGE_SIZE);
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800147
148int waker(struct pt_regs *ctx, struct task_struct *p) {
Teng Qine7432d42018-04-19 14:45:18 -0700149 // PID and TGID of the target Process to be waken
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800150 u32 pid = p->pid;
ceeaspb47cecb62016-11-26 22:36:10 +0000151 u32 tgid = p->tgid;
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800152
lorddoskiasb20f5e72020-05-30 19:17:33 +0300153 if (!((THREAD_FILTER) && (STATE_FILTER))) {
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800154 return 0;
ceeaspb47cecb62016-11-26 22:36:10 +0000155 }
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800156
Teng Qine7432d42018-04-19 14:45:18 -0700157 // Construct information about current (the waker) Process
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800158 struct wokeby_t woke = {};
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800159 bpf_get_current_comm(&woke.name, sizeof(woke.name));
ceeaspb47cecb62016-11-26 22:36:10 +0000160 woke.k_stack_id = KERNEL_STACK_GET;
161 woke.u_stack_id = USER_STACK_GET;
Teng Qine7432d42018-04-19 14:45:18 -0700162 woke.w_pid = bpf_get_current_pid_tgid();
163 woke.w_tgid = bpf_get_current_pid_tgid() >> 32;
164
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800165 wokeby.update(&pid, &woke);
166 return 0;
167}
168
169int oncpu(struct pt_regs *ctx, struct task_struct *p) {
Teng Qine7432d42018-04-19 14:45:18 -0700170 // PID and TGID of the previous Process (Process going into waiting)
171 u32 pid = p->pid;
ceeaspb47cecb62016-11-26 22:36:10 +0000172 u32 tgid = p->tgid;
Teng Qine7432d42018-04-19 14:45:18 -0700173 u64 *tsp;
174 u64 ts = bpf_ktime_get_ns();
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800175
Teng Qine7432d42018-04-19 14:45:18 -0700176 // Record timestamp for the previous Process (Process going into waiting)
lorddoskiasb20f5e72020-05-30 19:17:33 +0300177 if ((THREAD_FILTER) && (STATE_FILTER)) {
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800178 start.update(&pid, &ts);
179 }
180
Teng Qine7432d42018-04-19 14:45:18 -0700181 // Calculate current Process's wait time by finding the timestamp of when
182 // it went into waiting.
183 // pid and tgid are now the PID and TGID of the current (waking) Process.
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800184 pid = bpf_get_current_pid_tgid();
ceeaspb47cecb62016-11-26 22:36:10 +0000185 tgid = bpf_get_current_pid_tgid() >> 32;
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800186 tsp = start.lookup(&pid);
ceeaspb47cecb62016-11-26 22:36:10 +0000187 if (tsp == 0) {
Teng Qine7432d42018-04-19 14:45:18 -0700188 // Missed or filtered when the Process went into waiting
189 return 0;
ceeaspb47cecb62016-11-26 22:36:10 +0000190 }
Teng Qine7432d42018-04-19 14:45:18 -0700191 u64 delta = ts - *tsp;
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800192 start.delete(&pid);
193 delta = delta / 1000;
ceeaspb47cecb62016-11-26 22:36:10 +0000194 if ((delta < MINBLOCK_US) || (delta > MAXBLOCK_US)) {
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800195 return 0;
ceeaspb47cecb62016-11-26 22:36:10 +0000196 }
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800197
198 // create map key
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800199 struct key_t key = {};
200 struct wokeby_t *woke;
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800201
Teng Qine7432d42018-04-19 14:45:18 -0700202 bpf_get_current_comm(&key.target, sizeof(key.target));
203 key.t_pid = pid;
204 key.t_tgid = tgid;
ceeaspb47cecb62016-11-26 22:36:10 +0000205 key.t_k_stack_id = KERNEL_STACK_GET;
206 key.t_u_stack_id = USER_STACK_GET;
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800207
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800208 woke = wokeby.lookup(&pid);
209 if (woke) {
ceeaspb47cecb62016-11-26 22:36:10 +0000210 key.w_k_stack_id = woke->k_stack_id;
211 key.w_u_stack_id = woke->u_stack_id;
212 key.w_pid = woke->w_pid;
Teng Qine7432d42018-04-19 14:45:18 -0700213 key.w_tgid = woke->w_tgid;
Alexei Starovoitov7583a4e2016-02-03 21:25:43 -0800214 __builtin_memcpy(&key.waker, woke->name, TASK_COMM_LEN);
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800215 wokeby.delete(&pid);
216 }
217
Javier Honduvilla Coto64bf9652018-08-01 06:50:19 +0200218 counts.increment(key, delta);
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800219 return 0;
220}
221"""
ceeaspb47cecb62016-11-26 22:36:10 +0000222
223# set thread filter
224thread_context = ""
225if args.tgid is not None:
226 thread_context = "PID %d" % args.tgid
227 thread_filter = 'tgid == %d' % args.tgid
228elif args.pid is not None:
229 thread_context = "TID %d" % args.pid
230 thread_filter = 'pid == %d' % args.pid
231elif args.user_threads_only:
232 thread_context = "user threads"
233 thread_filter = '!(p->flags & PF_KTHREAD)'
234elif args.kernel_threads_only:
235 thread_context = "kernel threads"
236 thread_filter = 'p->flags & PF_KTHREAD'
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800237else:
ceeaspb47cecb62016-11-26 22:36:10 +0000238 thread_context = "all threads"
239 thread_filter = '1'
lorddoskiasb20f5e72020-05-30 19:17:33 +0300240if args.state == 0:
241 state_filter = 'p->state == 0'
242elif args.state:
243 # these states are sometimes bitmask checked
244 state_filter = 'p->state & %d' % args.state
245else:
246 state_filter = '1'
ceeaspb47cecb62016-11-26 22:36:10 +0000247bpf_text = bpf_text.replace('THREAD_FILTER', thread_filter)
lorddoskiasb20f5e72020-05-30 19:17:33 +0300248bpf_text = bpf_text.replace('STATE_FILTER', state_filter)
ceeaspb47cecb62016-11-26 22:36:10 +0000249
250# set stack storage size
251bpf_text = bpf_text.replace('STACK_STORAGE_SIZE', str(args.stack_storage_size))
252bpf_text = bpf_text.replace('MINBLOCK_US_VALUE', str(args.min_block_time))
253bpf_text = bpf_text.replace('MAXBLOCK_US_VALUE', str(args.max_block_time))
254
255# handle stack args
Teng Qine778db02018-04-24 16:11:49 -0700256kernel_stack_get = "stack_traces.get_stackid(ctx, 0)"
257user_stack_get = "stack_traces.get_stackid(ctx, BPF_F_USER_STACK)"
ceeaspb47cecb62016-11-26 22:36:10 +0000258stack_context = ""
259if args.user_stacks_only:
260 stack_context = "user"
261 kernel_stack_get = "-1"
262elif args.kernel_stacks_only:
263 stack_context = "kernel"
264 user_stack_get = "-1"
265else:
266 stack_context = "user + kernel"
267bpf_text = bpf_text.replace('USER_STACK_GET', user_stack_get)
268bpf_text = bpf_text.replace('KERNEL_STACK_GET', kernel_stack_get)
Nathan Scottcf0792f2018-02-02 16:56:50 +1100269if args.ebpf:
270 print(bpf_text)
271 exit()
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800272
273# initialize BPF
274b = BPF(text=bpf_text)
275b.attach_kprobe(event="finish_task_switch", fn_name="oncpu")
276b.attach_kprobe(event="try_to_wake_up", fn_name="waker")
277matched = b.num_open_kprobes()
278if matched == 0:
279 print("0 functions traced. Exiting.")
280 exit()
281
282# header
283if not folded:
ceeaspb47cecb62016-11-26 22:36:10 +0000284 print("Tracing blocked time (us) by %s off-CPU and waker stack" %
285 stack_context, end="")
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800286 if duration < 99999999:
287 print(" for %d secs." % duration)
288 else:
289 print("... Hit Ctrl-C to end.")
290
jeromemarchand09f9d3c2018-10-13 01:01:22 +0200291try:
292 sleep(duration)
293except KeyboardInterrupt:
294 # as cleanup can take many seconds, trap Ctrl-C:
295 # print a newline for folded output on Ctrl-C
296 signal.signal(signal.SIGINT, signal_ignore)
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800297
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800298
ceeaspb47cecb62016-11-26 22:36:10 +0000299if not folded:
300 print()
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800301
ceeaspb47cecb62016-11-26 22:36:10 +0000302missing_stacks = 0
303has_enomem = False
304counts = b.get_table("counts")
305stack_traces = b.get_table("stack_traces")
Teng Qine778db02018-04-24 16:11:49 -0700306need_delimiter = args.delimited and not (args.kernel_stacks_only or
307 args.user_stacks_only)
ceeaspb47cecb62016-11-26 22:36:10 +0000308for k, v in sorted(counts.items(), key=lambda counts: counts[1].value):
309 # handle get_stackid errors
Teng Qine778db02018-04-24 16:11:49 -0700310 if not args.user_stacks_only:
311 missing_stacks += int(stack_id_err(k.w_k_stack_id))
312 missing_stacks += int(stack_id_err(k.t_k_stack_id))
313 has_enomem = has_enomem or (k.w_k_stack_id == -errno.ENOMEM) or \
314 (k.t_k_stack_id == -errno.ENOMEM)
315 if not args.kernel_stacks_only:
316 missing_stacks += int(stack_id_err(k.w_u_stack_id))
317 missing_stacks += int(stack_id_err(k.t_u_stack_id))
318 has_enomem = has_enomem or (k.w_u_stack_id == -errno.ENOMEM) or \
319 (k.t_u_stack_id == -errno.ENOMEM)
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800320
ceeaspb47cecb62016-11-26 22:36:10 +0000321 waker_user_stack = [] if k.w_u_stack_id < 1 else \
322 reversed(list(stack_traces.walk(k.w_u_stack_id))[1:])
323 waker_kernel_stack = [] if k.w_k_stack_id < 1 else \
324 reversed(list(stack_traces.walk(k.w_k_stack_id))[1:])
325 target_user_stack = [] if k.t_u_stack_id < 1 else \
326 stack_traces.walk(k.t_u_stack_id)
327 target_kernel_stack = [] if k.t_k_stack_id < 1 else \
328 stack_traces.walk(k.t_k_stack_id)
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800329
ceeaspb47cecb62016-11-26 22:36:10 +0000330 if folded:
331 # print folded stack output
jeromemarchandb96ebcd2018-10-10 01:58:15 +0200332 line = [k.target.decode('utf-8', 'replace')]
Teng Qine778db02018-04-24 16:11:49 -0700333 if not args.kernel_stacks_only:
334 if stack_id_err(k.t_u_stack_id):
Jiri Olsaac00ac52019-11-15 12:45:59 +0100335 line.append("[Missed User Stack] %d" % k.t_u_stack_id)
Teng Qine778db02018-04-24 16:11:49 -0700336 else:
Jerome Marchandf03beca2019-02-15 17:35:37 +0100337 line.extend([b.sym(addr, k.t_tgid).decode('utf-8', 'replace')
Teng Qine778db02018-04-24 16:11:49 -0700338 for addr in reversed(list(target_user_stack)[1:])])
339 if not args.user_stacks_only:
340 line.extend(["-"] if (need_delimiter and k.t_k_stack_id > 0 and k.t_u_stack_id > 0) else [])
341 if stack_id_err(k.t_k_stack_id):
342 line.append("[Missed Kernel Stack]")
343 else:
Jerome Marchandf03beca2019-02-15 17:35:37 +0100344 line.extend([b.ksym(addr).decode('utf-8', 'replace')
Teng Qine778db02018-04-24 16:11:49 -0700345 for addr in reversed(list(target_kernel_stack)[1:])])
346 line.append("--")
347 if not args.user_stacks_only:
348 if stack_id_err(k.w_k_stack_id):
349 line.append("[Missed Kernel Stack]")
350 else:
Jerome Marchandf03beca2019-02-15 17:35:37 +0100351 line.extend([b.ksym(addr).decode('utf-8', 'replace')
Teng Qine778db02018-04-24 16:11:49 -0700352 for addr in reversed(list(waker_kernel_stack))])
353 if not args.kernel_stacks_only:
354 line.extend(["-"] if (need_delimiter and k.w_u_stack_id > 0 and k.w_k_stack_id > 0) else [])
355 if stack_id_err(k.w_u_stack_id):
Andrea Righi7813f8e2018-11-20 17:54:46 +0100356 line.append("[Missed User Stack]")
Teng Qine778db02018-04-24 16:11:49 -0700357 else:
Jerome Marchandf03beca2019-02-15 17:35:37 +0100358 line.extend([b.sym(addr, k.w_tgid).decode('utf-8', 'replace')
Teng Qine778db02018-04-24 16:11:49 -0700359 for addr in reversed(list(waker_user_stack))])
jeromemarchandb96ebcd2018-10-10 01:58:15 +0200360 line.append(k.waker.decode('utf-8', 'replace'))
ceeaspb47cecb62016-11-26 22:36:10 +0000361 print("%s %d" % (";".join(line), v.value))
ceeaspb47cecb62016-11-26 22:36:10 +0000362 else:
363 # print wakeup name then stack in reverse order
Yohei Ueda89bb40a2019-08-09 14:12:21 +0900364 print(" %-16s %s %s" % ("waker:", k.waker.decode('utf-8', 'replace'), k.w_pid))
Teng Qine778db02018-04-24 16:11:49 -0700365 if not args.kernel_stacks_only:
366 if stack_id_err(k.w_u_stack_id):
Jiri Olsaac00ac52019-11-15 12:45:59 +0100367 print(" [Missed User Stack] %d" % k.w_u_stack_id)
Teng Qine778db02018-04-24 16:11:49 -0700368 else:
369 for addr in waker_user_stack:
370 print(" %s" % b.sym(addr, k.w_tgid))
371 if not args.user_stacks_only:
372 if need_delimiter and k.w_u_stack_id > 0 and k.w_k_stack_id > 0:
373 print(" -")
374 if stack_id_err(k.w_k_stack_id):
375 print(" [Missed Kernel Stack]")
376 else:
377 for addr in waker_kernel_stack:
378 print(" %s" % b.ksym(addr))
Brendan Greggaf2b46a2016-01-30 11:02:29 -0800379
ceeaspb47cecb62016-11-26 22:36:10 +0000380 # print waker/wakee delimiter
381 print(" %-16s %s" % ("--", "--"))
Javier Honduvilla Coto64bf9652018-08-01 06:50:19 +0200382
Teng Qine778db02018-04-24 16:11:49 -0700383 if not args.user_stacks_only:
384 if stack_id_err(k.t_k_stack_id):
385 print(" [Missed Kernel Stack]")
386 else:
387 for addr in target_kernel_stack:
388 print(" %s" % b.ksym(addr))
389 if not args.kernel_stacks_only:
390 if need_delimiter and k.t_u_stack_id > 0 and k.t_k_stack_id > 0:
391 print(" -")
392 if stack_id_err(k.t_u_stack_id):
393 print(" [Missed User Stack]")
394 else:
395 for addr in target_user_stack:
396 print(" %s" % b.sym(addr, k.t_tgid))
Yohei Ueda89bb40a2019-08-09 14:12:21 +0900397 print(" %-16s %s %s" % ("target:", k.target.decode('utf-8', 'replace'), k.t_pid))
ceeaspb47cecb62016-11-26 22:36:10 +0000398 print(" %d\n" % v.value)
399
400if missing_stacks > 0:
401 enomem_str = " Consider increasing --stack-storage-size."
Teng Qine778db02018-04-24 16:11:49 -0700402 print("WARNING: %d stack traces lost and could not be displayed.%s" %
403 (missing_stacks, (enomem_str if has_enomem else "")),
ceeaspb47cecb62016-11-26 22:36:10 +0000404 file=stderr)