c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# CDDL HEADER START
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# The contents of this file are subject to the terms of the
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Common Development and Distribution License (the "License").
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# You may not use this file except in compliance with the License.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# See the License for the specific language governing permissions
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# and limitations under the License.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# When distributing Covered Code, include this CDDL HEADER in each
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# If applicable, add the following below this CDDL HEADER, with the
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# fields enclosed by brackets "[]" replaced with your own identifying
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# information: Portions Copyright [yyyy] [name of copyright owner]
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# CDDL HEADER END
7595fad9bab86562dbe8d6580c4b310bbad949b7akolb# Copyright 2008 Sun Microsystems, Inc. All rights reserved.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Use is subject to license terms.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# lgrpinfo: display information about locality groups.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbuse warnings;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbuse Getopt::Long qw(:config no_ignore_case bundling auto_version);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Sun::Solaris::Kstat is used to extract per-lgroup load average.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Amount of load contributed by a single thread. The value is exported by the
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# kernel in the 'loadscale' variable of lgroup kstat, but in case it is missing
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# we use the current default value as the best guess.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Get script name
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Get liblgrp version
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# The $loads hash keeps per-lgroup load average.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb########################################
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Set message locale
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Parse command-line options
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbour($opt_a, $opt_l, $opt_m, $opt_c, $opt_C, $opt_e, $opt_t, $opt_h, $opt_u,
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Check for conflicting options
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext("%s: Options -C, -T and -P can not be used together\n"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext("%s: Option -T can not be used with -I, -t\n"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext("%s: Warning: with '-T' all lgroups on the command line "),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb printf STDERR gettext("%s: Option -I can not be used with -L\n"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Figure out what to do based on options
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $opt_a || $opt_l || $opt_m || $opt_c || $opt_e || $opt_t || $opt_r;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbmy $l = Sun::Solaris::Lgrp->new($opt_G ? LGRP_VIEW_OS : LGRP_VIEW_CALLER) or
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb die(gettext("$cmdname: can not get lgroup information from the system\n"));
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Get list of all lgroups, the root and the list of intermediates
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbmy @intermediates = grep { $_ != $root && !$l->isleaf($_) } @lgrps;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Print everything if -a is specified or it is default without -T
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbmy $do_all = 1 if $opt_a || ($do_default && !($opt_T || $opt_L));
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Print individual information if do_all or requested specific print
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbmy $do_something = ($do_lat || $do_memory || $do_cpu || $do_topo ||
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Does the liblgrp(3LIB) has enough capabilities to support resource view?
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Get list of lgrps from arguments, expanding symbolic names like
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# "root" and "leaves"
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Use all lgroups if none are specified on the command line
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbmy @lgrp_list = (scalar (@ARGV) && !$opt_T) ? lgrp_expand($l, @ARGV) : @lgrps;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Apply 'Parent' or 'Children' operations if requested
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb@lgrp_list = map { $l->parents($_) } @lgrp_list if $opt_P;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb@lgrp_list = map { $l->children($_) } @lgrp_list if $opt_C;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Drop repeating elements and sort lgroups numerically.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# If both -L and -c are specified, just print list of CPUs.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my @cpus = uniqsort(map { $l->cpus($_, LGRP_CONTENT_HIERARCHY) }
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "@cpus\n";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Convert units to canonical numeric and string formats.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb if ($opt_u =~ /^b$/i) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb } elsif ($opt_u =~ /^k$/i) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb } elsif ($opt_u =~ /^m$/i) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb } elsif ($opt_u =~ /^g$/i) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb } elsif ($opt_u =~ /^t$/i) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb } elsif ($opt_u =~ /^p$/i) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb } elsif ($opt_u =~ /^e$/i) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb } elsif (! ($opt_u =~ /^m$/i)) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext("%s: invalid unit '$opt_u', should be [b|k|m|g|t|p|e]"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Collect load average data if requested.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Get latency values for each lgroup.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbmap { $self_latencies{$_} = $l->latency($_, $_) } @lgrps;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# If -T is specified, just print topology and return.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbif (!scalar @lgrp_list) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb printf STDERR gettext("%s: No matching lgroups found!\n"), $cmdname;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Just print list of lgrps if doing just filtering
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Walk through each requested lgrp and print whatever is requested.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb "root": $is_leaf ? gettext("leaf") : gettext("intermediate");
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Get children of this lgrp.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Are there any parents for this lgrp?
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $memstr = lgrp_showmemory($lgrp, LGRP_CONTENT_HIERARCHY);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Print all the information about lgrp.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "\n\t$loads->{$lgrp}" if defined ($loads->{$lgrp});
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb printf gettext("\n\tLatency: %d"), $self_latencies{$lgrp};
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "\n";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolbprint_latency_table(\@lgrps, \@lgrp_list) if $do_table;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# usage(exit_status)
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# print usage message and exit with the specified exit status.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print STDERR " [-aceGlLmrt] [-u unit] [-C|-P] [lgrp] ...\n";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print STDERR " \t$cmdname -I [-c] [-G] [-C|-P] [lgrp] ...\n";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print STDERR " \t$cmdname -T [-aceGlLmr] [-u unit]\n";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext(" Display information about locality groups\n\n" .
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb "\t-a: Equivalent to \"%s\" without -T and to \"%s\" with -T\n"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext("\t-l: Print information about lgroup latencies\n"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext("\t-P: Parent(s) of the specified lgroups\n"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext("\t-t: Print information about lgroup topology\n"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext("\t-u unit: Specify memory unit (b,k,m,g,t,p,e)\n\n\n");
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext(" The lgrp may be specified as an lgroup ID,"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb "-celmrt all";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb gettext(" Without any options print topology, CPU and memory " .
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb "information about each\n" .
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb " lgroup. If any lgroup IDs are specified on the " .
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb "command line only print\n" .
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb " information about the specified lgroup.\n\n");
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb exit(shift);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Return the input list with duplicates removed.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Sort the list numerically
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Should be called in list context
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb return (sort { $a <=> $b } @_);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Sort list numerically and remove duplicates
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Should be called in list context
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb return (sort { $a <=> $b } uniq(@_));
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Round values
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $val = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Expand list of lgrps.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Translate 'root' to the root lgrp id
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Translate 'all' to the list of all lgrps
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Translate 'leaves' to the list of all lgrps'
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Translate 'intermediate' to the list of intermediates.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $lobj = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # create a hash element for every element in @lgrps
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb foreach my $lgrp (@_) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb push(@result, $lobj->root), next if $lgrp =~ m/^root$/i;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb push(@result, $lobj->leaves), next if $lgrp =~ m/^leaves$/i;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb printf STDERR gettext("%s: skipping invalid lgrp $lgrp\n"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# lgrp_tree(class, node)
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Build the tree of the lgroup hierarchy starting with the specified node or
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# root if no initial node is specified. Calls itself recursively specifying each
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# of the children as a starting node. Builds a reference to the list with the
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# node in the end and each element being a subtree.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $c = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Call itself for each of the children and combine results in a list.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb [ (map { lgrp_tree($c, $_) } $c->children($lgrp)), $lgrp ];
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# lgrp_pp(tree, prefix, childprefix, npeers)
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# pretty-print the hierarchy tree.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Input Arguments:
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Reference to the tree
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Prefix for me to use
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Prefix for my children to use
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Number of peers left
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $tree = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $myprefix = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $childprefix = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $npeers = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb return unless defined ($el);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Pretty-print the subtree with a new offset.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb lgrp_pp($_, "| ", "$childprefix$new_prefix", --$nchildren)
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Pretty print the whole tree
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $c = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $lgrp = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $prefix = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $is_interm = ($lgrp != $root && !$l->isleaf($lgrp));
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "$lgrp";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $memstr = lgrp_showmemory($lgrp, LGRP_CONTENT_HIERARCHY);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Print all the information about lgrp.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "\n$prefix$loads->{$lgrp}" if defined ($loads->{$lgrp});
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Print latency information if requested.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb if ($do_lat && $lgrp != $root && defined($self_latencies{$lgrp})) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "\n${prefix}";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb printf gettext("Latency: %d"), $self_latencies{$lgrp};
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "\n";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# What CPUs are in this lgrp?
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $lgrp = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $hier = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Sort CPU list if there is something to sort.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# How much memory does this lgrp contain?
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $lgrp = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $hier = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $memory = $l->mem_size($lgrp, LGRP_MEM_SZ_INSTALLED, $hier);
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $freemem = $l->mem_size($lgrp, LGRP_MEM_SZ_FREE, $hier) || 0;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $memstr = $memstr . sprintf(gettext(", allocated %s"),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Get string containing lgroup resources
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $lgrp = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # What resources does this lgroup contain?
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my @resources_cpu = nsort($l->resources($lgrp, LGRP_RSRC_CPU));
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my @resources_mem = nsort($l->resources($lgrp, LGRP_RSRC_MEM));
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $rsrc = @resources_cpu || @resources_mem ? "" : gettext("none");
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $rsrc = "$rsrc $rsrc_cpu ($lcpu);" if scalar @resources_cpu;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $rsrc = "$rsrc $rsrc_mem ($lmemory)" if scalar @resources_mem;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Consolidate consequtive ids as start-end
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Input: list of ids
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Output: string with space-sepated cpu values with ranges
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# collapsed as x-y
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb return ('') unless @_;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $end = $start; # Initial range consists of the first element
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Got consecutive ID, so extend end of range without
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # printing anything since the range may extend further
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Next ID is not consecutive, so print IDs gotten so
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb } else { # same value
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Try finding consecutive range starting from this ID
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Print last ID(s)
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Remove any spaces in the beginning
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb $result =~ s/^\s+//;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Print latency information if requested and the system has several lgroups.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb return unless scalar @lgrps;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Find maximum lgroup
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Field width for lgroup - the width of the largest lgroup and 1 space
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Field width for latency. Get the maximum latency and add 1 space.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Make sure that width is enough to print lgroup itself.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Print table header
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Print horizontal line
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "\n";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Print the latency table
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb if (!defined ($latency)) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "\n";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Print table footer
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb print "\n";
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Convert a number to a string representation
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# The number is scaled down until it is small enough to be in a good
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# human readable format i.e. in the range 0 thru 1023.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# If it's smaller than 10 there's room enough to provide one decimal place.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $number = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my @measurement = ('K', 'M', 'G', 'T', 'P', 'E'); # Measurement
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Get size in K.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # check if we should output a decimal place after the point
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb return ("$result$uom");
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Convert memory size to the string representation
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $number = shift;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Zero memory - just print 0
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Return memory size scaled to human-readable form unless -u is
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # specified.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb return (number_to_scaled_string($number)) unless $opt_u;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb return ("$result$unit_str");
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# Read load averages from lgrp kstats Return hash reference indexed by lgroup ID
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb# for each lgroup which has load information.
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $ks = Sun::Solaris::Kstat->new(strip_strings => 1) or
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb warn(gettext("$cmdname: can not read lgrp kstat\n)")),
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Collect load for each lgroup
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb foreach my $i (keys %$lgrp_kstats) {
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $lav = $lgrp_kstats->{$i}->{"lgrp$i"}->{"load average"};
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb # Skip this lgroup if can't find its load average
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb next unless defined $lav;
c64027834c5ffc60c557c2b12555e0cd4d30320cakolb my $scale = $lgrp_kstats->{$i}->{"lgrp$i"}->{"loadscale"} ||