#!/usr/bin/env -S gnuplot --persist -c # Gnuplot script for data generated with: # smem -P '^myprogram' -t | tail -n1 \ # | awk '{print "USS:", $4; print "PSS:",$5; print "RSS:",$6; print "SWP:",$3;}' \ # | sed "s/:/ $(date --iso-8601=minutes)/" >> mem-myprogram.data # Example usage: ./memory-consumption-over-time.gp myprogram 2021-12-05T08:42 if (ARGC > 0) { myprog = ARG1 } else { myprog='unknown' } infile=sprintf('mem-%s.data', myprog) mytimefmt = "%Y-%m-%dT%H:%M" if (ARGC > 1) { mystarttime = strptime(mytimefmt, ARG2) } else { mystarttime = strptime(mytimefmt, "1970-01-01T00:00") } set title sprintf('%s memory consumption over time', myprog) set key left top set xlabel 'Time (Hours)' set ylabel 'MiB (USS, PSS, RSS)' set y2label 'MiB (Swap)' textcolor 'dark-red' set xdata time set timefmt mytimefmt set xtics timedate set xtics format "%tH" set xtics 21600 # 1 tic every 6 hours. set mxtics 6 # 1 mtic every hour. set ytics 10 nomirror # 1 tic every 10 MiB. set mytics 2 # 1 mtic every 5 MiB. set y2tics 10 nomirror textcolor 'dark-red' set my2tics 2 set grid xtics ytics mxtics mytics lc "gray50" lw 0.75, lc "gray" lw 0.5 myfont = "Source Sans Pro,12" # set terminal qt enhanced size 1200,900 font myfont # set terminal png enhanced notransparent size 1200,900 font myfont # set output sprintf("%s memory consumption over time.png", myprog) myfont = "Source Sans Pro,16" set terminal svg enhanced background rgb 'white' size 1200,900 dynamic font myfont set output sprintf("%s memory consumption over time.svg", myprog) plot infile every 4::0 using ((timecolumn(2) - mystarttime)):($3/1024) title 'USS' \ with linespoints linewidth 3 pointtype 7 pointsize 0.5 linecolor 'dark-violet', \ \ '' every 4::1 using ((timecolumn(2) - mystarttime)):($3/1024) title 'PSS' \ with linespoints linewidth 2 pointtype 7 pointsize 0.5 linecolor 'dark-green', \ \ '' every 4::2 using ((timecolumn(2) - mystarttime)):($3/1024) title 'RSS' \ with linespoints linewidth 2 pointtype 7 pointsize 0.5 linecolor 'dark-orange', \ \ '' every 4::3 using ((timecolumn(2) - mystarttime)):($3/1024) title 'Swap' \ with linespoints linewidth 2 pointtype 7 pointsize 0.5 linecolor 'dark-red' axes x1y2 print 'Maximum = ',GPVAL_DATA_Y_MAX