xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Kernel/cswstat.d (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1 #!/usr/sbin/dtrace -s
2 /*
3  * cswstat.d - context switch time stat.
4  *	       Uses DTrace (Solaris 10 03/05)
5  *
6  * This prints a context switch count and consumed time for context
7  * switching every second.
8  *
9  * $Id: cswstat.d,v 1.1.1.1 2015/09/30 22:01:09 christos Exp $
10  *
11  * USAGE:	cswstat.d
12  *
13  * FIELDS:
14  *		TIME		Current time
15  *		NUM		Number of context switches
16  *		CSWTIME(us)	Time consumed context switching, us
17  *		AVGTIME(us)	Average context switch time, us
18  *
19  * THANKS: Toomas Soome
20  *
21  * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
22  *
23  * CDDL HEADER START
24  *
25  *  The contents of this file are subject to the terms of the
26  *  Common Development and Distribution License, Version 1.0 only
27  *  (the "License").  You may not use this file except in compliance
28  *  with the License.
29  *
30  *  You can obtain a copy of the license at Docs/cddl1.txt
31  *  or http://www.opensolaris.org/os/licensing.
32  *  See the License for the specific language governing permissions
33  *  and limitations under the License.
34  *
35  * CDDL HEADER END
36  *
37  * 17-May-2005  Brendan Gregg   Created this.
38  * 03-Nov-2005	   "      "	Last update.
39  */
40 
41 #pragma D option quiet
42 
43 dtrace:::BEGIN
44 {
45 	/* print header */
46 	printf("%-20s  %8s %12s %12s\n", "TIME", "NUM", "CSWTIME(us)",
47 	    "AVGTIME(us)");
48 	times = 0;
49 	num = 0;
50 }
51 
52 sched:::off-cpu
53 {
54 	/* csw start */
55 	num++;
56 	start[cpu] = timestamp;
57 }
58 
59 sched:::on-cpu
60 /start[cpu]/
61 {
62 	/* csw end */
63 	times += timestamp - start[cpu];
64 	start[cpu] = 0;
65 }
66 
67 profile:::tick-1sec
68 {
69 	/* print output */
70 	printf("%20Y  %8d %12d %12d\n", walltimestamp, num, times/1000,
71 	    num == 0 ? 0 : times/(1000 * num));
72 	times = 0;
73 	num = 0;
74 }
75