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