我发现了这个解析 linux smaps 的 perl 脚本,但它似乎有点过时了:
#!/usr/bin/perl
# Copyright Ben Maurer
# you can distribute this under the MIT/X11 License
use Linux::Smaps;
my $pid=shift @ARGV;
unless ($pid) {
print "./smem.pl <pid>\n";
exit 1;
}
my $map=Linux::Smaps->new($pid);
my @VMAs = $map->vmas;
format STDOUT =
VMSIZE: @######## kb
$map->size
RSS: @######## kb total
$map->rss
@######## kb shared
$map->shared_clean + $map->shared_dirty
@######## kb private clean
$map->private_clean
@######## kb private dirty
$map->private_dirty
.
write;
printPrivateMappings ();
printSharedMappings ();
sub sharedMappings () {
return grep { ($_->shared_clean + $_->shared_dirty) > 0 } @VMAs;
}
sub privateMappings () {
return grep { ($_->private_clean + $_->private_dirty) > 0 } @VMAs;
}
sub printPrivateMappings ()
{
$TYPE = "PRIVATE MAPPINGS";
$^ = 'SECTION_HEADER';
$~ = 'SECTION_ITEM';
$- = 0;
$= = 100000000;
foreach $vma (sort {-($a->private_dirty <=> $b->private_dirty)}
privateMappings ()) {
$size = $vma->size;
$dirty = $vma->private_dirty;
$clean = $vma->private_clean;
$file = $vma->file_name;
write;
}
}
sub printSharedMappings ()
{
$TYPE = "SHARED MAPPINGS";
$^ = 'SECTION_HEADER';
$~ = 'SECTION_ITEM';
$- = 0;
$= = 100000000;
foreach $vma (sort {-(($a->shared_clean + $a->shared_dirty)
<=>
($b->shared_clean + $b->shared_dirty))}
sharedMappings ()) {
$size = $vma->size;
$dirty = $vma->shared_dirty;
$clean = $vma->shared_clean;
$file = $vma->file_name;
write;
}
}
format SECTION_HEADER =
@<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$TYPE
@>>>>>>>>>> @>>>>>>>>>> @>>>>>>>>> @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
"vmsize" "rss clean" "rss dirty" "file"
.
format SECTION_ITEM =
@####### kb @####### kb @####### kb @<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
$size $clean $dirty $file
.
当我运行脚本时,我得到:
./smem.perl 121212
Use of comma-less variable list is deprecated at ./smem.perl line 86.
Use of comma-less variable list is deprecated at ./smem.perl line 86.
Use of comma-less variable list is deprecated at ./smem.perl line 86.
Use of comma-less variable list is deprecated at ./smem.perl line 91.
Use of comma-less variable list is deprecated at ./smem.perl line 91.
Use of comma-less variable list is deprecated at ./smem.perl line 91.
Can't locate object method "size" via package "Linux::Smaps" at ./smem.perl line 18.
我正在运行 perl 5 和最新版本的 Linux::Smaps。我不是 perl 人,但我想知道这是否是一个简单的解决方法。另外,如果您知道类似的实用程序,我也很想听听。