diff options
| author | Paul Buetow <paul@buetow.org> | 2012-06-23 12:31:26 +0200 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2012-06-23 12:31:26 +0200 |
| commit | 91d104c18e6673fac3a83379e8f485e581f2dc48 (patch) | |
| tree | 4fb0dda4ebeb41538f594dccef1f2a07acaa10f9 /lib/Loadbars/Main.pm | |
| parent | 93afb23c5376123fbe128a23968d4e67b1121251 (diff) | |
use index function instead of regexp for cpu parsing
Diffstat (limited to 'lib/Loadbars/Main.pm')
| -rw-r--r-- | lib/Loadbars/Main.pm | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/lib/Loadbars/Main.pm b/lib/Loadbars/Main.pm index 6314b07..214ddc7 100644 --- a/lib/Loadbars/Main.pm +++ b/lib/Loadbars/Main.pm @@ -27,7 +27,7 @@ use Loadbars::Utils; $| = 1; sub set_showcores_regexp () { - $I{cpuregexp} = $C{showcores} ? 'cpu' : 'cpu '; + $I{cpustring} = $C{showcores} ? 'cpu' : 'cpu '; } sub percentage ($$) { @@ -91,9 +91,10 @@ sub stats_thread ($;$) { my ( $sigusr1, $sigterm ) = ( 0, 0 ); my $inter = Loadbars::Constants->INTERVAL; + my $cpustring = $I{cpustring}; + # Precompile some regexp my $loadavg_re = qr/^(\d+\.\d{2}) (\d+\.\d{2}) (\d+\.\d{2})/; - my $cpu_re = qr/$I{cpuregexp}/; my @meminfo = map { [$_, qr/^$_: *(\d+)/] } (qw(MemTotal MemFree Buffers Cached SwapTotal SwapFree)); @@ -149,7 +150,7 @@ BASH $AVGSTATS{$host} = "$1;$2;$3"; } - elsif ($_ =~ $cpu_re) { + elsif (0 == index $_, $cpustring) { my ( $name, $load ) = parse_cpu_line $_; $CPUSTATS{"$host;$name"} = join ';', map { $_ . '=' . $load->{$_} } @@ -185,8 +186,7 @@ BASH } if ($sigusr1) { - # TODO: Use index instead of regexp for cpuregexp - $cpu_re = qr/$I{cpuregexp}/; + $cpustring = $I{cpustring}; $sigusr1 = 0; } |
