Commit e324aa26 authored by Gary Wong's avatar Gary Wong

Generate time series data of future node usage.

parent fe20880b
......@@ -742,6 +742,60 @@ sub FreeCount($$;$) {
return $answer;
}
#
# Generate a time series of counts of nodes of a given type.
sub Forecast($$;$) {
my ($class, $type, $projlist) = @_;
my $reservations = LookupAll( $class, $type );
my @forecast = ();
my @answer = ();
my $t = time();
IsFeasible( $class, $reservations, undef, undef, undef, undef, \@forecast );
foreach my $f ( @forecast ) {
my $unavailable = 0;
my $held = 0;
my $free = $f->{'free'};
foreach my $pid ( keys( %{$f->{'used'}} ) ) {
$unavailable += $f->{'used'}->{$pid};
}
foreach my $pid ( keys( %{$f->{'reserved'}} ) ) {
my $r = $f->{'reserved'}->{$pid};
my $u = $f->{'used'}->{$pid};
if( $r > $u ) {
if( grep( $_ eq $pid, @$projlist ) ) {
$held += $r - $u;
} else {
$unavailable += $r - $u;
}
}
}
my %r = (
t => $f->{'t'},
unavailable => $unavailable,
held => $held,
free => $free
);
if( $r{'t'} < $t ) {
# event in the past; overwrite initial result in list but do
# not append
$r{'t'} = $t;
$answer[ 0 ] = \%r;
} else {
push( @answer, \%r );
}
}
return @answer;
}
sub ExptTypes($) {
my ($exptidx) = @_;
......
......@@ -46,8 +46,11 @@ sub usage()
{
print STDERR "Usage: predict [-p] [-u] [-t time] type\n";
print STDERR " predict -c type [pid...]\n";
print STDERR " predict -l type [pid...]\n";
print STDERR " -h This message\n";
print STDERR " -c Give an oversimplified free node count\n";
print STDERR " -l Give a list of node allocation status counts " .
"over time\n";
print STDERR " -p Identify by pid only, not pid/eid\n";
print STDERR " -t Give time/date for prediction (defaults to now)\n";
print STDERR " -u Interpret/display all times in UTC\n";
......@@ -55,11 +58,12 @@ sub usage()
exit( -1 );
}
my $optlist = "cdhpt:";
my $optlist = "cdhlpt:";
my $debug = 0;
my $time = time; # default to now
my $pidonly = 0;
my $countonly = 0;
my $timeseries = 0;
my $type;
sub fatal($)
......@@ -116,7 +120,10 @@ if (defined($options{"t"})) {
if (defined($options{"c"})) {
$countonly = 1;
}
usage() if( $countonly ? @ARGV < 1 : @ARGV != 1 );
if (defined($options{"l"})) {
$timeseries = 1;
}
usage() if( ( $countonly || $timeseries ) ? @ARGV < 1 : @ARGV != 1 );
$type = shift( @ARGV );
unless( $type =~ /^[-\w]+$/ ) {
fatal( "Invalid node type." );
......@@ -128,6 +135,19 @@ if( $countonly ) {
exit( 0 );
}
if( $timeseries ) {
print "Time Unavailable Held Free\n";
print "---------- ----- ---- ----\n";
foreach my $rec ( Reservation->Forecast( $type, \@ARGV ) ) {
printf( "%s %5d %5d %5d\n",
strftime( "%Y-%m-%d %H:%M", localtime( $rec->{'t'} ) ),
$rec->{'unavailable'}, $rec->{'held'}, $rec->{'free'} );
}
exit( 0 );
}
my $reservations = Reservation->LookupAll( $type );
my @timeline = ();
my $free = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment