blib/script/pagecache-clear.pl untested

filter: Statementstmt 0.0% 0 / 37 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 5 Podpod n/a totaltotal 0.0% 0 / 58 CC 1 SCAR 6.9
CC
1
Cov
0%
BEGIN
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 #!/usr/local/bin/perl
2  
3 use strict;
4 use warnings;
5  
6 use Getopt::Long qw(:config posix_default no_ignore_case no_ignore_case_always);
7 use Pod::Usage;
8  
9 use Sys::PageCache;
10  
11 MAIN: {
12 my $offset = 0;
13 my $length = 0;
14 my $rate;
15 GetOptions(
16 'rate|r=f' => \$rate,
17 'help|h|?' => sub { pod2usage(-verbose=>1) }) or pod2usage();
18  
19 my $fnlen = 8;
20 for (@ARGV) { $fnlen = length($_) if $fnlen < length($_) }
21 ### $fnlen
22  
23 for my $file (@ARGV) {
24 my $r;
25 printf("%-${fnlen}s:\n", $file);
26  
27 if (defined $rate && $rate > 0) {
28 ### rate: $rate
29 $rate = 1 if $rate > 1;
30 $length = int( (stat $file)[7] * $rate );
31 }
32  
33 ### offset: $offset
34 ### length: $length
35  
36 $r = fincore $file;
37 printf(" before cached/total_size=%llu/%llu cached/total_pages=%llu/%llu\n",
38 $r->{cached_size}, $r->{file_size},
39 $r->{cached_pages}, $r->{total_pages},
40 );
41  
42 $r = fadvise $file, $offset, $length, POSIX_FADV_DONTNEED;
43  
44 $r = fincore $file;
45 printf(" after cached/total_size=%llu/%llu cached/total_pages=%llu/%llu\n",
46 $r->{cached_size}, $r->{file_size},
47 $r->{cached_pages}, $r->{total_pages},
48 );
49 }
50  
51 exit 0;
52 }
53  
54 __END__