use of org.spf4j.stackmonitor.StackTrace in project spf4j by zolyfarkas.
the class SamplingAllocationMonitorAspect method afterAllocation.
@AfterReturning(pointcut = "call(*.new(..))", returning = "obj", argNames = "jp,obj")
public void afterAllocation(final JoinPoint jp, final Object obj) {
MutableInteger counter = ThreadLocalCounter.get();
int value = counter.getValue();
if (value < SAMPLE_COUNT) {
counter.setValue(value + 1);
} else {
// the stack trace get and the object size method are expensive to be done at every allocation...
counter.setValue(0);
StackTrace st = StackTrace.from(Thread.currentThread().getStackTrace(), 2);
RECORDER.getRecorder(st).record(InstrumentationHelper.getObjectSize(obj));
}
}
Aggregations