diff options
| author | Paul Buetow <paul@buetow.org> | 2010-11-07 11:21:48 +0000 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2010-11-07 11:21:48 +0000 |
| commit | f78a23a566b90ae93e4b330343b28a3ecd0d9921 (patch) | |
| tree | 7c0f73fa59b08c37c751e10a4dab1d9177faa7ef /cpuload.pl | |
| parent | 8f218f6d690646a1c9e095029521935f9787e093 (diff) | |
toggle CPUs without recreating threads
Diffstat (limited to 'cpuload.pl')
| -rwxr-xr-x | cpuload.pl | 18 |
1 files changed, 13 insertions, 5 deletions
@@ -65,6 +65,7 @@ sub get_remote_stat ($) { my $bash = "for i in \$(seq $CONF{samples}); do cat /proc/stat; sleep 0.1; done"; my $cmd = $host eq 'localhost' ? $bash : "ssh $CONF{sshopts} $host '$bash'"; + my $sigusr1 = 0; loop { my $pid = open2 my $out, my $in, $cmd or die "Error: $!\n"; @@ -75,12 +76,22 @@ sub get_remote_stat ($) { threads->exit(); }; + # Toggle CPUs + $SIG{USR1} = sub { + $sigusr1 = 1; + }; + my $cpuregexp = qr/$CONF{cpuregexp}/; while (<$out>) { /$cpuregexp/ && do { my ($name, $load) = parse_cpu_line $_; $STATS{"$host;$name"} = join ';', map { $_ . '=' . $load->{$_} } keys %$load; + }; + + if ($sigusr1) { + $cpuregexp = qr/$CONF{cpuregexp}/; + $sigusr1 = 0; } } } @@ -283,14 +294,11 @@ sub stop_threads (@) { sub toggle_cpus ($\@@) { my ($display, $threads, @hosts) = @_; - stop_threads @$threads; - - $display->kill('USR1'); - $CONF{total} = ! $CONF{total}; $CONF{cpuregexp} = $CONF{total} ? 'cpu ' : 'cpu'; - (undef, @$threads) = create_threads @hosts, no_display; + $_->kill('USR1') for @$threads; + $display->kill('USR1'); return undef; } |
