1 |
dpavlin |
38 |
#!/usr/bin/perl |
2 |
|
|
|
3 |
|
|
use warnings; |
4 |
|
|
use strict; |
5 |
|
|
|
6 |
|
|
use YAML; |
7 |
|
|
|
8 |
|
|
my $too_long = 0.5; # s |
9 |
|
|
my $stats; |
10 |
|
|
|
11 |
|
|
open(my $lastcomm, '-|', 'lastcomm'); |
12 |
|
|
while(<$lastcomm>) { |
13 |
|
|
chomp; |
14 |
|
|
if ( m{^(\S+).+?(\S+)\s+(\S+)\s+(\d+\.\d+) secs} ) { |
15 |
|
|
my ( $command, $user, $tty, $duration ) = ( $1, $2, $3, $4 ); |
16 |
|
|
$stats->{command}->{$command} += $duration; |
17 |
|
|
$stats->{user}->{$user} += $duration; |
18 |
|
|
$stats->{tty}->{$tty} += $duration; |
19 |
|
|
print "$_\n" if $duration > $too_long; |
20 |
|
|
} else { |
21 |
|
|
warn "# $_"; |
22 |
|
|
} |
23 |
|
|
} |
24 |
|
|
|
25 |
|
|
foreach my $stat ( keys %$stats ) { |
26 |
|
|
print "\n$stat:\n"; |
27 |
|
|
my $counter = $stats->{$stat}; |
28 |
|
|
foreach my $name ( sort { $counter->{$b} <=> $counter->{$a} } keys %$counter ) { |
29 |
dpavlin |
39 |
my $d = $counter->{$name}; |
30 |
|
|
printf "%8.2f %s\n", $d, $name if $d > $too_long; |
31 |
dpavlin |
38 |
} |
32 |
|
|
} |