To collect memory usage information for a Java™ or Node.js process you must first identify
the process you want to monitor, then use an operating system command
such as svmon or ps to gather the
information.
About this task
The system command to use depends on your operating system.
The IBM® Monitoring and Diagnostic
Tools - Garbage Collection and Memory Visualizer (GCMV) displays different
information for each command:
- AIX®: use the svmon command.
GCMV displays the following information:
- Memory in the system virtual space.
- Memory in use.
- Paging Space.
- Pinned Memory.
- Reserved Address Space (virtual memory).
- Linux: use the ps command
with the vsz and rss parameters.
GCMV displays the following information:
- Virtual set size (vsz), the total size that
the process occupies in virtual memory
- Resident set size (rss), the actual amount
of space the process occupies in physical memory, where some of the
memory the application has requested might currently be paged out
to disk and hence be part of the vsz number but
not the rss number.
- z/OS®: use the ps command
with the vsz parameter. GCMV displays the virtual
set size (vsz), the total size the process occupies
in virtual memory.
Procedure
- List all the Java or
Node.js processes that are running on your machine.
Use
one of the following commands to list all the processes:
- On AIX:
ps -e -o "pid args"
- On Linux:
ps -e -ww -o "pid args"
Use one of the following commands to list the processes
owned by a specific user:
- On AIX:
ps -u userid -o "pid args"
- On Linux:
ps -u userid -ww -o "pid args"
- On z/OS:
ps -e -o "jobname pid args"
- Identify the Java or
Node.js process that you want to gather memory usage information for,
and record its process ID for user later in this task.
You
can identify Java or Node.js
processes in the process list by looking for the path to the Java or Node.js program that is
running the process. If you are gathering verbose garbage collection
data for the process, the output also contains the string -verbose:gc.
- Modify the following example script to gather memory usage
information on your operating system.
You use a system
command to gather memory usage information, however the command produces
only a snapshot of information. To plot and analyze memory usage you
must have information that covers a period of time. To process the
data with GCMV, the information must also include the time when the
collection of data began and how frequently the data was gathered.
The example script runs the system command at fixed intervals, and
generates information that contains the date, a message about the
intervals between invocations of the system command, and the output
from the system command.
Find the comments in the script that
relate to operating systems and remove the comment and operating system
string for the line that is relevant to you. For example if you are
using the AIX operating system,
change
# AIX: echo "svmon interval = $INTERVAL" to
echo
"svmon interval = $INTERVAL".
Note: Although the script uses
the ps command only for Linux operating systems, you can also use it
on AIX systems that support
the proc file system. However the svmon command
provides more information.
#!/bin/sh
# The process id to monitor is the first and only argument.
PID=$1
# The interval between command invocations, in seconds.
INTERVAL=3
# Echo the date line to record the start of monitoring.
# AIX or Linux: echo timestamp = `date +%s`
# z/OS: echo timestamp = `date`
# Echo the interval frequency.
# AIX: echo "svmon interval = $INTERVAL"
# Linux or z/OS: echo "ps interval = $INTERVAL"
# Run the system command at intervals.
# AIX or Linux: while ([ -d /proc/$PID ]) do
# z/OS: while true ; do
# AIX: svmon -r -m -P $PID
# Linux: ps -p $PID -o pid,vsz,rss
# z/OS: ps -p $PID -o pid,vsz
sleep $INTERVAL
done
On the z/OS operating
system, some jobs span multiple processes. Use the following script
to obtain usage values across all the processes with the same job
name.
#!/bin/sh
# The jobname to monitor is the first and only argument.
JOBNAME=$1
# The interval between ps invocations, in seconds.
INTERVAL=3
# Echo the date line so we know when monitoring began.
echo timestamp = `date`
# Echo the interval frequency.
echo "ps interval = $INTERVAL"
while true ; do
echo " PID VSZ JOBNAME"
ps -o pid,vsz,jobname | grep $JOBNAME
sleep $INTERVAL
done
- Run the script, specifying the process ID to monitor or
the z/OS job name, and redirect
the script output to a file.
For example, the following
command generates an output file called memusage.out,
which contains memory usage information for the process whose ID is
1234. The example assumes that the script is saved as a file called memscript.sh,
and made executable by using the chmod u+x command.
./memscript.sh 1234 > memusage.out
If
you do not redirect the output, it is written to the standard output
(stdout) stream.
Example
Example memory usage information on the z/OS operating system:
timestamp = Fri Jul 16 03:49:21 EDT 2010
ps interval = 3
PID VSZ
9471 1145580
PID VSZ
9471 1145580
PID VSZ
9471 1145580
......
What to do next
You can now open the saved file in GCMV, to view and analyze
the memory usage data.