Solaris-Lgrp

 view release on metacpan or  search on metacpan

bin/lgrpinfo  view on Meta::CPAN

}

# What CPUs are in this lgrp?
sub lgrp_showcpus
{
	my $lgrp = shift;
	my $hier = shift;

	my @cpus = $l->cpus($lgrp, $hier);
	my $ncpus = @cpus;
	return 0 unless $ncpus;
	# Sort CPU list if there is something to sort.
	@cpus = nsort(@cpus) if ($ncpus > 1);
	my $cpu_string = lgrp_collapse(@cpus);
	return (($ncpus == 1) ?
		gettext("CPU: ") . $cpu_string:
		gettext("CPUs: ") . $cpu_string);
}

# How much memory does this lgrp contain?
sub lgrp_showmemory
{
	my $lgrp = shift;
	my $hier = shift;

	my $memory = $l->mem_size($lgrp, LGRP_MEM_SZ_INSTALLED, $hier);
	return (0) unless $memory;
	my $freemem = $l->mem_size($lgrp, LGRP_MEM_SZ_FREE, $hier);
	# Convert memory to units.
	my $memory_r = round($memory / $units);
	my $freemem_r = round($freemem / $units);
	my $usedmem = $memory_r - $freemem_r;
	my $memstr = sprintf(gettext("Memory: installed %s %s"),
			     $memory_r, $unit_str);
	$memstr = $memstr . sprintf(gettext(", allocated %s %s"),
				    $usedmem, $unit_str);
	$memstr = $memstr . sprintf(gettext(", free %s %s"),
				    $freemem_r, $unit_str);
	return ($memstr);
}

# Get string containing lgroup resources
sub lgrp_showresources
{
	my $lgrp = shift;
	my $rsrc_prefix = gettext("Lgroup resources:");
	# What resources does this lgroup contains?
	my @resources_cpu = nsort($l->resources($lgrp, LGRP_RSRC_CPU));
	my @resources_mem = nsort($l->resources($lgrp, LGRP_RSRC_MEM));
	my $rsrc = @resources_cpu || @resources_mem ? "" : gettext("none");
	$rsrc = $rsrc_prefix . $rsrc;
	my $rsrc_cpu = lgrp_collapse(@resources_cpu);
	my $rsrc_mem = lgrp_collapse(@resources_mem);
	my $lcpu = gettext("CPU");
	my $lmemory = gettext("memory");
	$rsrc = "$rsrc $rsrc_cpu ($lcpu);" if scalar @resources_cpu;
	$rsrc = "$rsrc $rsrc_mem ($lmemory)" if scalar @resources_mem;
	return ($rsrc);
}

# Consolidate consequtive ids as start-end
sub lgrp_collapse
{
	return "" unless @_;
	my @args = uniqsort(@_);
	my $start = shift(@args);
	my $end = $start;
	my $result = "";
	foreach my $el (@args) {
		if ($el == ($end + 1)) {
			$end = $el;
		} else {
			if ($end > $start + 1) {
				$result = "$result $start-$end";
			} elsif ($end > $start) {
				$result = "$result $start $end";
			} else {
				$result = "$result $start";
			}
			$start = $end = $el;
		}
	}
	if ($end > $start + 1) {
		$result = "$result $start-$end";
	} elsif ($end > $start) {
		$result = "$result $start $end";
	} else {
		$result = "$result $start";
	}
	$result =~ s/^\s+//;
	return ($result);
}

# Print latency information if requested and the system has several lgroups.
sub print_latency_table
{
	my ($lgrps1, $lgrps2) = @_;

	return unless scalar @lgrps;

	# Find maximum lgroup
	my $max = $root;
	map { $max = $_ if $max < $_ } @$lgrps1;

	# Field width for lgroup - the width of the largest lgroup and 1 space
	my $lgwidth = length($max) + 1;
	# Field width for latency. Get the maximum latency and add 1 space.
	my $width = length($l->latency($root, $root)) + 1;
	# Make sure that width is enough to print lgroup itself.
	$width = $lgwidth if $width < $lgwidth;

	# Print table header
	print gettext("\nLgroup latencies:\n");
	# Print horizontal line
	print "\n", "-" x ($lgwidth + 1);
	map { print '-' x $width } @$lgrps1;
	print "\n", " " x $lgwidth, "|";
	map { printf("%${width}d", $_) } @$lgrps1;
	print "\n", "-" x ($lgwidth + 1);
	map { print '-' x $width } @$lgrps1;
	print "\n";

 view all matches for this distribution
 view release on metacpan -  search on metacpan

( run in 1.125 second using v1.00-cache-2.02-grep-82fe00e-cpan-1925d2aa809 )