lkml.org 
[lkml]   [2003]   [Oct]   [6]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectMy stab at finding memory used by processes
This perl script just goes through /proc/maps, finding inodes numbered 
with 0 and adds those sizes. Seems to over-report things with our
servers, probably because it counts all pages even if they're copy on
write, don't know how to get around that.

Any comments are welcome.
#!/usr/bin/perl -w
use strict;
use File::Glob ':glob';

my $procregex = qr /^(\S+)-(\S+) \S+ \S+ \S+ (\S+)/;

sub process_mapsfile {
my ($path) = @_;

open(MAPSFD, $path);

my $totalsize = 0;
while(<MAPSFD>)
{
if (!/$procregex/)
{
#print "Couldn't match\n$_\n";
next;
}
else
{
#print "Matched\n$_\n";
}

#print "line = $_";
my $start = int(hex($1));
my $end = int(hex($2));
my $inode = int($3);
#print "inode = $inode, end = $end, start = $start\n";
if($inode == 0)
{
my $size = $end - $start;
$totalsize += $size;
}
}

close(MAPSFD);
return $totalsize;
}


my $totalsize = 0;
my @files = </proc/*>;
foreach my $file (@files)
{
# if we have a pid file, parse maps file
if($file =~ /\/proc\/\d+/)
{
$totalsize += process_mapsfile($file . "/maps");
}
}

print "size = $totalsize\n";
\
 
 \ /
  Last update: 2005-03-22 13:49    [W:0.045 / U:1.976 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site