13 |
my $dt = 3; |
my $dt = 3; |
14 |
my $acpi_every = 10; |
my $acpi_every = 10; |
15 |
|
|
16 |
|
my $disk_blk_size = 512; |
17 |
|
|
18 |
my $debug = shift @ARGV; |
my $debug = shift @ARGV; |
19 |
|
|
20 |
$|=1; |
$|=1; |
29 |
$value =~ s/ m[VW]h*$//; |
$value =~ s/ m[VW]h*$//; |
30 |
$h->{$key} = $value; |
$h->{$key} = $value; |
31 |
} |
} |
32 |
warn dump( $h ) if ( $debug ); |
warn "$f ",dump( $h ) if ( $debug ); |
33 |
return $h; |
return $h; |
34 |
} |
} |
35 |
|
|
38 |
|
|
39 |
warn "unit( $v )\n" if ($debug); |
warn "unit( $v )\n" if ($debug); |
40 |
|
|
41 |
my @units = qw/b k m g/; |
my @units = qw/b k M G/; |
42 |
my $o = 0; |
my $o = 0; |
43 |
|
|
44 |
while ( ( $v / 1024 ) >= 1 ) { |
while ( ( $v / 1024 ) >= 1 ) { |
47 |
} |
} |
48 |
|
|
49 |
if ( $v >= 1 ) { |
if ( $v >= 1 ) { |
50 |
return sprintf("%d%s/s", $v, $units[$o]); |
return sprintf("%d%s", $v, $units[$o]); |
51 |
|
} elsif ( $v == 0 ) { |
52 |
|
return ''; |
53 |
} else { |
} else { |
54 |
return sprintf("%.1f%s/s", $v, $units[$o]); |
return sprintf("%.1f%s", $v, $units[$o]); |
55 |
} |
} |
56 |
} |
} |
57 |
|
|
58 |
my ( $lrx, $ltx ) = ( 0, 0 ); |
my ( $lrx, $ltx ) = ( 0, 0 ); |
59 |
|
my ( $ld_r, $ld_w ) = ( 0, 0 ); |
60 |
my $bat; |
my $bat; |
61 |
|
|
62 |
my $i = 0; |
my $i = 0; |
74 |
my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'}; |
my $pcnt = $state->{'remaining capacity'} / $info->{'design capacity'}; |
75 |
|
|
76 |
my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} ); |
my $time = $state->{'remaining capacity'} / ( $state->{'present rate'} ); |
77 |
|
$time = ( $info->{'design capacity'} - $state->{'remaining capacity'} ) / $state->{'present rate'} if ( $state->{'charging state'} eq 'charging' ); |
78 |
|
|
79 |
warn "time = $time\n" if ($debug); |
warn "time = $time\n" if ($debug); |
80 |
|
|
109 |
|
|
110 |
foreach ( split(/\n/, $net) ) { |
foreach ( split(/\n/, $net) ) { |
111 |
s/^\s+//; |
s/^\s+//; |
112 |
|
s/:\s+/:/; |
113 |
my @n = split(/\s+/, $_, 17); |
my @n = split(/\s+/, $_, 17); |
114 |
next unless ( $n[0] =~ m!(eth\d|ath\d):! ); |
next unless ( $n[0] =~ s!(eth\d|ath\d):!! ); |
115 |
|
|
116 |
warn dump( @n ) if ($debug); |
warn dump( @n ) if ($debug); |
117 |
$rx += $n[1]; |
$rx += $n[0]; |
118 |
$tx += $n[9]; |
$tx += $n[8]; |
119 |
} |
} |
120 |
warn "rx: $rx tx: $tx\n" if ($debug); |
warn "rx: $rx tx: $tx\n" if ($debug); |
121 |
|
|
122 |
my $r = ( $rx - $lrx ) / $dt; |
my $net_rx = ( $rx - $lrx ) / $dt; |
123 |
my $t = ( $tx - $ltx ) / $dt; |
my $net_tx = ( $tx - $ltx ) / $dt; |
124 |
( $lrx, $ltx ) = ( $rx, $tx ); |
( $lrx, $ltx ) = ( $rx, $tx ); |
125 |
|
|
126 |
printf "%s | %s |%6s >> %-6s| %s%s\n", $s, $load, unit( $r ), unit( $t ), $bat, $temp; |
my $disk = read_file('/proc/diskstats'); |
127 |
|
my ( $d_r, $d_w ) = ( 0,0 ); |
128 |
|
|
129 |
|
foreach ( split(/\n/, $disk) ) { |
130 |
|
s/^\s+//; |
131 |
|
my @d = split(/\s+/, $_, 17); |
132 |
|
next unless ( $d[2] =~ m/^[sh]d\w$/ ); |
133 |
|
|
134 |
|
warn dump( @d ) if ($debug); |
135 |
|
$d_r += $d[5] * $disk_blk_size; |
136 |
|
$d_w += $d[7] * $disk_blk_size; |
137 |
|
} |
138 |
|
warn "d_r: $d_r d_w: $d_w\n" if ($debug); |
139 |
|
|
140 |
|
my $d_read = ( $d_r - $ld_r ) / $dt; |
141 |
|
my $d_write = ( $d_w - $ld_w ) / $dt; |
142 |
|
( $ld_r, $ld_w ) = ( $d_r, $d_w ); |
143 |
|
|
144 |
|
printf("%s | %s |%5s D %-5s|%5s > %-5s| %s%s\n", |
145 |
|
$s, |
146 |
|
$load, |
147 |
|
unit( $d_read ), unit( $d_write ), |
148 |
|
unit( $net_rx ), unit( $net_tx ), |
149 |
|
$bat, $temp, |
150 |
|
); |
151 |
|
|
152 |
sleep $dt; |
sleep $dt; |
153 |
} |
} |