@AuxCounters-like solution for events with stack traces?

Chris seahen123 at gmail.com
Fri Sep 8 19:22:44 UTC 2017


Hi all,

I have a benchmark where way too many objects are being created, but I have
no idea where or what class. Would it be possible, using @AuxCounters or
something similar, to emit something like a HashMultiset<StackTrace> or
Map<StackTrace, Integer> for reporting? StackTrace is a simple wrapper I've
built around StackTraceElement[] that does a truncation in the constructor
and implements equals, hashCode and toString.

Failing that, is it possible that JMH is swallowing the output of these
methods? Because either that, or
com.google.monitoring.runtime.instrumentation.AllocationRecorder isn't
working. If the output *is* being swallowed, how do I re-enable it?

// FIXME: Why isn't this outputting anything?
@Setup(Level.Trial)
public void setUp() {
  AllocationRecorder.addSampler((arrayLength, desc, newObj, size) -> {
    if (!desc.contains("StackTrace")) {
      LOG.info("Created %s (a %s of %d bytes)\n", newObj, desc, size);
      stackTraces.add(new
StackTrace(Thread.currentThread().getStackTrace()));
    }
  });
}

// FIXME: Why isn't this outputting anything either?
@TearDown(Level.Trial)
public void tearDown() {
  System.gc();
  for (StackTrace stackTrace : stackTraces) {
    LOG.info("%d objects created from:\n%s\n",
stackTraces.count(stackTrace), stackTrace);
  }
  stackTraces.clear();
}


More information about the jmh-dev mailing list