Skip to content

Instantly share code, notes, and snippets.

@zolotyh
Created June 14, 2018 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zolotyh/631562efc94ce883ce0b2d9a6493014e to your computer and use it in GitHub Desktop.
Save zolotyh/631562efc94ce883ce0b2d9a6493014e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# draw image and open chart for memory real
# and virtual usage
set e
FILE=measures.csv;
SCALE=1048576
gnuplot <<- EOF
set parametric
set xlabel "Time"
set terminal png size 2560,1600
set ylabel "Memory (gb)"
set title "Memory usage"
set datafile separator ","
set y2tics 1
set ytics 1
set my2tics 10
set mytics 10
set term png
set ytics nomirror
set output "${FILE}.png
const=3
set grid ytics mytics
set key autotitle columnhead
plot '${FILE}' using 1:(\$2/$SCALE) with line, '${FILE}' using 1:(\$3/$SCALE) with line,'${FILE}' using 1:(\$4/100) with line
EOF
open "${FILE}.png"
#!/usr/bin/env bash
set -e
# some command in daemon mode
dart --use_compactor tool/grind.dart atomic-build-runner 2> error_report &
pid=$!
# If this script is killed, kill the `dart'.
trap "kill $pid 2> /dev/null" EXIT
(>&2 echo "NUMBER,VIRTUAL_MEMORY (kb),REAL_MEMORY (kb),CPU,SWAP") 2> ./measures.csv
# While process is running...
COUNTER=1
while kill -0 $pid 2> /dev/null; do
VIRTUAL_MEMORY="$(ps -p $pid -o vsize=)";
REAL_MEMORY="$(ps -p $pid -o rss=)";
CPU="$(ps -p $pid -o %cpu=)";
SWAP="$(ps -p $pid -o nswap=)";
(>&2 echo $COUNTER","$VIRTUAL_MEMORY","$REAL_MEMORY","$CPU","$SWAP) 2>> ./measures.csv
COUNTER=$[$COUNTER +1]
sleep 1
done
# Disable the trap on a normal exit.
trap - EXIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment