<commit_before>#!/usr/bin/perl
use 5.020;

use strict;
use warnings;
use utf8;
use experimental 'signatures';
no if $] >= 5.018, warnings => "experimental::smartmatch";

use DBI;
use Text::CSV_XS qw( csv );
use Data::Dumper;
use Chart::Gnuplot;
use File::Find;
use File::Path qw(make_path remove_tree);
use Cwd 'abs_path';

# combining standard deviations is not trivial, but would be possible:
# http://www.burtonsys.com/climate/composite_standard_deviations.html

my $DBPATH = ':memory:';
my $TABLE = 'results';
my $CSVDIR = 'resultStore';
my $OUTDIR = 'fig';
my $BARGRAPH = abs_path("bargraph.pl");

our $FONT = "Times";
our $FONTSIZE = "30";

our $NAME_FINE = "Handcrafted";
our $NAME_COARSE = "G-Lock";
our $NAME_FULLMV = "FullMV";
our $NAME_PARRP = "MV-RP";
our $NAME_STM = "STM-RP";
our $NAME_RESTORING = "Snapshots";

our $YTIC_COUNT = 4;
our $YRANGE_ROUND = 100;
our $BARGRAPH_YTICS = 2.0;
our $BARGRAPH_YFORMAT = "%1.1f";
our $LEGEND_POS = "off";
our $YRANGE = "[0:]";
our $XRANGE = "[:]";
our $GNUPLOT_TERMINAL = "pdf size 5,2.5";
our %MARGINS = (
    lmargin => 5.8,
    rmargin => 1.5,
    tmargin => 0.3,
    bmargin => 1.5,
  );
our $VERTICAL_LINE = undef;
our $X_VARYING = "Threads";
our $BARGRAPH_LEGEND = "legendx=inside";
our %ADDITIONAL_GNUPLOT_PARAMS = ();

our $MANUAL_BARGRAPH_HACK = 0;

sub prettyName($name) {
  $name =~ s/Param: engineName:\s*//;
  $name =~ s/pessimistic|spinning|REScalaSpin|parrp/$NAME_PARRP/;
  $name =~ s/fullmv/$NAME_FULLMV/;
  $name =~ s/stm|REScalaSTM|STM/$NAME_STM/;
  $name =~ s/synchron|REScalaSynchron/$NAME_COARSE/;
  $name =~ s/unmanaged/$NAME_FINE/;
  $name =~ s/restoring/$NAME_RESTORING/;
  return $name;
}

sub styleByName($name) {
  given($name) {
    when (/$NAME_PARRP/)     { 'linecolor "dark-green" lt 2 lw 2 pt 7  ps 1' }
    when (/$NAME_STM/)       { 'linecolor "dark-green"       lt 2 lw 2 pt 7  ps 1' }
    when (/$NAME_COARSE|Restore/)    { 'linecolor "red"       lt 2 lw 2 pt 9  ps 1' }
    when (/fair/)            { 'linecolor "light-blue" lt 2 lw 2 pt 8  ps 1' }
    when (/$NAME_FULLMV/) { 'linecolor "blue" lt 2 lw 2 pt 5  ps 1' }
    when (/$NAME_FINE/)      { 'linecolor "black"      lt 2 lw 2 pt 11 ps 1' }
    when (/$NAME_RESTORING|Derive/) { 'linecolor "dark-green" lt 2 lw 2 pt 6  ps 1' }
    default { '' }
  }
}

my $DBH = DBI->connect("dbi:SQLite:dbname=". $DBPATH,"","",{AutoCommit => 0,PrintError => 1});
{

  importCSV();
#  $DBH->do("DELETE FROM $TABLE WHERE Threads > 16");
#  $DBH->do(qq[DELETE FROM $TABLE WHERE "Param: engineName" = "fair"]);
#  $DBH->do(qq[DELETE FROM $TABLE WHERE "Param: engineName" = "parrp"]);

  remove_tree($_) for glob("$OUTDIR/*");
  mkdir $OUTDIR;
  chdir $OUTDIR;

  makeLegend();
#  miscBenchmarks();
#  restorationBenchmarks();
  mvrpBenchmarks();

  $DBH->commit();
}

sub restorationBenchmarks() {
  { # fold percentages
    local $LEGEND_POS = "left bottom";
    my $benchmark = "benchmarks.restoring.RestoringSimple.countMany";
    local $X_VARYING = "Param: foldPercent";
    for my $foldNodes (queryChoices("Param: size", Benchmark => $benchmark)) {
      #local $LEGEND_POS = "right top" if $foldNodes == 4;
      plotBenchmarksFor("folds", "foldPercentage$foldNodes",
        (map {{Title => $_, "Param: engineName" => $_ , Benchmark => $benchmark, "Param: size" => $foldNodes }}
          queryChoices("Param: engineName", Benchmark => $benchmark, "Param: size" => $foldNodes)),);
    }
  }

  { # resotring vs deriving
    local $X_VARYING = "Param: size";
    local $LEGEND_POS = "right top";
    local %ADDITIONAL_GNUPLOT_PARAMS = (logscale => "x 10");
    plotBenchmarksFor("restoreVsDerive", "restoreVsDerive",
      {Title => "Restore", Benchmark => "benchmarks.restoring.RestoringSnapshotVsRecomputationA.restored"},
      {Title => "Derive", Benchmark => "benchmarks.restoring.RestoringSnapshotVsRecomputationB.derived"});
  }
}

sub mvrpBenchmarks() {
  # paper philosophers
  for my $topper (queryChoices("Param: topper")) {
    for my $dynamic (queryChoices("Param: dynamicity", "Param: topper" => $topper)) {
      for my $philosophers (queryChoices("Param: philosophers", "Param: dynamicity" => $dynamic, "Param: topper" => $topper)) {
        # local $YRANGE = "[0:500]" if $philosophers <= 64 && $dynamic eq "static";
        # local $YRANGE = "[0:400]" if $philosophers <= 32 && $dynamic eq "static";
        # local $YRANGE = "[0:800]" if $philosophers > 64 && $dynamic eq "static";
        # local $YRANGE = "[0:300]" if $dynamic ne "static" && $philosophers <= 64;
        local $YRANGE = "[0:150]" if $philosophers == 16 && $topper eq "none";
        local $YRANGE_ROUND = 150 if $philosophers == 16 && $topper eq "none";
        local $YTIC_COUNT = 3 if $philosophers == 16 && $topper eq "none";
        local $YRANGE = "[0:400]" if $philosophers == 64 && $topper eq "none";<commit_msg>starting on getting distributed benchmarks rendered<commit_after>#!/usr/bin/perl
use 5.020;

use strict;
use warnings;
use utf8;
use experimental 'signatures';
no if $] >= 5.018, warnings => "experimental::smartmatch";

use DBI;
use Text::CSV_XS qw( csv );
use Data::Dumper;
use Chart::Gnuplot;
use File::Find;
use File::Path qw(make_path remove_tree);
use Cwd 'abs_path';

# combining standard deviations is not trivial, but would be possible:
# http://www.burtonsys.com/climate/composite_standard_deviations.html

my $DBPATH = ':memory:';
my $TABLE = 'results';
my $CSVDIR = 'resultStore';
my $OUTDIR = 'fig';
my $BARGRAPH = abs_path("bargraph.pl");

our $FONT = "Times";
our $FONTSIZE = "30";

our $NAME_FINE = "Handcrafted";
our $NAME_COARSE = "G-Lock";
our $NAME_FULLMV = "FullMV";
our $NAME_PARRP = "MV-RP";
our $NAME_STM = "STM-RP";
our $NAME_RESTORING = "Snapshots";

our $YTIC_COUNT = 4;
our $YRANGE_ROUND = 100;
our $BARGRAPH_YTICS = 2.0;
our $BARGRAPH_YFORMAT = "%1.1f";
our $LEGEND_POS = "off";
our $YRANGE = "[0:]";
our $XRANGE = "[:]";
our $GNUPLOT_TERMINAL = "pdf size 5,2.5";
our %MARGINS = (
    lmargin => 5.8,
    rmargin => 1.5,
    tmargin => 0.3,
    bmargin => 1.5,
  );
our $VERTICAL_LINE = undef;
our $X_VARYING = "Threads";
our $BARGRAPH_LEGEND = "legendx=inside";
our %ADDITIONAL_GNUPLOT_PARAMS = ();

our $MANUAL_BARGRAPH_HACK = 0;

sub prettyName($name) {
  $name =~ s/Param: engineName:\s*//;
  $name =~ s/pessimistic|spinning|REScalaSpin|parrp/$NAME_PARRP/;
  $name =~ s/fullmv/$NAME_FULLMV/;
  $name =~ s/stm|REScalaSTM|STM/$NAME_STM/;
  $name =~ s/synchron|REScalaSynchron/$NAME_COARSE/;
  $name =~ s/unmanaged/$NAME_FINE/;
  $name =~ s/restoring/$NAME_RESTORING/;
  return $name;
}

sub styleByName($name) {
  given($name) {
    when (/$NAME_PARRP/)     { 'linecolor "dark-green" lt 2 lw 2 pt 7  ps 1' }
    when (/$NAME_STM/)       { 'linecolor "dark-green"       lt 2 lw 2 pt 7  ps 1' }
    when (/$NAME_COARSE|Restore/)    { 'linecolor "red"       lt 2 lw 2 pt 9  ps 1' }
    when (/fair/)            { 'linecolor "light-blue" lt 2 lw 2 pt 8  ps 1' }
    when (/$NAME_FULLMV/) { 'linecolor "blue" lt 2 lw 2 pt 5  ps 1' }
    when (/$NAME_FINE/)      { 'linecolor "black"      lt 2 lw 2 pt 11 ps 1' }
    when (/$NAME_RESTORING|Derive/) { 'linecolor "dark-green" lt 2 lw 2 pt 6  ps 1' }
    default { '' }
  }
}

my $DBH = DBI->connect("dbi:SQLite:dbname=". $DBPATH,"","",{AutoCommit => 0,PrintError => 1});
{

  importCSV();
#  $DBH->do("DELETE FROM $TABLE WHERE Threads > 16");
#  $DBH->do(qq[DELETE FROM $TABLE WHERE "Param: engineName" = "fair"]);
#  $DBH->do(qq[DELETE FROM $TABLE WHERE "Param: engineName" = "parrp"]);

  remove_tree($_) for glob("$OUTDIR/*");
  mkdir $OUTDIR;
  chdir $OUTDIR;

  makeLegend();
  distributionBenchmarks();

  $DBH->commit();
}

sub distributionBenchmarks() {
  { # conflict distance
    my $benchmark = "rescala.benchmarks.distributed.rtt.ConflictDistance.run";
    my $query = queryDataset(query("Param: mergeAt", "Benchmark"));
    plotDatasets("rtt", "conflictdistance", {xlabel => "Merge Depth"},
      $query->("foo", $benchmark)
    );
  }

  { # loop back
    my $benchmark = "rescala.benchmarks.distributed.rtt.RemoteGlitchLoop.run";
    my $query = queryDataset(query("Threads", "Benchmark"));
    plotDatasets("rtt", "loopback", {xlabel => "Threads"},
      $query->("foo", $benchmark)
    );
  }

  { # map grid single threaded
    my $benchmark = "rescala.benchmarks.distributed.rtt.DistributedSignalMapGrid.run";
    my $query = queryDataset(query("Param: depthHosts", "Threads", "Benchmark"));
    plotDatasets("rtt", "loopback", {xlabel => "Hosts"},
      $query->("foo", 1, $benchmark)
    );
  }

  { # map grid all threads
    my $benchmark = "rescala.benchmarks.distributed.rtt.DistributedSignalMapGrid.run";
    my $query = queryDataset(query("Threads", "Benchmark", "Param: depthHosts"));
    plotDatasets("rtt", "loopback", {xlabel => "Threads"},
      map { $query->("$_ Hosts", $benchmark, $_) } queryChoices("Param: depthHosts", "Benchmark" => $benchmark)
	);
  }
}

sub mvrpBenchmarks() {
  # paper philosophers
  for my $topper (queryChoices("Param: topper")) {
    for my $dynamic (queryChoices("Param: dynamicity", "Param: topper" => $topper)) {
      for my $philosophers (queryChoices("Param: philosophers", "Param: dynamicity" => $dynamic, "Param: topper" => $topper)) {
        # local $YRANGE = "[0:500]" if $philosophers <= 64 && $dynamic eq "static";
        # local $YRANGE = "[0:400]" if $philosophers <= 32 && $dynamic eq "static";
        # local $YRANGE = "[0:800]" if $philosophers > 64 && $dynamic eq "static";
        # local $YRANGE = "[0:300]" if $dynamic ne "static" && $philosophers <= 64;
        local $YRANGE = "[0:150]" if $philosophers == 16 && $topper eq "none";
        local $YRANGE_ROUND = 150 if $philosophers == 16 && $topper eq "none";
        local $YTIC_COUNT = 3 if $philosophers == 16 && $topper eq "none";
        local $YRANGE = "[0:400]" if $philosophers == 64 && $topper eq "none";
{'fraction_non_alphanumeric': 0.1763632677883641, 'fraction_numerical': 0.022501520372998175, 'mean_word_length': 3.799124513618677, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 60, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6070690', 'n_tokens_mistral': 4017, 'n_tokens_neox': 3700, 'n_words': 916}