1N/A#!/usr/sbin/dtrace -s
1N/A/*
1N/A * loads.d - print load averages. Written using DTrace (Solaris 10 3/05).
1N/A *
1N/A * These are the same load averages that the "uptime" command prints.
1N/A * The purpose of this script is to demonstrate fetching these values
1N/A * from the DTrace language.
1N/A *
1N/A * $Id: loads.d 3 2007-08-01 10:50:08Z brendan $
1N/A *
1N/A * USAGE: loads.d
1N/A *
1N/A * SEE ALSO: uptime(1)
1N/A *
1N/A * The first field is the 1 minute average, the second is the 5 minute,
1N/A * and the third is the 15 minute average. The value represents the average
1N/A * number of runnable threads in the system, a value higher than your
1N/A * CPU (core/hwthread) count may be a sign of CPU saturation.
1N/A *
1N/A * COPYRIGHT: Copyright (c) 2005 Brendan Gregg.
1N/A *
1N/A * CDDL HEADER START
1N/A *
1N/A * The contents of this file are subject to the terms of the
1N/A * Common Development and Distribution License, Version 1.0 only
1N/A * (the "License"). You may not use this file except in compliance
1N/A * with the License.
1N/A *
1N/A * You can obtain a copy of the license at Docs/cddl1.txt
1N/A * or http://www.opensolaris.org/os/licensing.
1N/A * See the License for the specific language governing permissions
1N/A * and limitations under the License.
1N/A *
1N/A * CDDL HEADER END
1N/A *
1N/A * 10-Jun-2005 Brendan Gregg Created this.
1N/A * 10-Jun-2005 " " Last update.
1N/A */
1N/A
1N/A#pragma D option quiet
1N/A
1N/Adtrace:::BEGIN
1N/A{
1N/A /* fetch load averages */
1N/A this->load1a = `hp_avenrun[0] / 65536;
1N/A this->load5a = `hp_avenrun[1] / 65536;
1N/A this->load15a = `hp_avenrun[2] / 65536;
1N/A this->load1b = ((`hp_avenrun[0] % 65536) * 100) / 65536;
1N/A this->load5b = ((`hp_avenrun[1] % 65536) * 100) / 65536;
1N/A this->load15b = ((`hp_avenrun[2] % 65536) * 100) / 65536;
1N/A
1N/A /* print load average */
1N/A printf("%Y, load average: %d.%02d, %d.%02d, %d.%02d\n",
1N/A walltimestamp, this->load1a, this->load1b, this->load5a,
1N/A this->load5b, this->load15a, this->load15b);
1N/A
1N/A exit(0);
1N/A}