Skip to content

Instantly share code, notes, and snippets.

@NobodyXu
Forked from mystor/icecc-jobs.pl
Created March 20, 2021 23:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NobodyXu/bf7709fa1e62467ddc849bf2f4951357 to your computer and use it in GitHub Desktop.
Save NobodyXu/bf7709fa1e62467ddc849bf2f4951357 to your computer and use it in GitHub Desktop.
A simple script for counting the avaliable jobs in an icecream network
#!/usr/bin/env perl
# This short script queries the icecream scheduler to discover what machines are connected,
# and sums the maximum job counts for all x86-64 machines.
# It can be used in your mozconfig as follows:
# mk_add_options MOZ_MAKE_FLAGS="-j$(icecc-jobs)"
# if this script is on your PATH, and named icecc-jobs
use List::Util qw(sum0);
my $scheduler = "10.242.24.68";
# Get the local processor count
if ($^O eq "darwin") {
$locl = `sysctl -n hw.ncpu`;
$xtra = $locl; # darwin machines are not included in the scheduler count
} else {
$locl = `nproc`;
$xtra = 0; # We're on linux, and will be included in the scheduler count
}
# Set up a signal to print out a default value if the query takes too long
$SIG{ALRM} = sub { print $locl; exit 0; };
alarm(2);
# Run the query, and print out the sum of the maximum job counts
my $resp = `nc $scheduler 8766 <<EOF
listcs
exit
EOF`;
print sum0($resp =~ /\[x86_64\].+jobs=[0-9]+\/([0-9]+)/g) + $xtra;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment