#!/usr/bin/octave -q
## -*-octave-*-

datafiles = argv();
datafiles = {
	     "rtems.dat"
	     "kernel.dat"
	     "mmapbusy-mmap.dat"
	     "mmapbusy-write.dat"
	     "readnb-write.dat"
	     "readbusy-write.dat"
	     "readbusynoirq-write.dat"
	     "readnb-mmap.dat"
	     "read-mmap.dat"
	     "read-write.dat"
	     "mmap-write.dat"
	     "mmap-mmap.dat"
};

quantiles = [0 0.5 0.90 0.99];

mat = zeros(0, length(quantiles) + 2);
names = {};

for i=1:length(datafiles),
  [d, n, e, v] = fileparts(datafiles{i});
  try
    x = load(datafiles{i})*1e6;
    stat = csv2cell([n, "-stat.txt"], '=');
    lost = stat{6,2};
    q = quantile (x, quantiles);
    q = max(q, 0)';
    avg = mean(x);
  catch
    disp(["Skiping ", n]);
    continue
  end_try_catch
  mat = [ mat; q lost avg ];
  names{length(names)+1} = n;
  disp(["Added ", n]);
end

if 0,
  [mat, ind] = sortrows(mat, 2);
  names = names(ind)
end
result = [names', num2cell(mat)];
cell2csv("result", result, ' ', '"');
