All of lore.kernel.org
 help / color / mirror / Atom feed
* My stab at finding memory used by processes
@ 2003-10-06 18:57 Brett
  0 siblings, 0 replies; only message in thread
From: Brett @ 2003-10-06 18:57 UTC (permalink / raw)
  To: linux-kernel; +Cc: Kevin Kahley

[-- Attachment #1: Type: text/plain, Size: 280 bytes --]

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.

[-- Attachment #2: getprocmem.pl --]
[-- Type: text/plain, Size: 869 bytes --]

#!/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";

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-10-06 18:58 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-10-06 18:57 My stab at finding memory used by processes Brett

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.