Gnuplot script cleanup.

Gnuplot script cleanup.

MPARM = 1
NPARM = 2
KPARM = 3
CPARM = 4
SSIZE = 5
USIZE = 6
FLOPS = 8
MEMBW = 9

HIM = -1
HIN = HIM
HIK = HIM

BASENAME = "cp2k"
FILENAME = system("sh -c \"echo ${FILENAME}\"")
if (FILENAME eq "") {
  FILENAME = BASENAME."-perf.pdf"
}

FILECOUNT = 1 # initial file number
# MULTI =-1: multiple files; no titles
# MULTI = 0: multiple files with titles
# MULTI = 1: single file with titles
MULTI = system("sh -c \"echo ${MULTI}\"")
if (MULTI eq "") {
  MULTI = 1
}

XFLOPS(M, N, K) = 2.0 * M * N * K
NFLOPS(M, N, K) = XFLOPS(column(M), column(N), column(K))
NBYTES(M, N, K, ELEMSIZE) = ELEMSIZE * (column(M) * column(K) + column(K) * column(N) + column(M) * column(N))
AI(M, N, K, ELEMSIZE) = NFLOPS(M, N, K) / NBYTES(M, N, K, ELEMSIZE)

TIME(M, N, K, F, S) = column(S) * NFLOPS(M, N, K) * 1E-9 / column(F)
#BW(M, N, K, F, S, BWC, ELEMSIZE) = column(S) * (column(M) * column(K) + column(K) * column(N)) * ELEMSIZE / (TIME(M, N, K, F, S) * 1024 * 1024 * 1024)
BW(M, N, K, F, S, BWC, ELEMSIZE) = column(BWC)

stats BASENAME."-perf.dat" using (column(MPARM)*column(NPARM)*column(KPARM)) nooutput; MNK = STATS_stddev**(1.0/3.0); MAXMNK = int(STATS_max)
stats BASENAME."-perf.dat" using (log(column(FLOPS))) nooutput; GEO = exp(STATS_sum/STATS_records)
stats BASENAME."-perf.dat" using FLOPS nooutput; MED = STATS_median; MINFLOPS = STATS_min; MAXFLOPS = STATS_max
stats BASENAME."-perf.dat" using NPARM nooutput; XN = int(STATS_max)

MAX(A, B) = A < B ? B : A
ACC = sprintf("%%.%if", ceil(MAX(1.0 / log10(MED) - 1.0, 0)))

IX(I1, J1, NJ) = int(MAX(I1 - 1, 0) * NJ + MAX(J1 - 1, 0))
I1(IX, NJ) = int(IX / NJ) + 1
J1(IX, NJ) = int(IX) % NJ + 1

set table BASENAME."-perf-avg.dat"
plot BASENAME."-perf.dat" using (IX(column(MPARM), column(NPARM), XN)):FLOPS smooth unique
unset table
set table BASENAME."-perf-mbw.dat"
plot BASENAME."-perf.dat" using (BW(MPARM,NPARM,KPARM,FLOPS,SSIZE,MEMBW,8)):(1.0) smooth cumulative
unset table
set table BASENAME."-perf-cdf.dat"
plot BASENAME."-perf.dat" using FLOPS:(1.0) smooth cumulative
unset table
stats BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?($2):(1/0)) nooutput; FREQSUM = STATS_max; FREQN = STATS_records

if (MULTI==1) {
  set output FILENAME
}

FILEEXT = system("sh -c \"echo ".FILENAME." | sed 's/.\\+\\.\\(.\\+\\)/\\1/'\"")
set terminal FILEEXT
set termoption enhanced
#set termoption font ",12"
save_encoding = GPVAL_ENCODING
set encoding utf8

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance" }
set origin -0.03, 0
set pm3d interpolate 0, 0
#set colorbox horizontal user origin 0, 0.1 size 1, 0.1
#set autoscale fix
if (0<HIM) { set xrange [*:HIM] }
if (0<HIN) { set yrange [*:HIN] }
if (0<HIK) { set zrange [*:HIK] }
if (0>HIM) { set xrange [*:MNK] }
if (0>HIN) { set yrange [*:MNK] }
if (0>HIK) { set zrange [*:MNK] }
set xlabel "M"
set ylabel "N" offset -3.0
set zlabel "K" offset 1.0
set ticslevel 0
set cblabel "GFLOP/s" offset 1.5
set format x "%g"; set format y "%g"; set format z "%g"; set format cb "%g"
splot BASENAME."-perf.dat" using MPARM:NPARM:KPARM:FLOPS notitle with points pointtype 7 linetype palette

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance (K-Average)" }
set origin -0.02, 0
set dgrid3d #9, 9
set pm3d interpolate 0, 0 map
set autoscale fix
set xlabel "M"
set ylabel "N" offset -1.5
set cblabel "GFLOP/s" offset 0.5
set format x "%g"; set format y "%g"; set format cb "%g"
set mxtics 2
splot BASENAME."-perf-avg.dat" using (("".strcol(3)."" eq "i")?(I1($1, XN)):(1/0)):(("".strcol(3)."" eq "i")?(J1($1, XN)):(1/0)):2 notitle with pm3d

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance (Average per Bin)" }
set style fill solid 0.4 noborder
set boxwidth 0.5
set grid y2tics linecolor "grey"
unset key
unset xtics
set xtics ("MNK <= 13^3" 0, "13^3 < MNK <= 23^3" 1, "23^3 < MNK" 2) scale 0 offset 0, 0.2
set x2tics ("Small" 0, "Medium" 1, "Larger" 2) scale 0
set xlabel "Problem Size (MNK)"
set ytics format ""
set y2tics nomirror
set y2label "GFLOP/s"
set xrange [-0.5:2.5]
set autoscale fix
plot  BASENAME."-perf.dat" \
      using (0.0):((NFLOPS(MPARM,NPARM,KPARM)<=XFLOPS(13,13,13))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey", \
  ""  using (1.0):(((XFLOPS(13,13,13)<NFLOPS(MPARM,NPARM,KPARM))&&(NFLOPS(MPARM,NPARM,KPARM)<=XFLOPS(23,23,23)))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey", \
  ""  using (2.0):((XFLOPS(23,23,23)<NFLOPS(MPARM,NPARM,KPARM))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey"

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance and Memory Bandwidth (CDF)" }
set xlabel "Probability\n\n{/=8 Minimum: ".sprintf(ACC, MINFLOPS)." GFLOP/s  Geo. Mean: ".sprintf(ACC, GEO)." GFLOP/s  Median: ".sprintf(ACC, MED)." GFLOP/s  Maximum: ".sprintf(ACC, MAXFLOPS)." GFLOP/s}"
set ylabel "GB/s"
set y2label "GFLOP/s"
set format x "%g%%"
set format y "%g"
set format y2 "%g"
set ytics nomirror
set y2tics nomirror
set grid x y2 linecolor "grey"
set xrange [0:100]
set yrange [0:*]
set y2range [0:*]
set fit quiet
f(x) = b * x + a
fit f(x) BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 via a, b
g(x) = (x - a) / b
x50 = 0.5 * (100 + MAX(0, g(0)))
h(x) = d * x + c
dx = 100 / FREQN
fit [x50-1.5*dx:x50+1.5*dx] h(x) BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 via c, d
set arrow from x50, second h(x50) to x50, second 0 front
set arrow from x50, second h(x50) to 100, second h(x50) front
set label sprintf("%.0f%%", x50) at x50, second 0.5 * h(x50) left offset 1 front
set label sprintf(ACC." GFLOP/s", h(x50)) at 0.5 * (x50 + 100.0), second h(x50) centre offset 0, -1 front
set key left invert
plot  BASENAME."-perf-mbw.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 axes x1y1 title "Memory Bandwidth" with lines linecolor "grey", \
      BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 axes x1y2 title "Compute Performance" with lines linewidth 2

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance and Arithmetic Intensity" }
set grid x y2 linecolor "grey"
set key left #spacing 0.5
set ytics format ""
set y2tics nomirror
set y2label "GFLOP/s"
set xlabel "FLOPS/Byte"
set autoscale fix
plot  BASENAME."-perf.dat" using (AI(MPARM,NPARM,KPARM,8)):FLOPS notitle smooth sbezier with lines linecolor "grey", \
                        "" using (AI(MPARM,NPARM,KPARM,8)):FLOPS notitle smooth unique with points pointtype 7 pointsize 0.1

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Memory Bandwidth" }
set grid x y2 linecolor "grey"
set key left #spacing 0.5
set ytics format ""
set y2tics nomirror
set y2label "GB/s"
set xlabel "Problem Size (MNK**1/3)"
set autoscale fix
plot  BASENAME."-perf.dat" using ((column(MPARM)*column(NPARM)*column(KPARM))**(1.0/3.0)):(BW(MPARM,NPARM,KPARM,FLOPS,SSIZE,MEMBW,8)) notitle smooth sbezier with lines linecolor "grey", \
                        "" using ((column(MPARM)*column(NPARM)*column(KPARM))**(1.0/3.0)):(BW(MPARM,NPARM,KPARM,FLOPS,SSIZE,MEMBW,8)) notitle smooth unique with points pointtype 7 pointsize 0.1

MPARM = 1
NPARM = 2
KPARM = 3
CPARM = 4
SSIZE = 5
USIZE = 6
FLOPS = 8
MEMBW = 9

HIM = -1
HIN = HIM
HIK = HIM

BASENAME = "cp2k"
FILENAME = system("sh -c \"echo ${FILENAME}\"")
if (FILENAME eq "") {
  FILENAME = BASENAME."-perf.pdf"
}

FILECOUNT = 1 # initial file number
# MULTI =-1: multiple files; no titles
# MULTI = 0: multiple files with titles
# MULTI = 1: single file with titles
MULTI = system("sh -c \"echo ${MULTI}\"")
if (MULTI eq "") {
  MULTI = 1
}

XFLOPS(M, N, K) = 2.0 * M * N * K
NFLOPS(M, N, K) = XFLOPS(column(M), column(N), column(K))
NBYTES(M, N, K, ELEMSIZE) = ELEMSIZE * (column(M) * column(K) + column(K) * column(N) + column(M) * column(N))
AI(M, N, K, ELEMSIZE) = NFLOPS(M, N, K) / NBYTES(M, N, K, ELEMSIZE)

TIME(M, N, K, F, S) = column(S) * NFLOPS(M, N, K) * 1E-9 / column(F)
#BW(M, N, K, F, S, BWC, ELEMSIZE) = column(S) * (column(M) * column(K) + column(K) * column(N)) * ELEMSIZE / (TIME(M, N, K, F, S) * 1024 * 1024 * 1024)
BW(M, N, K, F, S, BWC, ELEMSIZE) = column(BWC)

stats BASENAME."-perf.dat" using (column(MPARM)*column(NPARM)*column(KPARM)) nooutput; MNK = STATS_stddev**(1.0/3.0); MAXMNK = int(STATS_max)
stats BASENAME."-perf.dat" using (log(column(FLOPS))) nooutput; GEO = exp(STATS_sum/STATS_records)
stats BASENAME."-perf.dat" using FLOPS nooutput; MED = STATS_median; MINFLOPS = STATS_min; MAXFLOPS = STATS_max
stats BASENAME."-perf.dat" using NPARM nooutput; XN = int(STATS_max)

MAX(A, B) = A < B ? B : A
ACC = sprintf("%%.%if", ceil(MAX(1.0 / log10(MED) - 1.0, 0)))

IX(I1, J1, NJ) = int(MAX(I1 - 1, 0) * NJ + MAX(J1 - 1, 0))
I1(IX, NJ) = int(IX / NJ) + 1
J1(IX, NJ) = int(IX) % NJ + 1

set table BASENAME."-perf-avg.dat"
plot BASENAME."-perf.dat" using (IX(column(MPARM), column(NPARM), XN)):FLOPS smooth unique
unset table
set table BASENAME."-perf-mbw.dat"
plot BASENAME."-perf.dat" using (BW(MPARM,NPARM,KPARM,FLOPS,SSIZE,MEMBW,8)):(1.0) smooth cumulative
unset table
set table BASENAME."-perf-cdf.dat"
plot BASENAME."-perf.dat" using FLOPS:(1.0) smooth cumulative
unset table
stats BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?($2):(1/0)) nooutput; FREQSUM = STATS_max; FREQN = STATS_records

if (MULTI==1) {
  set output FILENAME
}

FILEEXT = system("sh -c \"echo ".FILENAME." | sed 's/.\\+\\.\\(.\\+\\)/\\1/'\"")
set terminal FILEEXT
set termoption enhanced
#set termoption font ",12"
save_encoding = GPVAL_ENCODING
set encoding utf8

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance" }
set origin -0.03, 0
set pm3d interpolate 0, 0
#set colorbox horizontal user origin 0, 0.1 size 1, 0.1
#set autoscale fix
if (0<HIM) { set xrange [*:HIM] }
if (0<HIN) { set yrange [*:HIN] }
if (0<HIK) { set zrange [*:HIK] }
if (0>HIM) { set xrange [*:MNK] }
if (0>HIN) { set yrange [*:MNK] }
if (0>HIK) { set zrange [*:MNK] }
set xlabel "M"
set ylabel "N" offset -3.0
set zlabel "K" offset 1.0
set ticslevel 0
set cblabel "GFLOP/s" offset 1.5
set format x "%g"; set format y "%g"; set format z "%g"; set format cb "%g"
splot BASENAME."-perf.dat" using MPARM:NPARM:KPARM:FLOPS notitle with points pointtype 7 linetype palette

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance (K-Average)" }
set origin -0.02, 0
set dgrid3d #9, 9
set pm3d interpolate 0, 0 map
set autoscale fix
set xlabel "M"
set ylabel "N" offset -1.5
set cblabel "GFLOP/s" offset 0.5
set format x "%g"; set format y "%g"; set format cb "%g"
set mxtics 2
splot BASENAME."-perf-avg.dat" using (("".strcol(3)."" eq "i")?(I1($1, XN)):(1/0)):(("".strcol(3)."" eq "i")?(J1($1, XN)):(1/0)):2 notitle with pm3d

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance (Average per Bin)" }
set style fill solid 0.4 noborder
set boxwidth 0.5
set grid y2tics linecolor "grey"
unset key
unset xtics
set xtics ("MNK <= 13^3" 0, "13^3 < MNK <= 23^3" 1, "23^3 < MNK" 2) scale 0 offset 0, 0.2
set x2tics ("Small" 0, "Medium" 1, "Larger" 2) scale 0
set xlabel "Problem Size (MNK)"
set ytics format ""
set y2tics nomirror
set y2label "GFLOP/s"
set xrange [-0.5:2.5]
set autoscale fix
plot  BASENAME."-perf.dat" \
      using (0.0):((NFLOPS(MPARM,NPARM,KPARM)<=XFLOPS(13,13,13))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey", \
  ""  using (1.0):(((XFLOPS(13,13,13)<NFLOPS(MPARM,NPARM,KPARM))&&(NFLOPS(MPARM,NPARM,KPARM)<=XFLOPS(23,23,23)))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey", \
  ""  using (2.0):((XFLOPS(23,23,23)<NFLOPS(MPARM,NPARM,KPARM))?column(FLOPS):1/0) notitle smooth unique with boxes linetype 1 linecolor "grey"

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance and Memory Bandwidth (CDF)" }
set xlabel "Probability\n\n{/=8 Minimum: ".sprintf(ACC, MINFLOPS)." GFLOP/s  Geo. Mean: ".sprintf(ACC, GEO)." GFLOP/s  Median: ".sprintf(ACC, MED)." GFLOP/s  Maximum: ".sprintf(ACC, MAXFLOPS)." GFLOP/s}"
set ylabel "GB/s"
set y2label "GFLOP/s"
set format x "%g%%"
set format y "%g"
set format y2 "%g"
set ytics nomirror
set y2tics nomirror
set grid x y2 linecolor "grey"
set xrange [0:100]
set yrange [0:*]
set y2range [0:*]
set fit quiet
f(x) = b * x + a
fit f(x) BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 via a, b
g(x) = (x - a) / b
x50 = 0.5 * (100 + MAX(0, g(0)))
h(x) = d * x + c
dx = 100 / FREQN
fit [x50-1.5*dx:x50+1.5*dx] h(x) BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 via c, d
set arrow from x50, second h(x50) to x50, second 0 front
set arrow from x50, second h(x50) to 100, second h(x50) front
set label sprintf("%.0f%%", x50) at x50, second 0.5 * h(x50) left offset 1 front
set label sprintf(ACC." GFLOP/s", h(x50)) at 0.5 * (x50 + 100.0), second h(x50) centre offset 0, -1 front
set key left invert
plot  BASENAME."-perf-mbw.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 axes x1y1 title "Memory Bandwidth" with lines linecolor "grey", \
      BASENAME."-perf-cdf.dat" using (("".strcol(3)."" eq "i")?(100*$2/FREQSUM):(1/0)):1 axes x1y2 title "Compute Performance" with lines linewidth 2

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Memory Bandwidth" }
set grid x y2 linecolor "grey"
set key left #spacing 0.5
set ytics format ""
set y2tics nomirror
set y2label "GB/s"
set xlabel "Problem Size (MNK**1/3)"
set autoscale fix
plot  BASENAME."-perf.dat" using ((column(MPARM)*column(NPARM)*column(KPARM))**(1.0/3.0)):(BW(MPARM,NPARM,KPARM,FLOPS,SSIZE,MEMBW,8)) notitle smooth sbezier with lines linecolor "grey", \
                        "" using ((column(MPARM)*column(NPARM)*column(KPARM))**(1.0/3.0)):(BW(MPARM,NPARM,KPARM,FLOPS,SSIZE,MEMBW,8)) notitle smooth unique with points pointtype 7 pointsize 0.1

reset
if (MULTI<=0) { set output "".FILECOUNT."-".FILENAME; FILECOUNT = FILECOUNT + 1 }
if (MULTI>-1) { set title "Performance and Arithmetic Intensity" }
set grid x y2 linecolor "grey"
set key left #spacing 0.5
set ytics format ""
set y2tics nomirror
set y2label "GFLOP/s"
set xlabel "FLOPS/Byte"
set autoscale fix
plot  BASENAME."-perf.dat" using (AI(MPARM,NPARM,KPARM,8)):FLOPS notitle smooth sbezier with lines linecolor "grey", \
                        "" using (AI(MPARM,NPARM,KPARM,8)):FLOPS notitle smooth unique with points pointtype 7 pointsize 0.1


Add fourth point to define unique polynomial.

set terminal png transparent nointerlace \
    font "lucon.ttf,20" \
    size 1920,1080 nocrop \
    noenhanced \
    background '#FFFFFF'

set output "cubic-2.png"
set encoding utf8

set style line 101 linetype 1 linewidth 5 linecolor rgbcolor '#000000'
set style line 102 linetype 2 linewidth 4 linecolor rgbcolor '#999999'
set style line 103 linetype 3 linewidth 4 linecolor rgbcolor '#A00000'
set style line 104 linetype 4 linewidth 4 linecolor rgbcolor '#FF0000'
set style line 105 linetype 5 linewidth 4 linecolor rgbcolor '#007000'
set style line 106 linetype 6 linewidth 6 linecolor rgbcolor '#00FF00'
set style line 107 linetype 7 linewidth 4 linecolor rgbcolor '#0000A0'
set style line 108 linetype 8 linewidth 4 linecolor rgbcolor '#1E90FF'
set style line 109 linetype 9 linewidth 4 linecolor rgbcolor '#A020F0'

set key off

# TODO: set origin and size as options or calculate.
set origin 0.02,0
set size 0.98,1
set ytics
set xtics
set border
set colorbox
set xrange [-7:5]
set grid xtics
set mxtics
set xlabel "x" font "lucon.ttf,30"

set grid ytics
set mytics
set my2tics
set ylabel "f(x)" font "lucon.ttf,30"
#set ytics nomirror
#set y2tics nomirror
set label 1 "2005-2017 © eigenholser" \
    at screen 0.99,0.014 right font "times.ttf,12"
set label 2 "f(x) = x^3 + 3x^2 - 13x + 42" at screen 0.21,0.865 left font "times.ttf,30"
set label 3 "f(x) = α(x^3 + x^2 - 26x + 24) + 2x^2 + 13x + 18" at screen 0.21,0.830 left font "times.ttf,30"
set title "Cubic polynomials passing through points (-4,50) and (1,40)" font "lucon.ttf,30"

# Greek α symbol is U03B1
f(x) = x**3 + 3*x**2 - 13.0*x + 42
x1 = -6
x2 = 1
x3 = 4
x4 = -3
set style line 1 pointtype 7 linecolor rgb '#000000' pointsize 4
plot \
    (-34.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (-21.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (-13.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (-8.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (8.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (13.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (21.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (34.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    f(x) axes x1y1 not with lines linestyle 106, \
    '+' using ($0 == 0 ? x1 : NaN):(f(x1)):(sprintf('(%.1d,%.1d)', x1, f(x1))) \
    with labels offset char -2,2.5 left textcolor rgb 'blue' \
    point linestyle 1 notitle, \
    '+' using ($0 == 0 ? x2 : NaN):(f(x2)):(sprintf('(%.1d,%.1d)', x2, f(x2))) \
    with labels offset char -4.0,3 left textcolor rgb 'blue' \
    point linestyle 1 notitle, \
    '+' using ($0 == 0 ? x3 : NaN):(f(x3)):(sprintf('(%.1d,%.1d)', x3, f(x3))) \
    with labels offset char -3.0,2.0 left textcolor rgb 'blue' \
    point linestyle 1 notitle, \
    '+' using ($0 == 0 ? x4 : NaN):(f(x4)):(sprintf('(%.1d,%.1d)', x4, f(x4))) \
    with labels offset char -2.5,0.75 left textcolor rgb 'blue' \
    point linestyle 1 notitle

set terminal png transparent nointerlace \
    font "lucon.ttf,20" \
    size 1920,1080 nocrop \
    noenhanced \
    background '#FFFFFF'

set output "cubic-2.png"
set encoding utf8

set style line 101 linetype 1 linewidth 5 linecolor rgbcolor '#000000'
set style line 102 linetype 2 linewidth 4 linecolor rgbcolor '#999999'
set style line 103 linetype 3 linewidth 4 linecolor rgbcolor '#A00000'
set style line 104 linetype 4 linewidth 4 linecolor rgbcolor '#FF0000'
set style line 105 linetype 5 linewidth 4 linecolor rgbcolor '#007000'
set style line 106 linetype 6 linewidth 6 linecolor rgbcolor '#00FF00'
set style line 107 linetype 7 linewidth 4 linecolor rgbcolor '#0000A0'
set style line 108 linetype 8 linewidth 4 linecolor rgbcolor '#1E90FF'
set style line 109 linetype 9 linewidth 4 linecolor rgbcolor '#A020F0'

set key off

# TODO: set origin and size as options or calculate.
set origin 0.02,0
set size 0.98,1
set ytics
set xtics
set border
set colorbox
set xrange [-7:5]
set grid xtics
set mxtics
set xlabel "x" font "lucon.ttf,30"

set grid ytics
set mytics
set my2tics
set ylabel "f(x)" font "lucon.ttf,30"
#set ytics nomirror
#set y2tics nomirror
set label 1 "2005-2017 © eigenholser" \
    at screen 0.99,0.014 right font "times.ttf,12"
set label 2 "f(x) = x^3 + 3x^2 - 13x + 42" at screen 0.21,0.865 left font "times.ttf,30"
set label 3 "f(x) = α(x^3 + x^2 - 26x + 24) + 2x^2 + 13x + 18" at screen 0.21,0.830 left font "times.ttf,30"
set title "Cubic polynomials passing through points (-4,50) and (1,40)" font "lucon.ttf,30"

# Greek α symbol is U03B1
f(x) = x**3 + 3*x**2 - 13.0*x + 42
x1 = -6
x2 = 1
x3 = 4
set style line 1 pointtype 7 linecolor rgb '#000000' pointsize 4
plot \
    (-34.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (-21.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (-13.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (-8.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (8.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (13.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (21.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    (34.0*(x**3 + x**2 - 26.0*x + 24) + 2.0*x**2 + 13.0*x + 18) axes x1y1 not with lines linestyle 102, \
    f(x) axes x1y1 not with lines linestyle 106, \
    '+' using ($0 == 0 ? x1 : NaN):(f(x1)):(sprintf('(%.1d,%.1d)', x1, f(x1))) \
    with labels offset char -2,2.5 left textcolor rgb 'blue' \
    point linestyle 1 notitle, \
    '+' using ($0 == 0 ? x2 : NaN):(f(x2)):(sprintf('(%.1d,%.1d)', x2, f(x2))) \
    with labels offset char -4.0,3 left textcolor rgb 'blue' \
    point linestyle 1 notitle, \
    '+' using ($0 == 0 ? x3 : NaN):(f(x3)):(sprintf('(%.1d,%.1d)', x3, f(x3))) \
    with labels offset char -4.0,3 left textcolor rgb 'blue' \
    point linestyle 1 notitle


change event process plot to lines

change event process plot to lines

# Gnuplot script file for plotting data
reset
set terminal png
set samples 10000
set   autoscale                        # scale axes automatically
unset log                              # remove any log-scaling
unset label                            # remove any previous labels
set xtic auto                          # set xtics automatically
set ytic auto                          # set ytics automatically
set title "Event Process Plot ".filename
set xlabel "Time(ms)"

set ylabel "Throughput"
set y2label "Latency"

set ytics nomirror in
set y2tics nomirror

set yrange [0:*]
set y2range [0:*]

# filename is a parameter
plot filename u 1:2 t 'Throughput' with lines axes x1y1,\
"" u 1:4 t 'Latency' with lines axes x1y2
#

# Gnuplot script file for plotting data
reset
set terminal png
set samples 10000
set   autoscale                        # scale axes automatically
unset log                              # remove any log-scaling
unset label                            # remove any previous labels
set xtic auto                          # set xtics automatically
set ytic auto                          # set ytics automatically
set title "Event Process Plot ".filename
set xlabel "Time(ms)"

set ylabel "Throughput"
set y2label "Latency"

set ytics nomirror in
set y2tics nomirror

set yrange [0:*]
set y2range [0:*]

# filename is a parameter
plot filename u 1:2 t 'Throughput' with points pointtype 7 pointsize 1 axes x1y1,\
"" u 1:4 t 'Latency' with points pointtype 7 pointsize 1 axes x1y2
#


y2tics needs format on right graph

y2tics needs format on right graph

#!/usr/bin/env gnuplot

# graph of humidity (and temperature)

# datafile
ifnameh = "/tmp/domod/mysql/sql22h.csv"
ifnamed = "/tmp/domod/mysql/sql22d.csv"
ifnamew = "/tmp/domod/mysql/sql22w.csv"
set output ofname = "/tmp/domod/site/img/day22.png"

# ******************************************************* General settings *****
set terminal png truecolor enhanced font "Vera" 9 size 1280,320
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
# Positions of split between graphs
LMPOS = 0.40
MRPOS = 0.75

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 2 name "X" nooutput

Xh_min = X_min + utc_offset - 946684800
Xh_max = X_max + utc_offset - 946684800

# stats to be calculated here for Y-axes
#stats ifnameh using 4 name "Y" nooutput
#Yh_min = Y_min * 0.90
#Yh_max = Y_max * 1.10

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 2 name "X" nooutput

Xd_min = X_min + utc_offset - 946684800
Xd_max = X_max + utc_offset - 946684800

# stats to be calculated here for Y-axes
#stats ifnamed using 4 name "Y" nooutput
#Yd_min = Y_min * 0.90
#Yd_max = Y_max * 1.10

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 2 name "X" nooutput
Xw_min = X_min + utc_offset - 946684800
Xw_max = X_max + utc_offset - 946684800

# stats for Y-axis
stats ifnamew using 3 name "Y" nooutput
Yw_min = Y_min -1
Yw_max = Y_max +1

# stats for Y2-axis
stats ifnamew using 4 name "Y2" nooutput
Y2w_min = Y2_min -1
Y2w_max = Y2_max +1

set multiplot layout 1, 3 title "Humidity & Temperature (DHT22) -=- ".strftime("%Y-%m-%d %H:%M", time(0))

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Humidity [%]"
set yrange [ Yw_min : Yw_max ]

# **************************************************************** Y2-axis *****
set y2label " "
set y2tics format " "``
set y2range [ Y2_min : Y2_max ]

# ***************************************************************** Legend *****
set key inside top left horizontal box
set key samplen 1
set key reverse Left

# ***************************************************************** Output *****
set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder
set rmargin at screen LMPOS

# ***** PLOT *****
plot ifnamew \
      using ($2+utc_offset):3 title " Humidity [%]"      with points pt 5 ps 0.2 fc rgb "#ccbb0000" \
  ,'' using ($2+utc_offset):4 title " Temperature [degC]" axes x1y2  with dots

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Yw_min : Yw_max ]

# **************************************************************** Y2-axis *****
set y2label " "
set y2tics format " "
set y2range [ Y2_min : Y2_max ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($2+utc_offset):3 with points pt 5 ps 0.2 fc rgb "#ccbb0000" \
  ,'' using ($2+utc_offset):4 axes x1y2  with dots

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Yw_min : Yw_max ]

# **************************************************************** Y2-axis *****
set y2label "Temperature [degC]"
set y2tics format "%2.1f"
set y2range [ Y2_min : Y2_max ]
set y2tics border

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
set lmargin at screen MRPOS+0.001
set rmargin -1

# ***** PLOT *****
plot ifnameh \
      using ($2+utc_offset):3 with points pt 5 ps 0.2 fc rgb "#ccbb0000" \
  ,'' using ($2+utc_offset):4 axes x1y2  with dots

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot

#!/usr/bin/env gnuplot

# graph of humidity (and temperature)

# datafile
ifnameh = "/tmp/domod/mysql/sql22h.csv"
ifnamed = "/tmp/domod/mysql/sql22d.csv"
ifnamew = "/tmp/domod/mysql/sql22w.csv"
set output ofname = "/tmp/domod/site/img/day22.png"

# ******************************************************* General settings *****
set terminal png truecolor enhanced font "Vera" 9 size 1280,320
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
# Positions of split between graphs
LMPOS = 0.40
MRPOS = 0.75

# ********************************************************* Statistics (R) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnameh using 2 name "X" nooutput

Xh_min = X_min + utc_offset - 946684800
Xh_max = X_max + utc_offset - 946684800

# stats to be calculated here for Y-axes
#stats ifnameh using 4 name "Y" nooutput
#Yh_min = Y_min * 0.90
#Yh_max = Y_max * 1.10

# ********************************************************* Statistics (M) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamed using 2 name "X" nooutput

Xd_min = X_min + utc_offset - 946684800
Xd_max = X_max + utc_offset - 946684800

# stats to be calculated here for Y-axes
#stats ifnamed using 4 name "Y" nooutput
#Yd_min = Y_min * 0.90
#Yd_max = Y_max * 1.10

# ********************************************************* Statistics (L) *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifnamew using 2 name "X" nooutput
Xw_min = X_min + utc_offset - 946684800
Xw_max = X_max + utc_offset - 946684800

# stats for Y-axis
stats ifnamew using 3 name "Y" nooutput
Yw_min = Y_min -1
Yw_max = Y_max +1

# stats for Y2-axis
stats ifnamew using 4 name "Y2" nooutput
Y2w_min = Y2_min -1
Y2w_max = Y2_max +1

set multiplot layout 1, 3 title "Humidity & Temperature (DHT22) -=- ".strftime("%Y-%m-%d %H:%M", time(0))

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                       LEFT PLOT: past week
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past week"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%a %d"            # Display time in 24 hour notation on the X axis
set xrange [ Xw_min : Xw_max ]

# ***************************************************************** Y-axis *****
set ylabel "Humidity [%]"
set yrange [ Yw_min : Yw_max ]

# **************************************************************** Y2-axis *****
set y2label " "
set y2tics format " "``
set y2range [ Y2_min : Y2_max ]

# ***************************************************************** Legend *****
set key inside top left horizontal box
set key samplen 1
set key reverse Left

# ***************************************************************** Output *****
set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
#set object 1 rect from screen 0,0 to screen 1,1 behind
#set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
#set object 2 rect from graph 0,0 to graph 1,1 behind
#set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder
set rmargin at screen LMPOS

# ***** PLOT *****
plot ifnamew \
      using ($2+utc_offset):3 title " Humidity [%]"      with points pt 5 ps 0.2 fc rgb "#ccbb0000" \
  ,'' using ($2+utc_offset):4 title " Temperature [degC]" axes x1y2  with dots

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                     MIDDLE PLOT:  past day
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past day"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xd_min : Xd_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Yw_min : Yw_max ]

# **************************************************************** Y2-axis *****
set y2label " "
set y2tics format " "
set y2range [ Y2_min : Y2_max ]

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set lmargin at screen LMPOS+0.001
set rmargin at screen MRPOS

# ***** PLOT *****
plot ifnamed \
      using ($2+utc_offset):3 with points pt 5 ps 0.2 fc rgb "#ccbb0000" \
  ,'' using ($2+utc_offset):4 axes x1y2  with dots

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                      RIGHT PLOT: past hour
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

# ***************************************************************** X-axis *****
set xlabel "past hour"       # X-axis label
set xdata time               # Data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xrange [ Xh_min : Xh_max ]

# ***************************************************************** Y-axis *****
set ylabel " "
set ytics format " "
set yrange [ Yw_min : Yw_max ]

# **************************************************************** Y2-axis *****
set y2label "Temperature [degC]"
set y2range [ Y2_min : Y2_max ]
set y2tics border

# ***************************************************************** Legend *****
unset key

# ***************************************************************** Output *****
set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
set lmargin at screen MRPOS+0.001
set rmargin -1

# ***** PLOT *****
plot ifnameh \
      using ($2+utc_offset):3 with points pt 5 ps 0.2 fc rgb "#ccbb0000" \
  ,'' using ($2+utc_offset):4 axes x1y2  with dots

# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#                                                                 FINALIZING
# %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

unset multiplot


Newplot

Newplot

#!/usr/bin/env gnuplot
set term postscript enhanced color 20

set log xy
se gri
set xlabel "memory footprint(MB)"
set ylabel "load bandwidth (GB/s)"
set arrow from 40,10 to 40,1000 nohead lc 2
set arrow from 4,10 to 4,1000 nohead lc 2
set arrow from 0.5,10 to 0.5,1000 nohead lc 2
set label 4 at first 100,12 "Memory"
set label 3 at first 10,12 "L3"
set label 2 at first 1,12 "L2"
set label 1 at first 0.1,12 "L1"

set out "benchmark-stream-xeon.eps"
plot 'benchmark-stream-xeon.txt' u (8*$1/2**20):(2*$4) lw 2 ps 4 t ""
set out "benchmark-stream-3d.eps"
plot 'benchmark-stream-3d.txt' u (8*$1/2**20):(2*$4) lw 2 ps 4 t ""

#!/usr/bin/env gnuplot
set term postscript enhanced color 20

set log xy
se gri
set out "benchmark-stream-xeon.eps"
set xlabel "memory footprint(MB)"
set ylabel "load bandwidth (GB/s)"
set arrow from 40,10 to 40,1000 nohead lc 2
set arrow from 4,10 to 4,1000 nohead lc 2
set arrow from 0.5,10 to 0.5,1000 nohead lc 2
set label 4 at first 100,12 "Memory"
set label 3 at first 10,12 "L3"
set label 2 at first 1,12 "L2"
set label 1 at first 0.1,12 "L1"
plot 'benchmark-stream-xeon.txt' u (8*$1/2**20):(2*$4) lw 2 ps 4 t ""


remove plot.gnuplot

remove plot.gnuplot

#!/usr/bin/gnuplot -persist
#
#
#    	G N U P L O T
#    	Version 4.2 patchlevel 3
#    	last modified Mar 2008
#    	System: Linux 2.6.25-gentoo-r6
#
#    	Copyright (C) 1986 - 1993, 1998, 2004, 2007, 2008
#    	Thomas Williams, Colin Kelley and many others
#
#    	Type `help` to access the on-line reference manual.
#    	The gnuplot FAQ is available from http://www.gnuplot.info/faq/
#
#    	Send bug reports and suggestions to <http://sourceforge.net/projects/gnuplot>
#
# set terminal x11
# set output
unset clip points
set clip one
unset clip two
set bar 1.000000
set border 31 front linetype -1 linewidth 1.000
set xdata
set ydata
set zdata
set x2data
set y2data
set timefmt x "%d/%m/%y,%H:%M"
set timefmt y "%d/%m/%y,%H:%M"
set timefmt z "%d/%m/%y,%H:%M"
set timefmt x2 "%d/%m/%y,%H:%M"
set timefmt y2 "%d/%m/%y,%H:%M"
set timefmt cb "%d/%m/%y,%H:%M"
set boxwidth
set style fill  empty border
set style rectangle back fc lt -3 fillstyle  solid 1.00 border -1
set dummy x,y
set format x "% g"
set format y "% g"
set format x2 "% g"
set format y2 "% g"
set format z "% g"
set format cb "% g"
set angles radians
unset grid
set key title ""
set key inside right top vertical Right noreverse enhanced autotitles nobox
set key noinvert samplen 4 spacing 1 width 0 height 0
unset label
unset arrow
set style increment default
unset style line
unset style arrow
set style histogram clustered gap 2 title  offset character 0, 0, 0
unset logscale
set offsets 0, 0, 0, 0
set pointsize 1
set encoding default
unset polar
unset parametric
unset decimalsign
set view 60, 30, 1, 1
set samples 100, 100
set isosamples 10, 10
set surface
unset contour
set clabel '%8.3g'
set mapping cartesian
set datafile separator whitespace
unset hidden3d
set cntrparam order 4
set cntrparam linear
set cntrparam levels auto 5
set cntrparam points 5
set size ratio 0 1,1
set origin 0,0
set style data points
set style function lines
set xzeroaxis linetype -2 linewidth 1.000
set yzeroaxis linetype -2 linewidth 1.000
set zzeroaxis linetype -2 linewidth 1.000
set x2zeroaxis linetype -2 linewidth 1.000
set y2zeroaxis linetype -2 linewidth 1.000
set ticslevel 0.5
set mxtics default
set mytics default
set mztics default
set mx2tics default
set my2tics default
set mcbtics default
set xtics border in scale 1,0.5 mirror norotate  offset character 0, 0, 0
set xtics autofreq
set ytics border in scale 1,0.5 mirror norotate  offset character 0, 0, 0
set ytics autofreq
set ztics border in scale 1,0.5 nomirror norotate  offset character 0, 0, 0
set ztics autofreq
set nox2tics
set noy2tics
set cbtics border in scale 1,0.5 mirror norotate  offset character 0, 0, 0
set cbtics autofreq
set title "game count - win rate curve"
set title  offset character 0, 0, 0 font "" norotate
set timestamp bottom
set timestamp ""
set timestamp  offset character 0, 0, 0 font "" norotate
set rrange [ * : * ] noreverse nowriteback  # (currently [0.00000:10.0000] )
set trange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
set urange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
set vrange [ * : * ] noreverse nowriteback  # (currently [-5.00000:5.00000] )
set xlabel "game_count"
set xlabel  offset character 0, 0, 0 font "" textcolor lt -1 norotate
set x2label ""
set x2label  offset character 0, 0, 0 font "" textcolor lt -1 norotate
set xrange [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set x2range [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set ylabel "rate"
set ylabel  offset character 0, 0, 0 font "" textcolor lt -1 rotate by 90
set y2label ""
set y2label  offset character 0, 0, 0 font "" textcolor lt -1 rotate by 90
set yrange [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set y2range [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set zlabel ""
set zlabel  offset character 0, 0, 0 font "" textcolor lt -1 norotate
set zrange [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set cblabel ""
set cblabel  offset character 0, 0, 0 font "" textcolor lt -1 rotate by 90
set cbrange [ * : * ] noreverse nowriteback  # (currently [-10.0000:10.0000] )
set zero 1e-08
set lmargin -1
set bmargin -1
set rmargin -1
set tmargin -1
set locale "C"
set pm3d explicit at s
set pm3d scansautomatic
set pm3d interpolate 1,1 flush begin noftriangles nohidden3d corners2color mean
set palette positive nops_allcF maxcolors 0 gamma 1.5 color model RGB
set palette rgbformulae 7, 5, 15
set colorbox default
set colorbox vertical origin screen 0.9, 0.2, 0 size screen 0.05, 0.6, 0 front bdefault
set loadpath
set fontpath
set fit noerrorvariables
GNUTERM = "x11"
plot 'plot' u 1:2 w l title "win rate", 'plot' u 1:3 w l title "expected win rate"
#    EOF


Add linear polynomial. Remove extra cruft.

set terminal png transparent nointerlace \
    font "lucon.ttf,20" \
    size 1920,1080 nocrop \
    noenhanced \
    background '#FFFFFF'

set output "background-title.png"
set encoding utf8

set style line 101 linetype 1 linewidth 5 linecolor rgbcolor '#000000'
set style line 102 linetype 2 linewidth 4 linecolor rgbcolor '#999999'
set style line 103 linetype 3 linewidth 4 linecolor rgbcolor '#A00000'
set style line 104 linetype 4 linewidth 4 linecolor rgbcolor '#FF0000'
set style line 105 linetype 5 linewidth 4 linecolor rgbcolor '#007000'
set style line 106 linetype 6 linewidth 6 linecolor rgbcolor '#00FF00'
set style line 107 linetype 7 linewidth 4 linecolor rgbcolor '#0000A0'
set style line 108 linetype 8 linewidth 4 linecolor rgbcolor '#1E90FF'
set style line 109 linetype 9 linewidth 4 linecolor rgbcolor '#A020F0'

set key off

# TODO: set origin and size as options or calculate.
set origin 0.02,0
set size 0.98,1
set ytics
set xtics
set border
set colorbox
set xrange [-3:3]
set grid xtics
set mxtics
set xlabel "x" font "lucon.ttf,30"

set format y ""
set format x ""
set grid ytics
set mytics
set my2tics
set ylabel "f(x)" font "lucon.ttf,30"
#set ytics nomirror
#set y2tics nomirror
set label 1 "2005-2017 © eigenholser" \
    at screen 0.99,0.014 right font "times.ttf,12"
#set label 2 "f(x) = x^3 + 3x^2 - 13x + 42" at screen 0.21,0.865 left font "times.ttf,30"
#set label 3 "f(x) = α(x^3 + x^2 - 26x + 24) + 2x^2 + 13x + 18" at screen 0.21,0.830 left font "times.ttf,30"
#set title "Cubic polynomials passing through points (-4,50) and (1,40)" font "lucon.ttf,30"

set style line 1 pointtype 7 linecolor rgb '#000000' pointsize 4
plot \
    -120*x - 300 axes x1y1 not with lines linestyle 102, \
    90*x**2 -20*x - 90 axes x1y1 not with lines linestyle 102, \
    12*x**3 - 8*x**2 - 20*x - 100  axes x1y1 not with lines linestyle 102, \
    2*x**4 - 19*x**3 + 3*x**2 + x - 300 axes x1y1 not with lines linestyle 102, \
    260*x  axes x1y1 not with lines linestyle 102

set terminal png transparent nointerlace \
    font "lucon.ttf,20" \
    size 1920,1080 nocrop \
    noenhanced \
    background '#FFFFFF'

set output "background-title.png"
set encoding utf8

set style line 101 linetype 1 linewidth 5 linecolor rgbcolor '#000000'
set style line 102 linetype 2 linewidth 4 linecolor rgbcolor '#999999'
set style line 103 linetype 3 linewidth 4 linecolor rgbcolor '#A00000'
set style line 104 linetype 4 linewidth 4 linecolor rgbcolor '#FF0000'
set style line 105 linetype 5 linewidth 4 linecolor rgbcolor '#007000'
set style line 106 linetype 6 linewidth 6 linecolor rgbcolor '#00FF00'
set style line 107 linetype 7 linewidth 4 linecolor rgbcolor '#0000A0'
set style line 108 linetype 8 linewidth 4 linecolor rgbcolor '#1E90FF'
set style line 109 linetype 9 linewidth 4 linecolor rgbcolor '#A020F0'

set key off

# TODO: set origin and size as options or calculate.
set origin 0.02,0
set size 0.98,1
set ytics
set xtics
set border
set colorbox
set xrange [-3:3]
set grid xtics
set mxtics
set xlabel "x" font "lucon.ttf,30"

set format y ""
set format x ""
set grid ytics
set mytics
set my2tics
set ylabel "f(x)" font "lucon.ttf,30"
#set ytics nomirror
#set y2tics nomirror
set label 1 "2005-2017 © eigenholser" \
    at screen 0.99,0.014 right font "times.ttf,12"
#set label 2 "f(x) = x^3 + 3x^2 - 13x + 42" at screen 0.21,0.865 left font "times.ttf,30"
#set label 3 "f(x) = α(x^3 + x^2 - 26x + 24) + 2x^2 + 13x + 18" at screen 0.21,0.830 left font "times.ttf,30"
#set title "Cubic polynomials passing through points (-4,50) and (1,40)" font "lucon.ttf,30"

# Greek α symbol is U03B1
f(x) = x**3 + 3*x**2 - 13.0*x + 42
x1 = -6
x2 = 1
x3 = 4
set style line 1 pointtype 7 linecolor rgb '#000000' pointsize 4
plot \
    -120*x - 300 axes x1y1 not with lines linestyle 102, \
    90*x**2 -20*x - 90 axes x1y1 not with lines linestyle 102, \
    12*x**3 - 8*x**2 - 20*x - 100  axes x1y1 not with lines linestyle 102, \
    2*x**4 - 19*x**3 + 3*x**2 + x - 300 axes x1y1 not with lines linestyle 102


Tests.

Tests.

:- include(misc(common)).

:- use_module(misc(util), []).

database('prolongo').
collection('testcoll').

up(Mongo) :-
    mongo:new_mongo(Mongo0),
    database(Database),
    mongo:use_database(Mongo0, Database, Mongo).

down(Mongo) :-
    mongo:free_mongo(Mongo).

:- begin_tests('mongo:update/4').

test('update normal', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    mongo:delete(Mongo, Collection, [hello-world]),
    mongo:delete(Mongo, Collection, [hello-me]),
    mongo:insert(Mongo, Collection, [hello-world]),
    mongo:update(Mongo, Collection, [hello-world], [hello-me]),
    mongo:find_one(Mongo, Collection, [hello-me], Doc),
    bson:doc_get(Doc, hello, me).

:- end_tests('mongo:update/4').

:- begin_tests('mongo:update/5').

test('update upsert', [setup(up(Conn)),cleanup(down(Conn))]) :-
    % xxx collection(Collection),
    mongo:get_database(Conn, prolongo, Db),
    mongo:get_collection(Db, testcoll, Coll),
    mongo:delete(Coll, [hello-world]),
    mongo:delete(Coll, [hello-me]),
    mongo:update(Coll, [hello-world], [hello-me], [upsert]).
    %mongo:find_one(Coll, [hello-me], Doc),
    %bson:doc_get(Doc, hello, me).

test('update multi', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Coll),
    mongo:delete(Mongo, Coll, [hello-world]),
    mongo:delete(Mongo, Coll, [hello-me]),
    mongo:insert(Mongo, Coll, [hello-world,num-1]),
    mongo:insert(Mongo, Coll, [hello-world,num-2]),
    mongo:insert(Mongo, Coll, [hello-world,num-3]),
    mongo:update(Mongo, Coll, [hello-world], ['$inc'-[num-10]], [multi]),
    mongo:find(Mongo, Coll, [hello-world], [], 0, 3, _Cursor, [Doc1,Doc2,Doc3]),
    % XXX Maybe this sort order is not guaranteed?
    bson:doc_get(Doc1, num, 11),
    bson:doc_get(Doc2, num, 12),
    bson:doc_get(Doc3, num, 13).

:- end_tests('mongo:update/5').

:- begin_tests('mongo:delete/3').

test('delete', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    mongo:insert(Mongo, Collection, [hello-world]),
    mongo:find(Mongo, Collection, [hello-world], [], 0, 0, _Cursor1, [_|_]),
    mongo:delete(Mongo, Collection, [hello-world]),
    mongo:find(Mongo, Collection, [hello-world], [], 0, 0, _Cursor2, []).

:- end_tests('mongo:delete/3').

:- begin_tests('mongo:find/8').

test('cursor', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    mongo:delete(Mongo, Collection, [hello-world]),
    mongo:insert(Mongo, Collection, [hello-world,number-1]),
    mongo:insert(Mongo, Collection, [hello-world,number-2]),
    mongo:insert(Mongo, Collection, [hello-world,number-3]),
    mongo:insert(Mongo, Collection, [hello-world,number-4]),
    mongo:insert(Mongo, Collection, [hello-world,number-5]),
    mongo:insert(Mongo, Collection, [hello-world,number-6]),
    mongo:insert(Mongo, Collection, [hello-world,number-7]),
    mongo:insert(Mongo, Collection, [hello-world,number-8]),
    mongo:insert(Mongo, Collection, [hello-world,number-9]),
    mongo:find(Mongo, Collection, [hello-world], [number-1], 3, 3, Cursor0, Docs0),
    Docs0 =
    [
        ['_id'-object_id(_),number-_],
        ['_id'-object_id(_),number-_],
        ['_id'-object_id(_),number-_]
    ],
    mongo:cursor_has_more(Cursor0),
    mongo:cursor_get_more(Cursor0, 3, Docs1, Cursor1),
    Docs1 =
    [
        ['_id'-object_id(_),number-_],
        ['_id'-object_id(_),number-_],
        ['_id'-object_id(_),number-_]
    ],
    mongo:cursor_has_more(Cursor1),
    mongo:cursor_get_more(Cursor1, 3, Docs2, Cursor2),
    Docs2 =
    [
    ],
    \+ mongo:cursor_has_more(Cursor2).

test('cursor exhaust', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    mongo:delete(Mongo, Collection, [hello-world]),
    insert_n(Mongo, Collection, 1000),
    mongo:find(Mongo, Collection, [hello-world], [number-1], 0, 0, Cursor, Docs0),
    mongo:cursor_exhaust(Cursor, DocsRest),
    lists:length(Docs0, N0),
    lists:length(DocsRest, N),
    1000 is N0 + N.

insert_n(_Mongo, _Coll, 0) :- !.
insert_n(Mongo, Coll, N) :-
    mongo:insert(Mongo, Coll, [hello-world,number-N]),
    N1 is N - 1,
    insert_n(Mongo, Coll, N1).

:- end_tests('mongo:find/8').

:- begin_tests('mongo:find_one/4,5').

test('entire doc', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    Doc = [hello-world, number-42],
    mongo:insert(Mongo, Collection, Doc),
    mongo:find_one(Mongo, Collection, Doc, Doc1),
    bson:doc_get(Doc1, number, 42).

test('entire doc', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    Doc = [hello-world, number-42],
    mongo:insert(Mongo, Collection, Doc),
    mongo:find_one(Mongo, Collection, Doc, Doc1),
    bson:doc_get(Doc1, number, 42).

test('return fields selector', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    Doc = [hello-world, number-42],
    mongo:insert(Mongo, Collection, Doc),
    Fields = [number-1],
    mongo:find_one(Mongo, Collection, Doc, Fields, Doc1),
    bson:doc_get(Doc1, '_id', object_id(_)), % Always returned.
    bson:doc_get(Doc1, number, 42),
    \+ bson:doc_get(Doc1, hello, world).

:- end_tests('mongo:find_one/4,5').

:- begin_tests('mongo:insert/3').

test('insert', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    util:ms_since_epoch(MilliSeconds),
    Document =
    [
        hello - [åäö,5.05],
        now   - utc(MilliSeconds)
    ],
    collection(Collection),
    mongo:insert(Mongo, Collection, Document).

:- end_tests('mongo:insert/3').

:- begin_tests('mongo:command/3').
/*
test('list database infos', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    mongo:list_database_infos(Mongo, DatabaseInfos),
    database(Database),
    bson:doc_get(DatabaseInfos, Database, Info),
    Info \== +null.
    %bson_format:pp(DatabaseInfos), nl.

test('list database names', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    mongo:list_database_names(Mongo, DatabaseNames),
    database(Database),
    core:memberchk(Database, DatabaseNames).
*/

% XXX this works now, but I need to fix cursors (only one is shown).
test('list collection names', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    mongo:list_collection_names(Mongo, Result),
    bson_format:pp(Result).

/*
test('drop collection',
[
    setup(up(Mongo)),
    cleanup(down(Mongo))
]) :-
    collection(Collection),
    mongo:drop_collection(Mongo, Collection, Result),
    write(Result), nl,
    mongo:doc_ok(Result).
*/

/*
% Takes a bit too long when MongoDB reallocates the collection later.
test('drop database', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    database(Database),
    mongo:drop_database(Mongo, Database, Result),
    bson:doc_get(Result, ok, 1.0).
*/

:- end_tests('mongo:command/3').

:- include(misc(common)).

:- use_module(misc(util), []).

database('prolongo').
collection('testcoll').

up(Mongo) :-
    mongo:new_mongo(Mongo0),
    database(Database),
    mongo:use_database(Mongo0, Database, Mongo).

down(Mongo) :-
    mongo:free_mongo(Mongo).

:- begin_tests('mongo:update/4').

test('update normal', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    mongo:delete(Mongo, Collection, [hello-world]),
    mongo:delete(Mongo, Collection, [hello-me]),
    mongo:insert(Mongo, Collection, [hello-world]),
    mongo:update(Mongo, Collection, [hello-world], [hello-me]),
    mongo:find_one(Mongo, Collection, [hello-me], Doc),
    bson:doc_get(Doc, hello, me).

:- end_tests('mongo:update/4').

:- begin_tests('mongo:update/5').

test('update upsert', [setup(up(Conn)),cleanup(down(Conn))]) :-
    % xxx collection(Collection),
    mongo:get_database(Conn, prolongo, Db),
    mongo:get_collection(Db, testcoll, Coll),
    mongo:delete(Coll, [hello-world]),
    mongo:delete(Coll, [hello-me]),
    mongo:update(Coll, [hello-world], [hello-me], [upsert]).
    %mongo:find_one(Coll, [hello-me], Doc),
    %bson:doc_get(Doc, hello, me).

test('update multi', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Coll),
    mongo:delete(Mongo, Coll, [hello-world]),
    mongo:delete(Mongo, Coll, [hello-me]),
    mongo:insert(Mongo, Coll, [hello-world,num-1]),
    mongo:insert(Mongo, Coll, [hello-world,num-2]),
    mongo:insert(Mongo, Coll, [hello-world,num-3]),
    mongo:update(Mongo, Coll, [hello-world], ['$inc'-[num-10]], [multi]),
    mongo:find(Mongo, Coll, [hello-world], [], 0, 3, _Cursor, [Doc1,Doc2,Doc3]),
    % XXX Maybe this sort order is not guaranteed?
    bson:doc_get(Doc1, num, 11),
    bson:doc_get(Doc2, num, 12),
    bson:doc_get(Doc3, num, 13).

:- end_tests('mongo:update/5').

:- begin_tests('mongo:delete/3').

test('delete', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    mongo:insert(Mongo, Collection, [hello-world]),
    mongo:find(Mongo, Collection, [hello-world], [], 0, 0, _Cursor1, [_|_]),
    mongo:delete(Mongo, Collection, [hello-world]),
    mongo:find(Mongo, Collection, [hello-world], [], 0, 0, _Cursor2, []).

:- end_tests('mongo:delete/3').

:- begin_tests('mongo:find/8').

test('cursor', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    mongo:delete(Mongo, Collection, [hello-world]),
    mongo:insert(Mongo, Collection, [hello-world,number-1]),
    mongo:insert(Mongo, Collection, [hello-world,number-2]),
    mongo:insert(Mongo, Collection, [hello-world,number-3]),
    mongo:insert(Mongo, Collection, [hello-world,number-4]),
    mongo:insert(Mongo, Collection, [hello-world,number-5]),
    mongo:insert(Mongo, Collection, [hello-world,number-6]),
    mongo:insert(Mongo, Collection, [hello-world,number-7]),
    mongo:insert(Mongo, Collection, [hello-world,number-8]),
    mongo:insert(Mongo, Collection, [hello-world,number-9]),
    mongo:find(Mongo, testcoll, [hello-world], [number-1], 3, 3, Cursor0, Docs0),
    Docs0 =
    [
        ['_id'-object_id(_),number-_],
        ['_id'-object_id(_),number-_],
        ['_id'-object_id(_),number-_]
    ],
    mongo:cursor_has_more(Cursor0),
    mongo:cursor_get_more(Cursor0, 3, Docs1, Cursor1),
    Docs1 =
    [
        ['_id'-object_id(_),number-_],
        ['_id'-object_id(_),number-_],
        ['_id'-object_id(_),number-_]
    ],
    mongo:cursor_has_more(Cursor1),
    mongo:cursor_get_more(Cursor1, 3, Docs2, Cursor2),
    Docs2 =
    [
    ],
    \+ mongo:cursor_has_more(Cursor2).

test('cursor exhaust', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    mongo:delete(Mongo, Collection, [hello-world]),
    mongo:insert(Mongo, Collection, [hello-world,number-1]),
    mongo:insert(Mongo, Collection, [hello-world,number-2]),
    mongo:insert(Mongo, Collection, [hello-world,number-3]),
    mongo:insert(Mongo, Collection, [hello-world,number-4]),
    mongo:insert(Mongo, Collection, [hello-world,number-5]),
    mongo:insert(Mongo, Collection, [hello-world,number-6]),
    mongo:insert(Mongo, Collection, [hello-world,number-7]),
    mongo:insert(Mongo, Collection, [hello-world,number-8]),
    mongo:insert(Mongo, Collection, [hello-world,number-9]),
    mongo:find(Mongo, testcoll, [hello-world], [number-1], 3, 3, Cursor0, Docs0),
    Docs0 =
    [
        ['_id'-object_id(_),number-4],
        ['_id'-object_id(_),number-5],
        ['_id'-object_id(_),number-6]
    ],
    mongo:cursor_exhaust(Cursor0, DocsRest),
    lists:length(DocsRest, 3).

:- end_tests('mongo:find/8').

:- begin_tests('mongo:find_one/4,5').

test('entire doc', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    Doc = [hello-world, number-42],
    mongo:insert(Mongo, Collection, Doc),
    mongo:find_one(Mongo, Collection, Doc, Doc1),
    bson:doc_get(Doc1, number, 42).

test('entire doc', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    Doc = [hello-world, number-42],
    mongo:insert(Mongo, Collection, Doc),
    mongo:find_one(Mongo, Collection, Doc, Doc1),
    bson:doc_get(Doc1, number, 42).

test('return fields selector', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    collection(Collection),
    Doc = [hello-world, number-42],
    mongo:insert(Mongo, Collection, Doc),
    Fields = [number-1],
    mongo:find_one(Mongo, Collection, Doc, Fields, Doc1),
    bson:doc_get(Doc1, '_id', object_id(_)), % Always returned.
    bson:doc_get(Doc1, number, 42),
    \+ bson:doc_get(Doc1, hello, world).

:- end_tests('mongo:find_one/4,5').

:- begin_tests('mongo:insert/3').

test('insert', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    util:ms_since_epoch(MilliSeconds),
    Document =
    [
        hello - [åäö,5.05],
        now   - utc(MilliSeconds)
    ],
    collection(Collection),
    mongo:insert(Mongo, Collection, Document).

:- end_tests('mongo:insert/3').

:- begin_tests('mongo:command/3').
/*
test('list database infos', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    mongo:list_database_infos(Mongo, DatabaseInfos),
    database(Database),
    bson:doc_get(DatabaseInfos, Database, Info),
    Info \== +null.
    %bson_format:pp(DatabaseInfos), nl.

test('list database names', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    mongo:list_database_names(Mongo, DatabaseNames),
    database(Database),
    core:memberchk(Database, DatabaseNames).
*/

% XXX this works now, but I need to fix cursors (only one is shown).
test('list collection names', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    mongo:list_collection_names(Mongo, Result),
    bson_format:pp(Result).

/*
test('drop collection',
[
    setup(up(Mongo)),
    cleanup(down(Mongo))
]) :-
    collection(Collection),
    mongo:drop_collection(Mongo, Collection, Result),
    write(Result), nl,
    mongo:doc_ok(Result).
*/

/*
% Takes a bit too long when MongoDB reallocates the collection later.
test('drop database', [setup(up(Mongo)),cleanup(down(Mongo))]) :-
    database(Database),
    mongo:drop_database(Mongo, Database, Result),
    bson:doc_get(Result, ok, 1.0).
*/

:- end_tests('mongo:command/3').


cleaned space

cleaned space

#
BHOME	=$(PWD)
#
CC	= g++-5
#
#
COMP	= -fcilkplus -lcilkrts -lm
COPTS	= -O3 -fstrict-aliasing
#
#
NOLINK= -c
#

all: sum dot normsq

sum: sum.o
	$(CC) $(COMP) -o sum sum.o

normsq: normsq.o
	$(CC) $(COMP) -o normsq normsq.o

dot: dot.o
	$(CC) $(COMP) -o dot dot.o

%.o: %.cpp
	$(CC) $(COPTS) $(COMP) $(NOLINK) $<

clean:
	rm -f *.o sum dot normsq


update plot

update plot

reset
dx=5.
n=2
total_box_width_relative=0.75
gap_width_relative=0.1
d_width=(gap_width_relative+total_box_width_relative)*dx/2.
reset
set term png truecolor
set output "profit.png"
set grid
set border linecolor rgbcolor "cyan"
set key textcolor rgbcolor "yellow"
set title "Coolerudo's Benchmark strcmp() vs sse4.2 strcmp()" textcolor rgbcolor "cyan"
set ylabel "CPU cycles" textcolor rgbcolor "yellow"
set xlabel "Cyan - simple strcmp()\nGreen - SSE4.2 strcmp()" textcolor rgbcolor "yellow"
set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"
set boxwidth total_box_width_relative/n relative
set style fill transparent solid 0.5 noborder
plot "bench.dat" u 1:2 w boxes lc rgb"green" notitle,\
     "bench.dat" u ($1+d_width):3 w boxes lc rgb"cyan" notitle

reset
dx=5.
n=2
total_box_width_relative=0.75
gap_width_relative=0.1
d_width=(gap_width_relative+total_box_width_relative)*dx/2.
reset
set term png truecolor
set output "profit.png"
set grid
set border linecolor rgbcolor "cyan"
set key textcolor rgbcolor "yellow"
set title "Coolerudo's Benchmark strcmp() vs sse4.2 strcmp()" textcolor rgbcolor "cyan"
set ylabel "CPU cycles" textcolor rgbcolor "yellow"
set xlabel "Green - simple strcmp()\nCyan - SSE4.2 strcmp()" textcolor rgbcolor "yellow"
set obj 1 rectangle behind from screen 0,0 to screen 1,1
set obj 1 fillstyle solid 1.0 fillcolor rgbcolor "black"
set boxwidth total_box_width_relative/n relative
set style fill transparent solid 0.5 noborder
plot "bench.dat" u 1:2 w boxes lc rgb"green" notitle,\
     "bench.dat" u ($1+d_width):3 w boxes lc rgb"cyan" notitle


tools: perftests gnuplot: set xrange and yrange

if (!exists("unrelfile")) unrelfile='out1.txt'
if (!exists("relfile")) relfile='out2.txt'
if (!exists("mytitle")) mytitle='Throughput tests'

set title mytitle
set xlabel "Packet size (bytes)"
set ylabel "Throughput (Gbps)"
set grid xtics lw 1 lt 0
set grid ytics lw 1 lt 0
set xtics 0,100,1500
set ytics 0,1,13
set xrange [-10:1500]
set yrange [-0.5:13.5]
set key left top
plot unrelfile using 1:($7/1000) title 'Unreliable sender' with linespoints lw 2 ps 1 pt 6 lt rgb "red", \
     unrelfile using 1:($9/1000) title 'Unreliable receiver' with linespoints lw 2 ps 1 pt 6 lt rgb "#00AA00", \
     relfile using 1:($7/1000) title 'Reliable sender/receiver' with linespoints lw 2 ps 1 pt 6 lt rgb "blue"
pause -1

if (!exists("unrelfile")) unrelfile='out1.txt'
if (!exists("relfile")) relfile='out2.txt'
if (!exists("mytitle")) mytitle='Throughput tests'

set title mytitle
set xlabel "Packet size (bytes)"
set ylabel "Throughput (Gbps)"
set grid xtics lw 1 lt 0
set grid ytics lw 1 lt 0
set xtics 0,100,1500
set ytics 0,1,13
set key left top
plot unrelfile using 1:($7/1000) title 'Unreliable sender' with linespoints lw 2 ps 1 pt 6 lt rgb "red", \
     unrelfile using 1:($9/1000) title 'Unreliable receiver' with linespoints lw 2 ps 1 pt 6 lt rgb "#00AA00", \
     relfile using 1:($7/1000) title 'Reliable sender/receiver' with linespoints lw 2 ps 1 pt 6 lt rgb "blue"
pause -1


update

update

# Tested with gnuplot 4.6 patchlevel 6

FN_IN = system("echo $FN_IN")
FN_OUT = system("echo $FN_OUT")

# Can be parameterized later
NUM_SSTABLES=17

# Get min and max values
set terminal unknown
set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"
plot \
FN_IN u 2:($4+$5) w points not
# GPVAL_DATA_[X|Y]_[MIN|MAX] are set now

set terminal pdfcairo enhanced size 3in, 2in
set output FN_OUT

#set tmargin at screen 0.975
#set bmargin at screen 0.152
#set lmargin at screen 0.185
#set rmargin at screen 0.940

set print "-"
print sprintf("SSTableMaxAccesses=%d", GPVAL_DATA_Y_MAX)

set xlabel "Time (min)" offset 0,0.3
set ylabel "Normalized # of accesses\nper sec by SSTables" offset 1.6,0

set border (1 + 2) back lc rgb "#808080"
set xtics nomirror scale 0.5,0 tc rgb "#808080"
set ytics nomirror scale 0.5,0 tc rgb "#808080" autofreq 0,5

set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"
set format x "%M"
#set format x ":%S"

# Draw the bottom line. Not really needed.
#set for [i=1:NUM_SSTABLES] arrow from GPVAL_DATA_X_MIN,i to GPVAL_DATA_X_MAX,i nohead lc rgb "#C0C0C0" front

set pointsize 0.02

MAX_HEIGHT=1.2*GPVAL_DATA_Y_MAX

set xrange [GPVAL_DATA_X_MIN:GPVAL_DATA_X_MAX]
set yrange [:NUM_SSTABLES]

plot \
for [i=1:NUM_SSTABLES] \
FN_IN u 2:($1==i ? (($1-1)+(($4+$5)/MAX_HEIGHT)) : 1/0) w filledcurves y1=(i-1) lc rgb "#FFC0C0" not, \
for [i=1:NUM_SSTABLES] \
FN_IN u 2:($1==i ? (($1-1)+(($4+$5)/MAX_HEIGHT)) : 1/0) w linespoints pt 7 lc rgb "#FF0000" not

# Tested with gnuplot 4.6 patchlevel 6

FN_IN = system("echo $FN_IN")
FN_OUT = system("echo $FN_OUT")

# Can be parameterized later
NUM_SSTABLES=17

# Get min and max values
set terminal unknown
set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"
plot \
FN_IN u 2:($4+$5) w points not
# GPVAL_DATA_[X|Y]_[MIN|MAX] are set now

set terminal pdfcairo enhanced size 3in, 2in
set output FN_OUT

#set tmargin at screen 0.975
#set bmargin at screen 0.152
#set lmargin at screen 0.185
#set rmargin at screen 0.940

set xlabel "Time (min)" offset 0,0.3
set ylabel sprintf("Normalized # of accesses\nper sec by SSTables (max=%d)", GPVAL_DATA_Y_MAX)  offset 1.6,0

set border (1 + 2) back lc rgb "#808080"
set xtics nomirror scale 0.5,0 tc rgb "#808080"
set ytics nomirror scale 0.5,0 tc rgb "#808080" autofreq 0,5

set xdata time
set timefmt "%Y-%m-%d-%H:%M:%S"
set format x "%M"
#set format x ":%S"

# Draw the bottom line. Not really needed.
#set for [i=1:NUM_SSTABLES] arrow from GPVAL_DATA_X_MIN,i to GPVAL_DATA_X_MAX,i nohead lc rgb "#C0C0C0" front

set pointsize 0.02

MAX_HEIGHT=1.2*GPVAL_DATA_Y_MAX

set xrange [GPVAL_DATA_X_MIN:GPVAL_DATA_X_MAX]
set yrange [:NUM_SSTABLES]

plot \
for [i=1:NUM_SSTABLES] \
FN_IN u 2:($1==i ? (($1-1)+(($4+$5)/MAX_HEIGHT)) : 1/0) w filledcurves y1=(i-1) lc rgb "#FFC0C0" not, \
for [i=1:NUM_SSTABLES] \
FN_IN u 2:($1==i ? (($1-1)+(($4+$5)/MAX_HEIGHT)) : 1/0) w linespoints pt 7 lc rgb "#FF0000" not


set y2range

set y2range

#!/usr/bin/env gnuplot

# graph of CPU load

# datafile
ifname = "/tmp/sql12.csv"
ofname = "/tmp/lnxdiagd/site/img/day12.png"

# ******************************************************* General settings *****
# set terminal png font "Vera" 11 size 640,480
set terminal png truecolor enhanced font "Vera" 10 size 640,304
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid front
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
set timestamp 'created: %Y-%m-%d %H:%M' bottom font "Vera,8"

# ************************************************************* Statistics *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifname using 2 name "X" nooutput

X_min = X_min + utc_offset - 946684800
X_max = X_max + utc_offset - 946684800

# ****************************************************************** Title *****
set title "CPU Load"

# ***************************************************************** X-axis *****
set xlabel "Date/Time"       # X-axis label
set xdata time               # Define that data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xtics rotate by 40 right
set xrange [ X_min : X_max ]

# ***************************************************************** Y-axis *****
set ylabel "Usage [%]"
set yrange [0:100]
# set autoscale y

# **************************************************************** Y2-axis *****
set y2label "Load"
#set autoscale y2
set y2range [0:2]
set y2tics border

# ***************************************************************** Legend *****
set key outside bottom center horizontal box
set key samplen .2
set key reverse Left

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
set object 1 rect from screen 0,0 to screen 1,1 behind
set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
set object 2 rect from graph 0,0 to graph 1,1 behind
set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder
set output ofname

# ***** PLOT *****
set style data boxes
set style fill solid noborder
plot ifname \
      using ($2+utc_offset):($10+$11+$12+$13) title "idle"    fc rgb "#229922"    \
  ,'' using ($2+utc_offset):($10+$11+$13)     title "waiting" fc "blue"           \
  ,'' using ($2+utc_offset):($10+$11)         title "system"  fc "yellow"         \
  ,'' using ($2+utc_offset):10                title "user"    fc rgb "#ccbb0000"  \
  ,'' using ($2+utc_offset):5                 title "load 5min" with lines lw 0.1 lc "black" axes x1y2

#!/usr/bin/env gnuplot

# graph of CPU load

# datafile
ifname = "/tmp/sql12.csv"
ofname = "/tmp/lnxdiagd/site/img/day12.png"

# ******************************************************* General settings *****
# set terminal png font "Vera" 11 size 640,480
set terminal png truecolor enhanced font "Vera" 10 size 640,304
set datafile separator ';'
set datafile missing "NaN"    # Ignore missing values
set grid front
tz_offset = utc_offset / 3600 # GNUplot only works with UTC. Need to compensate
                              # for timezone ourselves.
set timestamp 'created: %Y-%m-%d %H:%M' bottom font "Vera,8"

# ************************************************************* Statistics *****
# stats to be calculated here of column 2 (UX-epoch)
stats ifname using 2 name "X" nooutput

X_min = X_min + utc_offset - 946684800
X_max = X_max + utc_offset - 946684800

# ****************************************************************** Title *****
set title "CPU Load"

# ***************************************************************** X-axis *****
set xlabel "Date/Time"       # X-axis label
set xdata time               # Define that data on X-axis should be interpreted as time
set timefmt "%s"             # Time in log-file is given in Unix format
set format x "%R"            # Display time in 24 hour notation on the X axis
set xtics rotate by 40 right
set xrange [ X_min : X_max ]

# ***************************************************************** Y-axis *****
set ylabel "Usage [%]"
set yrange [0:100]
# set autoscale y

# **************************************************************** Y2-axis *****
set y2label "Load"
set autoscale y2
set y2tics border

# ***************************************************************** Legend *****
set key outside bottom center horizontal box
set key samplen .2
set key reverse Left

# ***************************************************************** Output *****
# set arrow from graph 0,graph 0 to graph 0,graph 1 nohead lc rgb "red" front
# set arrow from graph 1,graph 0 to graph 1,graph 1 nohead lc rgb "green" front
set object 1 rect from screen 0,0 to screen 1,1 behind
set object 1 rect fc rgb "#eeeeee" fillstyle solid 1.0 noborder
set object 2 rect from graph 0,0 to graph 1,1 behind
set object 2 rect fc rgb "#ffffff" fillstyle solid 1.0 noborder
set output ofname

# ***** PLOT *****
set style data boxes
set style fill solid noborder
plot ifname \
      using ($2+utc_offset):($10+$11+$12+$13) title "idle"    fc rgb "#229922"    \
  ,'' using ($2+utc_offset):($10+$11+$13)     title "waiting" fc "blue"           \
  ,'' using ($2+utc_offset):($10+$11)         title "system"  fc "yellow"         \
  ,'' using ($2+utc_offset):10                title "user"    fc rgb "#ccbb0000"  \
  ,'' using ($2+utc_offset):5                 title "load 5min" with lines lw 0.1 lc "black" axes x1y2