gnuplot-scripts/memory-consumption-over-tim...

117 lines
4.0 KiB
Gnuplot
Executable File

#!/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
#
# Arguments: <program name> <time of first data point> [ytic mode] [mtic mode] [width] [height]
# Argument 3 (ytic mode) means:
# - default: 1 tic every 10 MiB, 1 mtic every 5 MiB.
# - big: 1 tic every 100 MiB, 1 mtic every 10 MiB.
# - verybig: 1 tic every 1000 MiB, 1 mtic every 100 MiB.
# Argument 4 (mtic mode) means:
# - short: 1 tic every 10 minutes.
# - default: 1 tic every hour.
# - long: 1 tic every 6 hours.
# Example usage: ./memory-consumption-over-time.gp myprogram 2021-12-05T08:42
# Example usage: ./memory-consumption-over-time.gp myprogram 2021-12-05T08:42 big short 640 480
if (ARGC < 2) {
printerr "You probably want to supply the program name ", \
"and the time of first data point. ", \
"See the header of this script for more information."
}
myprog='unknown'
if (ARGC >= 1) {
myprog = ARG1
}
infile=sprintf('mem-%s.data', myprog)
mytimefmt = "%Y-%m-%dT%H:%M"
mystarttime = strptime(mytimefmt, "1970-01-01T00:00")
if (ARGC >= 2) {
mystarttime = strptime(mytimefmt, ARG2)
}
myytics = 10 # 1 tic every 10 MiB.
mymytics = 2 # 1 mtic every 5 MiB.
if (ARGC >= 3) {
if (ARG3 eq "big") {
myytics = 100 # 1 tic every 100 MiB.
mymytics = 10 # 1 mtic every 10 MiB.
}
if (ARG3 eq "verybig") {
myytics = 1000 # 1 tic every 1000 MiB.
mymytics = 10 # 1 mtic every 10 MiB.
}
}
set xlabel 'Time (Hours)'
set xtics format "%tH"
set xtics 3600 # 1 tic every hour.
set mxtics 6 # 1 mtic every 10 minutes.
if (ARGC >= 4) {
if (ARG4 eq "short") {
set xlabel 'Time (Minutes)'
set xtics format "%tM"
set xtics 600 # 1 tic every 10 minutes.
set mxtics 10 # 1 tic every minute.
}
if (ARG4 eq "long") {
set xlabel 'Time (Hours)'
set xtics format "%tH"
set xtics 21600 # 1 tic every 6 hours.
set mxtics 6 # 1 mtic every hour.
}
}
array mysize[2] = [ 1200, 900 ]
if (ARGC >= 6) {
array mysize[2] = [ ARG5, ARG6 ]
}
set title sprintf('%s memory consumption over time', myprog)
set key left top
set ylabel 'MiB (USS, PSS, RSS)'
set y2label 'MiB (Swap)' textcolor 'dark-red'
set xdata time
set timefmt mytimefmt
set xtics timedate
set ytics myytics nomirror
set mytics mymytics
set y2tics myytics nomirror textcolor 'dark-red'
set my2tics mymytics
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 mysize[1],mysize[2] font myfont
# set terminal png enhanced notransparent size mysize[1],mysize[2] 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 mysize[1],mysize[2] \
dynamic font myfont
set output sprintf("%s memory consumption over time.svg", myprog)
set y2range [0:] # Don't go into minus if Swap is 0 the whole time.
# set label 1 '1 hour 200 MiB' at (1*60*60),(204800/1024) offset first 0,0 \
# point pt 7 lc "red"
plot infile every 4::0 using ((timecolumn(2) - mystarttime)):($3/1024) title 'USS' \
with linespoints linewidth 3 pointtype 7 pointsize 0.5, \
\
'' every 4::1 using ((timecolumn(2) - mystarttime)):($3/1024) title 'PSS' \
with linespoints linewidth 2 pointtype 7 pointsize 0.5, \
\
'' every 4::2 using ((timecolumn(2) - mystarttime)):($3/1024) title 'RSS' \
with linespoints linewidth 2 pointtype 7 pointsize 0.5, \
\
'' 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