]> CyberLeo.Net >> Repos - FreeBSD/stable/10.git/blob - cddl/contrib/dtracetoolkit/Cpu/loads.d
Copy head (r256279) to stable/10 as part of the 10.0-RELEASE cycle.
[FreeBSD/stable/10.git] / cddl / contrib / dtracetoolkit / Cpu / loads.d
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 3 2007-08-01 10:50:08Z brendan $
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 }