[mca1001] / doodles / who-spun-disc.pl  

mca1001: doodles/who-spun-disc.pl

File: [mca1001] / doodles / who-spun-disc.pl (download) (as text)
Revision: 1.1, Fri Aug 6 22:27:44 2004 UTC (6 years, 1 month ago) by mca1001
Branch: MAIN
CVS Tags: HEAD
chuck this in just as I'm working on something more efficient and useful

#! /usr/bin/perl -w

use strict;
use Time::HiRes qw( usleep gettimeofday tv_interval );
our $VERSION = (qw$Revision 0.0 $)[1];

=head1 NAME

who-spun-disc.pl - find processes in disk sleep

=head1 DESCRIPTION

I wondered what had caused my laptop's drive to spin up.  I figure
some process will have gone into C<disk sleep>, and it will have to
stay there for the 3/4 sec or so that it takes to get data off the
surface.

Polling L<ps> four times a second doesn't thrash disc of course,
because it's cached, but it uses a fair bit of CPU.

=head1 SEE ALSO

L<bin/squid-dates.pl>

=head1 AUTHOR

(c) 2004 Matthew Astley L<http://www.t8o.org/~mca1001/>

No rights reserved.  It's a doodle, do what you like with it.

=cut

my $ticks;
while (1) {
    my @ps = `ps -e --cols 90 -o pid -o wchan:20 -o pagein -o stat -o cmd `; # suits Debian procps 1:3.2.1-2, at least
    my $when = [ gettimeofday ];
    die "Choke on header >$ps[0]<" unless $ps[0] eq
	"  PID WCHAN                PAGEIN STAT CMD\n";
    print " " x 10, ": ", shift @ps unless $ticks++; # header
    foreach (@ps) {
	my ($pid, $wchan, $pg, $stat, $cmd) = split /\s+/, $_, 5;
	my $now = time();
	print "$now: $_" if $stat =~ /D/;
    }

    usleep(0.25 * 1E6);
}

Repository owner

Powered by ViewCVS 1.0-dev
(Powered by ViewCVS)

ViewCVS and CVS Help