@Override public StackResult aggregate(final Collection<StackResult> results) { if (results.isEmpty()) { throw new IllegalArgumentException("Nothig to aggregate: " + results); } else if (results.size() == 1) { return results.iterator().next(); } Iterator<StackResult> it = results.iterator(); StackResult result = it.next(); SampleNode agg = result.getSamples(); final String benchmark = result.getBenchmark(); while (it.hasNext()) { result = it.next(); String obenchmark = result.getBenchmark(); if (!benchmark.equals(obenchmark)) { throw new Spf4jProfilerException("Should not aggregate " + benchmark + " with " + obenchmark); } agg = SampleNode.aggregate(agg, result.getSamples()); } try { return new StackResult(agg, benchmark, false); } catch (IOException ex) { throw new UncheckedIOException(ex); } }
@Override @Nonnull public Collection<? extends Result> afterIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams, final IterationResult ir) { try { SAMPLER.stop(); } catch (InterruptedException ex) { Thread.currentThread().interrupt(); return Collections.EMPTY_LIST; } Map<String, SampleNode> c = SAMPLER.getStackCollectionsAndReset(); if (c.isEmpty()) { return Collections.EMPTY_LIST; } SampleNode collected = c.values().iterator().next(); try { return Collections.singletonList(new StackResult(collected, benchmarkParams.id(), true)); } catch (IOException ex) { throw new UncheckedIOException(ex); } }
public StackResult(final SampleNode samples, final String benchmark, final boolean isIteration) throws IOException { super(ResultRole.SECONDARY, "@stack", of(Double.NaN), "---", AggregationPolicy.AVG); this.samples = samples; this.benchmark = benchmark; if (!isIteration) { String fileName = DUMP_FOLDER + '/' + benchmark + ".ssdump2"; Converter.save(new File(fileName), samples); } }