First, what is a memory leak?
When programs allocate memory, buy fail to 'release' this memory for other programs to use, the memory is said to have leaked. It is no longer avalible to the system until a restart occures. Over time, these small amounts of memory can add up and degredate system performance.
In our example, we will look at firefox.
The first thing we need to do is list the memory usage of firefox using the ps command:
ps -C firefox-bin -o etime=,sz=
This will output the elapsed time, and the amount of memory used.
Now, to detect a memory leak, we will need to monitor this over time, so we will loop this command and pipe the output to a file:
while true; do
ps -C firefox-bin -o etime=,sz= >> data.txt
sleep 10
done
This will generate a list of out memory usage in the file named data.txt in 10 second intervals.
Finally, we will want to graph this data, and see what our memory usage looks like over time. To achive this, we will use gnuplot.
To graph our newly gathered data, we will use the following command:
COMMAND = "plot'data.txt' using 1:2"
SETUP = "set xdata time; set timefmt '%M:%S'; set format x '%M'; unset key"
$SETUP $COMMAND | gnuplat -persist