|
Problem(Abstract) |
Under Linux™, the ps command lists
indistinctly all the processes and threads. The memmap tool identifies
which are real processes and which are threads. |
|
|
|
Resolving the
problem |
The memmap tool scans the output of the ps
command and identifies the processes running for WebSphere® Application
Server. Then, for each process, it reads the info in /proc and determines
whether the current entry is a real process or just a thread sharing the
same storage as the parent process.
Then, for each group of threads sharing the same storage, memmap displays
the following statistics:
- VmSize: Virtual memory size
- VmRss: Resident Set Size that the process has in real memory, minus 3
for administrative purposes. This is just the pages which count towards
text, data, or stack space. This does not include pages which have not
been demand-loaded in, or which are swapped out.
- VmData: Data (heap) allocated
- VmStk: Size of the stack
- VmExe: Size of the code (text) portion
- VmLib: Shared memory mapped to libraries and shared code
The source code follows (My server will go down shortly, no URL). See
installation instructions below.
#! /usr/bin/perl -w
# This program scans the process list of the Linux machine and
# finds all the WebSphere threads. It counts the threads and
# display statistics.
use 'File::Basename';
my $ProgName;
my $line;
my $pid;
my $ppid;
my $pgid;
my $session;
my $rss;
my $vsz;
my $ThdCnt = 0; # Number of threads in a group
my $GrpIdent=""; # Process group identifier
my $ProcIdent=""; # Process identifier
$ProgName = basename($0);
# This ps command gets a hierarchical tree of all processes
open PSOUT, "ps -eo 'pid,ppid,pgid,session,rss,vsz,command' -H |" or
die "$ProgName: cannot execute command ps: $!";
while (<PSOUT>) {
next unless /WebSphere/; # Skip everything not related to WAS
$line= $_; # Current line from ps output
$line =~ s/^ +//; # Remove blanks from beginning
($pid, $ppid, $pgid, $session, $rss, $vsz) = split / +/, $line;
# print "$pid, $ppid, $pgid, $session, $rss, $vsz\n"; ## DEBUG
# To decide that a set of processes are actually in the same
# group, we verify that: 1. they are in a hierachy (same
# tree branch),
# 2. they have the same PGID, SESSION, RSS and VSZ values,
## Process identifier = concatenation of PGID, SESSION, RSS and VSZ
$ProcIdent = $pgid . $session . $rss . $vsz;
if ($ProcIdent ne $GrpIdent) { # Is this a new thread group?
DisplayThd(); # Display the stats for previous group if any
$ThdCnt = 1;
$Parent = $pid;
$GrpIdent = $ProcIdent;
# Grab the content of the /proc/X/status entry
@Status=`cat /proc/$pid/status |grep '^Vm'`;
}
else {
$ThdCnt++;
}
}
close PSOUT;
DisplayThd(); # Might be needed
exit 0;
############################################
sub DisplayThd {
if ($ThdCnt != 0) {
print "Group of $ThdCnt threads, parent PID=$Parent\n";
my $i;
foreach $i (@Status) { print $i;}
}
}
#example of short cmdline display:
#(cat /proc/10755/cmdline; echo) | tr "\000" "\n" |grep -v '^-[A-Z]'
|
|
|
|
|
|
|