Search in sources :

Example 1 with StackTrace

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));
    }
}
Also used : StackTrace(org.spf4j.stackmonitor.StackTrace) MutableInteger(org.spf4j.base.MutableInteger) JoinPoint(org.aspectj.lang.JoinPoint) AfterReturning(org.aspectj.lang.annotation.AfterReturning)

Aggregations

JoinPoint (org.aspectj.lang.JoinPoint)1 AfterReturning (org.aspectj.lang.annotation.AfterReturning)1 MutableInteger (org.spf4j.base.MutableInteger)1 StackTrace (org.spf4j.stackmonitor.StackTrace)1