diff options
author | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-05-21 14:59:38 +0200 |
---|---|---|
committer | Kjetil Ørbekk <kjetil.orbekk@gmail.com> | 2012-05-21 14:59:38 +0200 |
commit | 775546f63d04778ab26b401fc179746fa3fb71a7 (patch) | |
tree | 4eaaffd27f84388e144f63ad9651df35751d0bc5 /statserver/src | |
parent | 97f5dda0c10c3a885cbe53d1e8ae324cec2dcc49 (diff) |
Process data and output in gnuplot format.
Diffstat (limited to 'statserver/src')
-rw-r--r-- | statserver/src/main/java/com/orbekk/stats/Analysis.java | 32 | ||||
-rw-r--r-- | statserver/src/main/java/com/orbekk/stats/Experiment1Impl.java | 22 |
2 files changed, 50 insertions, 4 deletions
diff --git a/statserver/src/main/java/com/orbekk/stats/Analysis.java b/statserver/src/main/java/com/orbekk/stats/Analysis.java new file mode 100644 index 0000000..a6d0271 --- /dev/null +++ b/statserver/src/main/java/com/orbekk/stats/Analysis.java @@ -0,0 +1,32 @@ +package com.orbekk.stats; + +import java.util.List; + +public class Analysis { + final List<Double> samples; + + public Analysis(List<Double> samples) { + this.samples = samples; + } + + public double getAverage() { + double sum = 0.0; + for (Double d : samples) { + sum += d; + } + return sum / samples.size(); + } + + public double getVariance() { + double average = getAverage(); + double sumDifferences = 0.0; + for (Double d : samples) { + sumDifferences += (d - average) * (d - average); + } + return sumDifferences / samples.size(); + } + + public double getStandardDeviation() { + return Math.sqrt(getVariance()); + } +} diff --git a/statserver/src/main/java/com/orbekk/stats/Experiment1Impl.java b/statserver/src/main/java/com/orbekk/stats/Experiment1Impl.java index a9b8331..cd4393c 100644 --- a/statserver/src/main/java/com/orbekk/stats/Experiment1Impl.java +++ b/statserver/src/main/java/com/orbekk/stats/Experiment1Impl.java @@ -3,6 +3,7 @@ package com.orbekk.stats; import java.io.FileNotFoundException; import java.io.PrintWriter; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.logging.Logger; @@ -14,13 +15,19 @@ import com.orbekk.stats.Experiments.SimpleTiming; public class Experiment1Impl extends Experiment1 { private final static Logger logger = Logger.getLogger(Experiment1Impl.class.getName()); - private List<SimpleTiming> samples = new ArrayList<SimpleTiming>(); + // private List<SimpleTiming> samples = new ArrayList<SimpleTiming>(); + + private HashMap<Integer, List<Double>> samples = + new HashMap<Integer, List<Double>>(); @Override public synchronized void registerSample(RpcController controller, SimpleTiming request, RpcCallback<Empty> done) { logger.info(request.toString()); - samples.add(request); + if (samples.get(request.getNumDevices()) == null) { + samples.put(request.getNumDevices(), new ArrayList<Double>()); + } + samples.get(request.getNumDevices()).add(request.getTiming()); done.run(Empty.getDefaultInstance()); } @@ -30,9 +37,16 @@ public class Experiment1Impl extends Experiment1 { printer = new PrintWriter(filename); System.out.println("Writing results to " + filename); printer.println("# Automatically generated by Experiment1Impl.java"); - for (SimpleTiming timing : samples) { - printer.println(timing); + + printer.println("# <numDevices> <avg latency> <avg-stddev> <avg+stddev>"); + for (int numDevices : samples.keySet()) { + Analysis data = new Analysis(samples.get(numDevices)); + double avg = data.getAverage(); + double stddev = data.getStandardDeviation(); + printer.println(String.format( + "%d %f %f %f", numDevices, avg, avg-stddev, avg+stddev)); } + } catch (FileNotFoundException e) { e.printStackTrace(); } finally { |