Skip to content

Instantly share code, notes, and snippets.

@icholy
Created June 10, 2014 17:02
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save icholy/c37391b1773c73ea3315 to your computer and use it in GitHub Desktop.
Save icholy/c37391b1773c73ea3315 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# Author: Ilia Choly <ilia.choly@gmail.com>
# Year: 2014
#
if [[ -z "$1" ]]; then
echo "usage: graph_memory.sh <pid>"
exit 1
fi
_pid=$1
_out_file=${_pid}.log
_gnuplot_file=${_pid}.gnuplot
echo -e "
set datafile separator \",\"
set terminal dumb
set title \"Memory Usage\"
set ylabel \"Bytes\"
set xlabel \"Date\"
set xdata time
set timefmt \"%s\"
set format x \"%m/%d\"
set key left top
set grid
plot \"${_out_file}\" using 1:2 title '${_pid}'
" > $_gnuplot_file
while true; do
_rss=$(ps ax -eo pid,rss | grep -e "^\s*$_pid" | awk '{ print $2 }')
_ts=$(date +"%s")
echo "$_ts, $_rss" >> $_out_file
clear
gnuplot $_gnuplot_file
sleep 10
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment