summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Buetow <paul@buetow.org>2010-11-07 14:55:07 +0000
committerPaul Buetow <paul@buetow.org>2010-11-07 14:55:07 +0000
commit4d153a22f28e793b268680ae49913410f53e9ef7 (patch)
tree2e89139d29276aacad4f6f686b8fa55ce09d379b
parente78f5366195d5fec2e9b51404faaf70042552f8c (diff)
better getopt support
-rwxr-xr-xcpuload.pl19
1 files changed, 15 insertions, 4 deletions
diff --git a/cpuload.pl b/cpuload.pl
index 1ef32f6..150c214 100755
--- a/cpuload.pl
+++ b/cpuload.pl
@@ -38,7 +38,7 @@ my %CONF :shared;
interval => 0.1,
sshopts => '',
cpuregexp => 'cpu',
- total => 0,
+ toggle => 0,
);
sub say (@) { print "$_\n" for @_; return undef }
@@ -302,11 +302,15 @@ sub stop_threads (@) {
return undef;
}
+sub set_toggle_regexp () {
+ $CONF{cpuregexp} = $CONF{toggle} ? 'cpu ' : 'cpu';
+}
+
sub toggle_cpus ($@) {
my ($display, @threads) = @_;
- $CONF{total} = ! $CONF{total};
- $CONF{cpuregexp} = $CONF{total} ? 'cpu ' : 'cpu';
+ $CONF{toggle} = ! $CONF{toggle};
+ set_toggle_regexp;
$_->kill('USR1') for @threads;
%STATS = ();
@@ -339,9 +343,16 @@ END
sub main () {
my $hosts = '';
- GetOptions ('hosts=s' => \$hosts);
+ GetOptions (
+ 'hosts=s' => \$hosts,
+ 'averate=i' => \$CONF{average},
+ 'interval=i' => \$CONF{interval},
+ 'samples=i' => \$CONF{samples},
+ 'toggle=i' => \$CONF{toggle},
+ );
my @hosts = split ',', $hosts;
@hosts = 'localhost' unless @hosts;
+ set_toggle_regexp;
my ($display, @threads) = create_threads @hosts;