new issue
[andk-cpan-tools.git] / bin / cpanshellwatcher.pl
blobc8a32462667eedeaff9e11a5b44e805a35708324
1 #!/usr/bin/perl
3 # use 5.010;
4 use strict;
5 use warnings;
7 =head1 NAME
11 =head1 SYNOPSIS
15 =head1 OPTIONS
17 =over 8
19 =cut
21 my @opt = <<'=back' =~ /B<--(\S+)>/g;
23 =item B<--help|h!>
25 This help
27 =back
29 =head1 DESCRIPTION
31 I had to repeat this several times
33 ps auxww|grep 'CPAN.*shell'
34 while true; do echo -n `date`; grep VmData /proc/14305/status; sleep 12; done
36 Now implementing it in one program
38 =cut
41 use FindBin;
42 use lib "$FindBin::Bin/../lib";
43 BEGIN {
44 push @INC, qw( );
47 use Dumpvalue;
48 use File::Basename qw(dirname);
49 use File::Path qw(mkpath);
50 use File::Spec;
51 use File::Temp;
52 use Getopt::Long;
53 use Hash::Util qw(lock_keys);
55 our %Opt;
56 lock_keys %Opt, map { /([^=]+)/ } @opt;
57 GetOptions(\%Opt,
58 @opt,
59 ) or pod2usage(1);
61 use POSIX qw(strftime);
63 while () {
64 open my $fh, "-|", ps => "axww" or die;
65 while (<$fh>) {
66 my($pid,undef,undef,undef,$cmd) = split " ", $_, 5;
67 next unless $cmd =~ /CPAN\s.*shell/;
68 open my $fh2, "<", "/proc/$pid/status" or next;
69 while (<$fh2>) {
70 # VmData: 7528 kB
71 next unless /^VmData:(?:\s+)(\d+) kB/;
72 printf "%s %5d %7d\n", strftime("%FT%T",localtime), $pid, $1;
75 sleep 12;
78 # Local Variables:
79 # mode: cperl
80 # cperl-indent-level: 4
81 # End: