org.openjdk.jmh.infra.IterationParams Java Examples

The following examples show how to use org.openjdk.jmh.infra.IterationParams. 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 File: MemoryProfiler.java    From customized-symspell with 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 File: MemoryProfiler.java    From unsafe with 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 File: GenesisMemoryProfiler.java    From hadoop-ozone with 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 #4
Source File: GcProfiler.java    From cache2k-benchmark with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) {
  installHooks();

  long gcTime = 0;
  long gcCount = 0;
  for (GarbageCollectorMXBean bean : ManagementFactory.getGarbageCollectorMXBeans()) {
    gcCount += bean.getCollectionCount();
    gcTime += bean.getCollectionTime();
  }
  this.beforeGCCount = gcCount;
  this.beforeGCTime = gcTime;
  this.beforeAllocated = HotspotAllocationSnapshot.create();
  this.beforeTime = System.nanoTime();
}
 
Example #5
Source File: ForcedGcMemoryProfiler.java    From cache2k-benchmark with 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 #6
Source File: MiscResultRecorderProfiler.java    From cache2k-benchmark with 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) {
  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 #7
Source File: MemoryProfiler.java    From NNAnalytics with 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 #8
Source File: MemoryProfiler.java    From NNAnalytics with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeIteration(
    final BenchmarkParams benchmarkParams, final IterationParams iterationParams) {
  references = new Object[100000];
  referenceCount = 0;
  usedMemoryBeforeIteration = getUsedMemory();
}
 
Example #9
Source File: ReporterProfiler.java    From apm-agent-java with 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 #10
Source File: ReporterProfiler.java    From apm-agent-java with Apache License 2.0 5 votes vote down vote up
@Override
public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) {
    final Reporter reporter = getReporter();
    if (reporter != null) {
        reportedCountStart = reporter.getReported();
        droppedCountStart = reporter.getDropped();
        receivedBytesStart = getLong("server.received.bytes");
        receivedPayloadsStart = getLong("server.received.payloads");
    }
}
 
Example #11
Source File: CpuProfiler.java    From apm-agent-java with 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 #12
Source File: MemoryProfiler.java    From unsafe with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) {
}
 
Example #13
Source File: FlightRecorderProfiler.java    From cglib with Apache License 2.0 4 votes vote down vote up
private long getDurationSeconds(IterationParams warmup) {
    return warmup.getTime().convertTo(TimeUnit.SECONDS) * warmup.getCount();
}
 
Example #14
Source File: FlightRecorderProfiler.java    From calcite with Apache License 2.0 4 votes vote down vote up
private long getDurationSeconds(IterationParams warmup) {
  return warmup.getTime().convertTo(TimeUnit.SECONDS) * warmup.getCount();
}
 
Example #15
Source File: LinuxVmProfiler.java    From cache2k-benchmark with 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
Source File: MiscResultRecorderProfiler.java    From cache2k-benchmark with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams) {
  counters.clear();
}
 
Example #17
Source File: CpuProfiler.java    From apm-agent-java with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) {
    beforeProcessCpuTime = osMxBean.getProcessCpuTime();
}
 
Example #18
Source File: ForcedGcMemoryProfiler.java    From cache2k-benchmark with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams) {
usageAfterIteration = usageAfterSettled = null;
  enabled = true;
}
 
Example #19
Source File: GenesisMemoryProfiler.java    From hadoop-ozone with Apache License 2.0 4 votes vote down vote up
@Override
public void beforeIteration(BenchmarkParams benchmarkParams,
    IterationParams iterationParams) {

}
 
Example #20
Source File: GcProfiler.java    From cache2k-benchmark with 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;
}
 
Example #21
Source File: LinuxVmProfiler.java    From cache2k-benchmark with Apache License 2.0 2 votes vote down vote up
@Override
public void beforeIteration(final BenchmarkParams benchmarkParams, final IterationParams iterationParams) {

}
 
Example #22
Source File: MemoryProfiler.java    From customized-symspell with MIT License 2 votes vote down vote up
@Override
public void beforeIteration(BenchmarkParams benchmarkParams, IterationParams iterationParams) {

}