Annotation of src/share/btrace/runqlat.bt, Revision 1.3
1.3 ! bluhm 1: /* $OpenBSD$ */
! 2:
1.1 mpi 3: /*
4: * runqlat.bt Measure run queue latency (aka scheduler latency). OpenBSD.
5: *
6: * This measures the time from enqueue to on-cpu, for the same thread.
7: *
8: * WARNING: This traces scheduler functions, which can incur high overhead.
9: * This is not suitable for 24x7 monitoring.
10: *
11: * Copyright (c) 2014 Brendan Gregg. All rights reserved.
12: * Copyright (c) 2021 Martin Pieuchot. All rights reserved.
13: *
1.2 mpi 14: * Redistribution and use in source and binary forms, with or without
1.1 mpi 15: * modification, are permitted provided that the following conditions
16: * are met:
1.2 mpi 17: * 1. Redistributions of source code must retain the above copyright
1.1 mpi 18: * notice, this list of conditions and the following disclaimer.
1.2 mpi 19: * 2. Redistributions in binary form must reproduce the above copyright
1.1 mpi 20: * notice, this list of conditions and the following disclaimer in the
21: * documentation and/or other materials provided with the distribution.
22: *
23: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
24: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
27: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
1.2 mpi 29: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1.1 mpi 31: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1.2 mpi 32: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
1.1 mpi 33: * SUCH DAMAGE.
34: *
35: * 19-Jun-2014 Brendan Gregg Created this.
36: * 08-Sep-2021 Martin Pieuchot Ported this to OpenBSD's btrace(8)
37: */
38:
39: /*
40: * Work around multiple enqueue/dequeue cycles due to priority changes
41: * before executing by registering only the first time a thread is put
42: * on a scheduler queue.
43: */
44: tracepoint:sched:enqueue
45: /@ts[arg0] == 0/
46: {
47: /*
48: * For the enqueue and dequeue probes, arg0 is the thread ID.
49: */
50: @ts[arg0] = nsecs
51: }
52:
53: tracepoint:sched:on__cpu
54: /@ts[tid]/
55: {
56: $usec = (nsecs - @ts[tid]) / 1000;
57: @max_usec[0] = max($usec);
58: @dist_usec = hist($usec);
59: delete(@ts[tid]);
60: }
61:
62: interval:hz:1
63: {
64: time("%H:%M:%S ");
65: printf("Run queue latency (us):\n");
66: print(@dist_usec);
67: printf("Max run queue latency: %d ms\n", @max_usec[0] / 1000);
68: clear(@dist_usec); clear(@max_usec);
69: }
70:
71: END
72: {
73: clear(@ts);
74: time("%H:%M:%S ");
75: printf("Run queue latency (us):\n");
76: print(@dist_usec);
77: printf("Max run queue latency: %d ms\n", @max_usec[0] / 1000);
78: clear(@dist_usec); clear(@max_usec);
79: }