diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java index 7d299d5e2f71c6e9452557fa7a5c53e0b1cafbe7..ac88a8b9c9fa8bc070b4b3c67110c4a850aa7518 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/BenchmarkJobManager.java @@ -8,13 +8,10 @@ import java.nio.file.Files; import java.nio.file.InvalidPathException; import java.nio.file.Path; import java.nio.file.Paths; -import java.text.NumberFormat; -import java.text.ParseException; import java.util.Arrays; import java.util.Collection; import java.util.LinkedList; import java.util.List; -import java.util.Locale; import java.util.Map; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -35,7 +32,6 @@ import net.imagej.updater.util.Progress; public class BenchmarkJobManager { - @SuppressWarnings("unused") private static Logger log = LoggerFactory .getLogger(cz.it4i.fiji.haas_spim_benchmark.core.BenchmarkJobManager.class); @@ -231,17 +227,14 @@ public class BenchmarkJobManager { private static void formatResultFile(Path filename) throws FileNotFoundException { - LinkedList<ResultFileTask> identifiedTasks = new LinkedList<ResultFileTask>(); + List<ResultFileTask> identifiedTasks = new LinkedList<ResultFileTask>(); try { String line = null; final String separator = ";"; ResultFileTask processedTask = null; - LinkedList<String> id = new LinkedList<String>(); - LinkedList<Double> memoryUsed = new LinkedList<Double>(); - LinkedList<Integer> wallTime = new LinkedList<Integer>(); - LinkedList<Integer> cpuPercentage = new LinkedList<Integer>(); + List<ResultFileJob> values = new LinkedList<>(); BufferedReader reader = Files.newBufferedReader(filename); while (null != (line = reader.readLine())) { @@ -256,51 +249,36 @@ public class BenchmarkJobManager { if (columns[0].equals("Task name")) { if (null != processedTask ) { - for (int i = 0; i < id.size(); i++) { - processedTask.jobs.add(new ResultFileJob(id.get(i), memoryUsed.get(i), wallTime.get(i), cpuPercentage.get(i))); - } + processedTask.jobs.addAll(values); + identifiedTasks.add(processedTask); } processedTask = new ResultFileTask(columns[1]); - - id = new LinkedList<String>(); - memoryUsed = new LinkedList<Double>(); - wallTime = new LinkedList<Integer>(); - cpuPercentage = new LinkedList<Integer>(); + values.clear(); } else if (columns[0].equals("job ids")) { for (int i = 1; i < columns.length; i++) { - id.add(columns[i]); - } - } else if (columns[0].equals("resources_used.mem")) { - for (int i = 1; i < columns.length; i++) { - Number number = NumberFormat.getInstance(Locale.GERMANY).parse(columns[i]); - memoryUsed.add(number.doubleValue()); - } - } else if (columns[0].equals("resources_used.walltime")) { - for (int i = 1; i < columns.length; i++) { - wallTime.add(Integer.parseInt(columns[i])); + values.add(new ResultFileJob(columns[i])); } - } else if (columns[0].equals("resources_used.cpupercent")) { + } else if (!columns[0].equals("jobs #")){ for (int i = 1; i < columns.length; i++) { - cpuPercentage.add(Integer.parseInt(columns[i])); + ResultFileJob resultFileJob; + resultFileJob = values.get(i - 1); + resultFileJob.setValue(columns[0], columns[i]); } - } + } } if (null != processedTask ) { - for (int i = 0; i < id.size(); i++) { - processedTask.jobs.add(new ResultFileJob(id.get(i), memoryUsed.get(i), wallTime.get(i), cpuPercentage.get(i))); - } + processedTask.jobs.addAll(values); + identifiedTasks.add(processedTask); } } catch (IOException e) { log.error(e.getMessage(), e); - } catch (ParseException e) { - log.error(e.getMessage(), e); - } + } for (ResultFileTask task : identifiedTasks) { System.out.println("Task " + task.name + " needed " + task.getJobCount() + " jobs and " + task.getAverageMemoryUsage() +" MB of memory in average."); diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/ResultFileJob.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/ResultFileJob.java index 5a17fcadf1122116e340e94a1d10f886011817d8..eb6f5c4ef4e182035a7b6b070d1fffc093cb0cb0 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/ResultFileJob.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/ResultFileJob.java @@ -1,14 +1,22 @@ package cz.it4i.fiji.haas_spim_benchmark.core; +import java.util.HashMap; +import java.util.Map; + public class ResultFileJob { String id; - double memoryUsed; - int wallTime; - int cpuPercentage; - public ResultFileJob(String id, double memoryUsed, int wallTime, int cpuPercentage) { + Map<String, String> values = new HashMap<>(); + + public ResultFileJob(String id) { this.id = id; - this.memoryUsed = memoryUsed; - this.wallTime = wallTime; - this.cpuPercentage = cpuPercentage; + + } + + public String getValue(String key) { + return values.get(key); + } + + public void setValue(String key, String value) { + values.put(key, value); } } \ No newline at end of file diff --git a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/ResultFileTask.java b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/ResultFileTask.java index e52d0f8b12b80fb69c6d71a06ae6a8a945205822..8ec16a0d59a724e7c0716368d8e6d788d4b9e2f6 100644 --- a/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/ResultFileTask.java +++ b/haas-spim-benchmark/src/main/java/cz/it4i/fiji/haas_spim_benchmark/core/ResultFileTask.java @@ -1,41 +1,41 @@ package cz.it4i.fiji.haas_spim_benchmark.core; import java.util.LinkedList; +import java.util.function.Function; +import java.util.stream.Collector; +import java.util.stream.Collectors; public class ResultFileTask { String name; LinkedList<ResultFileJob> jobs; - + public ResultFileTask(String name) { this.name = name; - this.jobs = new LinkedList<ResultFileJob>(); + this.jobs = new LinkedList<ResultFileJob>(); } - + public int getJobCount() { return this.jobs.size(); } - + public double getAverageMemoryUsage() { - double memoryUsageTotal = 0; - for (ResultFileJob job : this.jobs ) { - memoryUsageTotal += job.memoryUsed; - } - return (double)memoryUsageTotal / this.jobs.size(); + return getAverage(str->Double.parseDouble(str), Collectors.averagingDouble(d->d),"resources_used.mem").doubleValue(); } - + public double getAverageWallTime() { - double wallTimeTotal = 0; - for (ResultFileJob job : this.jobs ) { - wallTimeTotal += job.wallTime; - } - return (double)wallTimeTotal / this.jobs.size(); + return getAverage("resources_used.walltime"); } - + public double getAverageCpuPercentage() { - int cpuPercentageTotal = 0; - for (ResultFileJob job : this.jobs ) { - cpuPercentageTotal += job.cpuPercentage; - } - return (double)cpuPercentageTotal / this.jobs.size(); + return getAverage("resources_used.cpupercent"); + } + + private double getAverage(String propertyName) { + return getAverage(str->Integer.parseInt(str), Collectors.averagingInt(i->i),propertyName).doubleValue(); + } + + private<T> Double getAverage(Function<String, T> valueProvider,Collector<T,?,Double> collector,String propertyName) { + return jobs.stream().map(job -> job.getValue(propertyName)).map(memStr -> valueProvider.apply(memStr)) + .collect(collector); } } \ No newline at end of file