xref: /netbsd-src/external/cddl/dtracetoolkit/dist/Cpu/loads.d (revision c29d51755812ace2e87aeefdb06cb2b4dac7087a)
1 #!/usr/sbin/dtrace -s
2 /*
3  * loads.d - print load averages. Written using DTrace (Solaris 10 3/05).
4  *
5  * These are the same load averages that the "uptime" command prints.
6  * The purpose of this script is to demonstrate fetching these values
7  * from the DTrace language.
8  *
9  * $Id: loads.d,v 1.1.1.1 2015/09/30 22:01:07 christos Exp $
10  *
11  * USAGE:	loads.d
12  *
13  * SEE ALSO:	uptime(1)
14  *
15  * The first field is the 1 minute average, the second is the 5 minute,
16  * and the third is the 15 minute average. The value represents the average
17  * number of runnable threads in the system, a value higher than your
18  * CPU (core/hwthread) count may be a sign of CPU saturation.
19  *
20  * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
21  *
22  * CDDL HEADER START
23  *
24  *  The contents of this file are subject to the terms of the
25  *  Common Development and Distribution License, Version 1.0 only
26  *  (the "License").  You may not use this file except in compliance
27  *  with the License.
28  *
29  *  You can obtain a copy of the license at Docs/cddl1.txt
30  *  or http://www.opensolaris.org/os/licensing.
31  *  See the License for the specific language governing permissions
32  *  and limitations under the License.
33  *
34  * CDDL HEADER END
35  *
36  * 10-Jun-2005	Brendan Gregg	Created this.
37  * 10-Jun-2005	   "      "	Last update.
38  */
39 
40 #pragma D option quiet
41 
42 dtrace:::BEGIN
43 {
44 	/* fetch load averages */
45 	this->load1a  = `hp_avenrun[0] / 65536;
46 	this->load5a  = `hp_avenrun[1] / 65536;
47 	this->load15a = `hp_avenrun[2] / 65536;
48 	this->load1b  = ((`hp_avenrun[0] % 65536) * 100) / 65536;
49 	this->load5b  = ((`hp_avenrun[1] % 65536) * 100) / 65536;
50 	this->load15b = ((`hp_avenrun[2] % 65536) * 100) / 65536;
51 
52 	/* print load average */
53 	printf("%Y,  load average: %d.%02d, %d.%02d, %d.%02d\n",
54 	    walltimestamp, this->load1a, this->load1b, this->load5a,
55 	    this->load5b, this->load15a, this->load15b);
56 
57 	exit(0);
58 }
59