Last active
March 20, 2021 23:47
-
-
Save mystor/27beaf86a4868a357dcd58f585b42c6a to your computer and use it in GitHub Desktop.
A simple script for counting the avaliable jobs in an icecream network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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