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 * 10-Jun-2005, ver 0.90 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 */ 38 39#pragma D option quiet 40 41dtrace:::BEGIN 42{ 43 /* fetch load averages */ 44 this->fscale = `averunnable.fscale; 45 this->load1a = `averunnable.ldavg[0] / this->fscale; 46 this->load5a = `averunnable.ldavg[1] / this->fscale; 47 this->load15a = `averunnable.ldavg[2] / this->fscale; 48 this->load1b = ((`averunnable.ldavg[0] % this->fscale) * 100) / this->fscale; 49 this->load5b = ((`averunnable.ldavg[1] % this->fscale) * 100) / this->fscale; 50 this->load15b = ((`averunnable.ldavg[2] % this->fscale) * 100) / this->fscale; 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