Java Code Examples for org.openjdk.jmh.results.Result

The following examples show how to use org.openjdk.jmh.results.Result. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: customized-symspell   Source File: MemoryProfiler.java    License: MIT License 6 votes vote down vote up
@Override
public Collection<? extends Result> afterIteration(BenchmarkParams bp, IterationParams ip,
    IterationResult result) {
  MemoryUsage heapUsage = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage();
  MemoryUsage nonheapUsage = ManagementFactory.getMemoryMXBean().getNonHeapMemoryUsage();

  Collection<ScalarResult> results = new ArrayList<>();
  results.add(
      new ScalarResult(Defaults.PREFIX + "mem.heap", heapUsage.getUsed() / (1024 * 1024.0), "MB",
          AggregationPolicy.MAX));
  results.add(new ScalarResult(
      Defaults.PREFIX + "mem.nonheap", nonheapUsage.getUsed() / (1024 * 1024.0), "MB",
      AggregationPolicy.MAX));

  return results;
}
 
Example 2
Source Project: unsafe   Source File: MemoryProfiler.java    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public Collection<? extends Result> afterIteration(BenchmarkParams benchmarkParams,
    IterationParams iterationParams, IterationResult result) {
  final Runtime runtime = Runtime.getRuntime();

  final long max = runtime.maxMemory();
  final long total = runtime.totalMemory();
  final long free = runtime.freeMemory();
  final long used = total - free;

  return Arrays
      .asList(new ProfilerResult(PREFIX + "rt.mem.max", max, "bytes", AggregationPolicy.MAX),
          new ProfilerResult(PREFIX + "rt.mem.total", total, "bytes", AggregationPolicy.MAX),
          new ProfilerResult(PREFIX + "rt.mem.free", free, "bytes", AggregationPolicy.MAX),
          new ProfilerResult(PREFIX + "rt.mem.used", used, "bytes", AggregationPolicy.MAX));
}
 
Example 3
Source Project: cache2k-benchmark   Source File: LinuxVmProfiler.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Parse the linux {@code /proc/self/status} and add everything prefixed with "Vm" as metric to
 * the profiling result.
 */
public static void addLinuxVmStats(String prefix, List<Result> l) {
  try {
    LineNumberReader r = new LineNumberReader(new InputStreamReader(new FileInputStream("/proc/self/status")));
    String _line;
    while ((_line = r.readLine()) != null) {
      if (!_line.startsWith("Vm")) {
        continue;
      }
      String[] sa = _line.split("\\s+");
      if (sa.length != 3) {
        throw new IOException("Format error: 3 elements expected");
      }
      if (!sa[2].equals("kB")) {
        throw new IOException("Format error: unit kB expected, was: " + sa[2]);
      }
      String _name = sa[0].substring(0, sa[0].length() - 1);
      l.add(
        new OptionalScalarResult(prefix + "." + _name, (double) Long.parseLong(sa[1]), "kB", AggregationPolicy.AVG)
      );
    }
  } catch (IOException ex) {
    throw new UncheckedIOException(ex);
  }
}
 
Example 4
Source Project: cache2k-benchmark   Source File: Cache2kMetricsRecorder.java    License: Apache License 2.0 6 votes vote down vote up
public static void recordStatsAfterIteration(String _statisticsString) {
  Stat now = extract(_statisticsString);
  if (now == null) {
    return;
  }
  if (before == null) {
    throw new IllegalStateException("saveStats() needs to be called before iteration.");
  }
  long _scanCount = now.scanCount - before.scanCount;
  long _evictCount = now.evictCount - before.evictCount;
  long _getCount = now.getCount - before.getCount;
  List<Result> l = new ArrayList<>();
  l.add(new ScalarResult(RESULT_PREFIX + "scanCount", _scanCount, "counter", AggregationPolicy.AVG));
  l.add(new ScalarResult(RESULT_PREFIX + "evictCount", _evictCount, "counter", AggregationPolicy.AVG));
  l.add(new ScalarResult(RESULT_PREFIX + "getCount", _getCount, "counter", AggregationPolicy.AVG));
  if (_evictCount > 0) {
    l.add(new ScalarResult(RESULT_PREFIX + "scanPerEviction", _scanCount * 1.0D / _evictCount, "counter", AggregationPolicy.AVG));
  }
  l.forEach(MiscResultRecorderProfiler::setResult);
  before = now;
}
 
Example 5
Source Project: hadoop-ozone   Source File: GenesisMemoryProfiler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Collection<? extends Result> afterIteration(BenchmarkParams
    benchmarkParams, IterationParams iterationParams, IterationResult
    result) {
  long totalHeap = Runtime.getRuntime().totalMemory();

  Collection<ScalarResult> samples = new ArrayList<>();
  samples.add(new ScalarResult("Max heap",
      StorageUnit.BYTES.toGBs(totalHeap), "GBs",
      AggregationPolicy.MAX));
  return samples;
}
 
Example 6
Source Project: apm-agent-java   Source File: CpuProfiler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Collection<? extends Result> afterIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams, IterationResult result) {
    List<ScalarResult> results = new ArrayList<>();
    long allOps = result.getMetadata().getAllOps();

    long totalCpuTime = osMxBean.getProcessCpuTime() - beforeProcessCpuTime;

    results.add(new ScalarResult(Defaults.PREFIX + "cpu.time.norm",
        (allOps != 0) ? 1.0 * totalCpuTime / allOps : Double.NaN, "ns/op", AggregationPolicy.AVG));
    return results;
}
 
Example 7
Source Project: apm-agent-java   Source File: ReporterProfiler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Collection<? extends Result> afterIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams, IterationResult result) {
    List<ScalarResult> results = new ArrayList<>();
    final TimeValue time = iterationParams.getTime();
    final Reporter reporter = getReporter();
    if (reporter != null) {
        final double iterationDurationNs = time.convertTo(TimeUnit.NANOSECONDS);

        final long reportedDuringThisIteration = reporter.getReported() - reportedCountStart;
        if (reportedDuringThisIteration > 0) {
            double reportsPerSecond = perSecond(iterationDurationNs, reportedDuringThisIteration);
            results.add(new ScalarResult(Defaults.PREFIX + "reporter.reported", reportsPerSecond, "events/s", AggregationPolicy.AVG));
        }

        final long droppedDuringThisIteration = reporter.getDropped() - droppedCountStart;
        if (droppedDuringThisIteration >0) {
            double dropsPerSecond = perSecond(iterationDurationNs, droppedDuringThisIteration);
            results.add(new ScalarResult(Defaults.PREFIX + "reporter.dropped", dropsPerSecond, "events/s", AggregationPolicy.AVG));
        }

        if (receivedBytesStart != null) {
            long receivedBytesDuringThisIteration = getLong("server.received.bytes") - receivedBytesStart;
            results.add(new ScalarResult(Defaults.PREFIX + "server.received.bytes", perSecond(iterationDurationNs,
                receivedBytesDuringThisIteration), "bytes/s", AggregationPolicy.AVG));
        }

        if (receivedPayloadsStart != null) {
            long receivedPayloadsDuringThisIteration = getLong("server.received.payloads") - receivedPayloadsStart;
            results.add(new ScalarResult(Defaults.PREFIX + "server.received.payloads", perSecond(iterationDurationNs,
                receivedPayloadsDuringThisIteration), "payloads/s", AggregationPolicy.AVG));
        }
    }
    return results;
}
 
Example 8
Source Project: SpringBootBucket   Source File: ResultExporter.java    License: MIT License 5 votes vote down vote up
public static void exportResult(String titleStr, Collection<RunResult> results,
                                String paramKey, String xunit) throws Exception {
    // 几个测试对象
    List<String> objects = new ArrayList<>();
    // 测试维度,输入值n
    List<String> dimensions = new ArrayList<>();
    // 有几个测试对象,就有几组测试数据,每组测试数据中对应几个维度的结果
    List<List<Double>> allData = new ArrayList<>();
    List<Double> temp = new ArrayList<>();
    for (RunResult runResult : results) {
        BenchmarkResult benchmarkResult = runResult.getAggregatedResult();
        Result r = benchmarkResult.getPrimaryResult();
        BenchmarkParams params = runResult.getParams();
        if (!objects.contains(r.getLabel())) {
            objects.add(r.getLabel());
            if (!temp.isEmpty()) {
                allData.add(temp);
                temp = new ArrayList<>();
            }
        }
        temp.add(Double.parseDouble(String.format("%.2f", r.getScore())));
        // 测试维度
        if (!dimensions.contains("n=" + params.getParam(paramKey))) {
            dimensions.add("n=" + params.getParam(paramKey));
        }
    }
    // 最后一组测试数据别忘记加进去了
    allData.add(temp);

    String optionStr = generateOption(titleStr, objects, dimensions, allData, xunit);
    // POST到接口上
    postOption(optionStr, "http://localhost:9075/api/v1/data");
}
 
Example 9
Source Project: NNAnalytics   Source File: MemoryProfiler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Collection<? extends Result> afterIteration(
    final BenchmarkParams benchmarkParams,
    final IterationParams iterationParams,
    final IterationResult result) {
  long usedMemoryAfterIteration = getUsedMemory();
  references = null;

  long usedMemoryInIteration = usedMemoryAfterIteration - usedMemoryBeforeIteration;
  double usedMemoryPerOp =
      ((double) usedMemoryInIteration) / result.getMetadata().getMeasuredOps();
  List<Result> results = new ArrayList<Result>();
  results.add(new ScalarResult("+memory.used", usedMemoryPerOp, "bytes", AggregationPolicy.AVG));
  return results;
}
 
Example 10
@Override
public Collection<? extends Result> afterIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams, final IterationResult result) {
  List<Result<?>> all = new ArrayList<>();
  counters.values().stream()
    .map(e ->
      new ScalarResult(SECONDARY_RESULT_PREFIX + e.key, (double) e.counter.get(), e.unit, e.aggregationPolicy))
    .sequential().forEach(e -> all.add(e));
  all.addAll(results.values());
  return all;
}
 
Example 11
Source Project: cache2k-benchmark   Source File: ForcedGcMemoryProfiler.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public Collection<? extends Result> afterIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams, final IterationResult result) {
  if (runOnlyAfterLastIteration) {
    if (iterationParams.getType() != IterationType.MEASUREMENT
    || iterationParams.getCount() != ++iterationNumber) {
      return Collections.emptyList();
    }
  }
  recordUsedMemory();
  List<Result> l = new ArrayList<>();
  l.addAll(Arrays.asList(
    new OptionalScalarResult("+forced-gc-mem.gcTimeMillis", (double) gcTimeMillis, "ms", AggregationPolicy.AVG),
    new OptionalScalarResult("+forced-gc-mem.usedHeap", (double) usedHeapViaHistogram, "bytes", AggregationPolicy.AVG)
  ));
  if (usageAfterIteration != null) {
  	// old metrics, t.b. removed
	l.addAll(Arrays.asList(
		new OptionalScalarResult("+forced-gc-mem.used.settled", (double) usageAfterSettled.getTotalUsed(), "bytes", AggregationPolicy.AVG),
		new OptionalScalarResult("+forced-gc-mem.used.after", (double) usageAfterIteration.getTotalUsed(), "bytes", AggregationPolicy.AVG),
		new OptionalScalarResult("+forced-gc-mem.total", (double) usageAfterSettled.getTotalCommitted(), "bytes", AggregationPolicy.AVG)
	));
	l.addAll(Arrays.asList(
		new OptionalScalarResult("+forced-gc-mem.totalUsed", (double) usageAfterSettled.getTotalUsed(), "bytes", AggregationPolicy.AVG),
		new OptionalScalarResult("+forced-gc-mem.totalUsed.after", (double) usageAfterIteration.getTotalUsed(), "bytes", AggregationPolicy.AVG),
		new OptionalScalarResult("+forced-gc-mem.totalCommitted", (double) usageAfterSettled.getTotalCommitted(), "bytes", AggregationPolicy.AVG),
		new OptionalScalarResult("+forced-gc-mem.totalCommitted.after", (double) usageAfterIteration.getTotalCommitted(), "bytes", AggregationPolicy.AVG),
		new OptionalScalarResult("+forced-gc-mem.heapUsed", (double) usageAfterSettled.heap.getUsed(), "bytes", AggregationPolicy.AVG),
		new OptionalScalarResult("+forced-gc-mem.heapUsed.after", (double) usageAfterIteration.heap.getUsed(), "bytes", AggregationPolicy.AVG)
	));
}
  LinuxVmProfiler.addLinuxVmStats("+forced-gc-mem.linuxVm", l);
  keepReference = null;
  return l;
}
 
Example 12
Source Project: tlaplus   Source File: FlightRecorderProfiler.java    License: MIT License 4 votes vote down vote up
@Override
public Collection<? extends Result> afterTrial(BenchmarkResult arg0, long arg1, File arg2, File arg3) {
       return new ArrayList<>();
}
 
Example 13
Source Project: cglib   Source File: FlightRecorderProfiler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Collection<? extends Result> afterTrial(BenchmarkResult br, long pid, File stdOut, File stdErr) {
    return Collections.emptyList();
}
 
Example 14
Source Project: calcite   Source File: FlightRecorderProfiler.java    License: Apache License 2.0 4 votes vote down vote up
@Override public Collection<? extends Result> afterTrial(BenchmarkResult br, long pid,
    File stdOut, File stdErr) {
  return Collections.emptyList();
}
 
Example 15
Source Project: cache2k-benchmark   Source File: LinuxVmProfiler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Collection<? extends Result> afterIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams, final IterationResult result) {
  List<Result> l = new ArrayList<>();
  addLinuxVmStats(PREFIX, l);
  return l;
}
 
Example 16
/**
 * Add result to the JMH result data. If called multiple times with the same label only the last one will be added.
 */
public static void setResult(Result r) {
  results.put(r.getLabel(), r);
}
 
Example 17
Source Project: cache2k-benchmark   Source File: GcProfiler.java    License: Apache License 2.0 4 votes vote down vote up
@Override
public Collection<? extends Result> afterIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams, IterationResult iResult) {

  try {
    Thread.sleep(567);
  } catch (InterruptedException ignore) {

  }

  uninstallHooks();
  long afterTime = System.nanoTime();

  HotspotAllocationSnapshot newSnapshot = HotspotAllocationSnapshot.create();

  long gcTime = 0;
  long gcCount = 0;
  for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
    gcCount += bean.getCollectionCount();
    gcTime += bean.getCollectionTime();
  }

  List<Result<?>> results = new ArrayList<>();

  if (beforeAllocated == HotspotAllocationSnapshot.EMPTY) {
    results.add(new ScalarResult(Defaults.PREFIX + "gc.alloc.rate",
      Double.NaN,
      "MB/sec", AggregationPolicy.AVG));
  } else {
    long allocated = newSnapshot.subtract(beforeAllocated);
    results.add(new ScalarResult(Defaults.PREFIX + "gc.alloc.rate",
      (afterTime != beforeTime) ?
        1.0 * allocated / 1024 / 1024 * TimeUnit.SECONDS.toNanos(1) / (afterTime - beforeTime) :
        Double.NaN,
      "MB/sec", AggregationPolicy.AVG));
    if (allocated != 0) {
      long allOps = iResult.getMetadata().getAllOps();
      results.add(new ScalarResult(Defaults.PREFIX + "gc.alloc.rate.norm",
        (allOps != 0) ?
          1.0 * allocated / allOps :
          Double.NaN,
        "B/op", AggregationPolicy.AVG));
    }
  }

  results.add(new ScalarResult(
    Defaults.PREFIX + "gc.count",
    gcCount - beforeGCCount,
    "counts",
    AggregationPolicy.AVG));

  if (gcCount != beforeGCCount || gcTime != beforeGCTime) {
    results.add(new ScalarResult(
      Defaults.PREFIX + "gc.time",
      gcTime - beforeGCTime,
      "ms",
      AggregationPolicy.AVG));
  }

  for (String space : churn.keys()) {
    double churnRate = (afterTime != beforeTime) ?
      1.0 * churn.count(space) * TimeUnit.SECONDS.toNanos(1) / (afterTime - beforeTime) / 1024 / 1024 :
      Double.NaN;

    double churnNorm = 1.0 * churn.count(space) / iResult.getMetadata().getAllOps();

    String spaceName = space.replaceAll(" ", "_");

    results.add(new ScalarResult(
      Defaults.PREFIX + "gc.churn." + spaceName + "",
      churnRate,
      "MB/sec",
      AggregationPolicy.AVG));

    results.add(new ScalarResult(Defaults.PREFIX + "gc.churn." + spaceName + ".norm",
      churnNorm,
      "B/op",
      AggregationPolicy.AVG));
  }

  if (!usedAfterGc.isEmpty()) {
    Collections.sort(usedAfterGc);
    long _maximumUsedAfterGc = usedAfterGc.get(usedAfterGc.size() - 1);
    results.add(new ScalarResult(Defaults.PREFIX + "gc.maximumUsedAfterGc",
      _maximumUsedAfterGc,
      "bytes",
      AggregationPolicy.AVG));
    System.out.println("maximumUsedAfterGc=" + _maximumUsedAfterGc);
  }
  if (!committedAfterGc.isEmpty()) {
    Collections.sort(committedAfterGc);
    long _committedUsedAfterGc = committedAfterGc.get(committedAfterGc.size() - 1);
    results.add(new ScalarResult(Defaults.PREFIX + "gc.maximumCommittedAfterGc",
      _committedUsedAfterGc,
      "bytes",
      AggregationPolicy.AVG));
    System.out.println("maximumCommittedAfterGc=" + _committedUsedAfterGc);
  }

  return results;
}