org.openjdk.jmh.results.AggregationPolicy Java Examples

The following examples show how to use org.openjdk.jmh.results.AggregationPolicy. 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: Cache2kMetricsRecorder.java    From cache2k-benchmark with 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 #3
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 #4
Source File: LinuxVmProfiler.java    From cache2k-benchmark with 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 #5
Source File: HitCountRecorder.java    From cache2k-benchmark with Apache License 2.0 6 votes vote down vote up
@TearDown(Level.Iteration)
public void tearDown() {
  synchronized (LOCK) {
    if (hitCount > 0) {
      addCounterResult("hitCount", hitCount, "hit", AggregationPolicy.AVG);
    }
    if (missCount > 0) {
      addCounterResult("missCount", missCount, "miss", AggregationPolicy.AVG);
    }
    if (opCount == 0) {
      opCount = hitCount + missCount;
    }
    addCounterResult("opCount", opCount, "op", AggregationPolicy.AVG);
    updateHitrate("tearDown(), hitCount=" + hitCount + ", missCount=" + missCount + ", opCount=" + opCount);
    hitCount = missCount = opCount = 0;
  }
}
 
Example #6
Source File: HitCountRecorder.java    From cache2k-benchmark with Apache License 2.0 5 votes vote down vote up
public static void recordMissCount(long _missCount) {
  synchronized (LOCK) {
    addCounterResult(
      "missCount", _missCount, "op", AggregationPolicy.AVG
    );
    updateHitrate("miss=" + _missCount);
  }
}
 
Example #7
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 #8
Source File: MiscResultRecorderProfiler.java    From cache2k-benchmark with Apache License 2.0 5 votes vote down vote up
/**
 * Insert the counter value as secondary result. If a value is already inserted the
 * counter value is added to the existing one. This can be used to collect and sum up
 * results from different threads.
 */
public static void addCounterResult(String key, long _counter, String _unit, AggregationPolicy _aggregationPolicy) {
  CounterResult r = counters.computeIfAbsent(key, any -> new CounterResult());
  r.aggregationPolicy = _aggregationPolicy;
  r.unit = _unit;
  r.counter.addAndGet(_counter);
  r.key = key;
}
 
Example #9
Source File: HitCountRecorder.java    From cache2k-benchmark with Apache License 2.0 5 votes vote down vote up
/** Called for each thread */
private static void updateHitrate(String s) {
  long _missCountSum = getCounterResult("missCount");
  long _opCountSum = getCounterResult("opCount");
  if (_opCountSum == 0L) {
    return;
  }
  double _hitRate = 100.0 - _missCountSum * 100.0 / _opCountSum;
  System.err.println(Thread.currentThread() + " " + s + ", opSum=" + _opCountSum + ", missSum=" + _missCountSum + ", hitRate=" + _hitRate);
  setResult("hitrate", _hitRate, "percent", AggregationPolicy.AVG);
}
 
Example #10
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 #11
Source File: HitCountRecorder.java    From cache2k-benchmark with Apache License 2.0 5 votes vote down vote up
public static void recordOpCount(long _opCount) {
  synchronized (LOCK) {
    addCounterResult(
      "opCount", _opCount, "op", AggregationPolicy.AVG
    );
    updateHitrate("ops=" + _opCount);
  }
}
 
Example #12
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 #13
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 #14
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 #15
Source File: OptionalScalarResult.java    From cache2k-benchmark with Apache License 2.0 4 votes vote down vote up
public OptionalScalarResult(String label, double n, String unit, AggregationPolicy policy) {
	this(label, of(n), unit, policy);
}
 
Example #16
Source File: OptionalScalarResult.java    From cache2k-benchmark with Apache License 2.0 4 votes vote down vote up
OptionalScalarResult(String label, Statistics s, String unit, AggregationPolicy policy) {
	super(ResultRole.SECONDARY, label, s, unit, policy);
}
 
Example #17
Source File: MiscResultRecorderProfiler.java    From cache2k-benchmark with Apache License 2.0 4 votes vote down vote up
/**
 * Insert the counter value as secondary result. An existing counter value is replaced.
 */
public static void setResult(String key, double _result, String _unit, AggregationPolicy _aggregationPolicy) {
  setResult(new ScalarResult(SECONDARY_RESULT_PREFIX + key, _result, _unit, _aggregationPolicy));
}
 
Example #18
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 #19
Source File: OptionalScalarResult.java    From cache2k-benchmark with Apache License 2.0 votes vote down vote up
AggregationPolicy getPolicy() { return policy; }