- if ($message =~ /^cpustats$/i) {
- if ($^O !~ /linux/) {
- &ERROR("cpustats: your OS is not supported yet.");
- return;
- }
-
- ### poor method to get info out of file, please fix.
- open(STAT,"/proc/$$/stat");
- my $line = <STAT>;
- chop $line;
- my @data = split(/ /, $line);
- close STAT;
-
- # utime(13) + stime(14).
- my $cpu_usage = sprintf("%.01f", ($data[13]+$data[14]) / 100 );
- # cutime(15) + cstime (16).
- my $cpu_usage2 = sprintf("%.01f", ($data[15]+$data[16]) / 100 );
- my $time = time() - $^T;
- my $raw_perc = $cpu_usage*100/$time;
- my $raw_perc2 = $cpu_usage2*100/$time;
- my $perc;
- my $perc2;
- my $total;
- my $ratio;
-
- if ($raw_perc > 1) {
- $perc = sprintf("%.01f", $raw_perc);
- $perc2 = sprintf("%.01f", $raw_perc2);
- $total = sprintf("%.01f", $raw_perc+$raw_perc2);
- } elsif ($raw_perc > 0.1) {
- $perc = sprintf("%.02f", $raw_perc);
- $perc2 = sprintf("%.02f", $raw_perc2);
- $total = sprintf("%.02f", $raw_perc+$raw_perc2);
- } else { # <=0.1
- $perc = sprintf("%.03f", $raw_perc);
- $perc2 = sprintf("%.03f", $raw_perc2);
- $total = sprintf("%.03f", $raw_perc+$raw_perc2);
- }
- $ratio = sprintf("%.01f", 100*$perc/($perc+$perc2) );
-
- &performStrictReply("Total CPU usage: \002$cpu_usage\002 s ... ".
- "Total used: \002$total\002 % ".
- "(parent/child ratio: $ratio %)"
- );
-
- return;
+ if ( $message =~ /^cpustats$/i ) {
+ if ( $^O !~ /linux/ ) {
+ &ERROR('cpustats: your OS is not supported yet.');
+ return;
+ }
+
+ ### poor method to get info out of file, please fix.
+ open( STAT, "/proc/$$/stat" );
+ my $line = <STAT>;
+ chop $line;
+ my @data = split( / /, $line );
+ close STAT;
+
+ # utime(13) + stime(14).
+ my $cpu_usage = sprintf( '%.01f', ( $data[13] + $data[14] ) / 100 );
+
+ # cutime(15) + cstime (16).
+ my $cpu_usage2 = sprintf( '%.01f', ( $data[15] + $data[16] ) / 100 );
+ my $time = time() - $^T;
+ my $raw_perc = $cpu_usage * 100 / $time;
+ my $raw_perc2 = $cpu_usage2 * 100 / $time;
+ my $perc;
+ my $perc2;
+ my $total;
+ my $ratio;
+
+ if ( $raw_perc > 1 ) {
+ $perc = sprintf( '%.01f', $raw_perc );
+ $perc2 = sprintf( '%.01f', $raw_perc2 );
+ $total = sprintf( '%.01f', $raw_perc + $raw_perc2 );
+ }
+ elsif ( $raw_perc > 0.1 ) {
+ $perc = sprintf( '%.02f', $raw_perc );
+ $perc2 = sprintf( '%.02f', $raw_perc2 );
+ $total = sprintf( '%.02f', $raw_perc + $raw_perc2 );
+ }
+ else { # <=0.1
+ $perc = sprintf( '%.03f', $raw_perc );
+ $perc2 = sprintf( '%.03f', $raw_perc2 );
+ $total = sprintf( '%.03f', $raw_perc + $raw_perc2 );
+ }
+ $ratio = sprintf( '%.01f', 100 * $perc / ( $perc + $perc2 ) );
+
+ &performStrictReply( "Total CPU usage: \002$cpu_usage\002 s ... "
+ . "Total used: \002$total\002 % "
+ . "(parent/child ratio: $ratio %)" );
+
+ return;