AllocationMonitorAspect { @AfterReturning(pointcut = "call(*.new(..))", returning = "obj", argNames = "jp,obj") public void afterAllocation(final JoinPoint jp, final Object obj) { if (RECORD_OBJECT_SIZE) { RECORDER.getRecorder(jp.getSourceLocation().getWithinType()). record(InstrumentationHelper.getObjectSize(obj)); } else { RECORDER.getRecorder(jp.getSourceLocation().getWithinType()).record(1); } }  @AfterReturning(pointcut = "call(*.new(..))", returning = "obj", argNames = "jp,obj") void afterAllocation(final JoinPoint jp, final Object obj); static final int SAMPLE_TIME_MILLIS; }
@Test public void testAfterAllocation() throws InterruptedException, IOException { System.setProperty("spf4j.perf.allocations.sampleTimeMillis", "1000"); MemoryUsageSampler.start(500); OpenFilesSampler.start(500, 512, 1000, false); for (int i = 0; i < 1000; i++) { LOG.debug("T{}", i); if (i % 100 == 0) { Thread.sleep(500); } } testAllocInStaticContext(); TestClass.testAllocInStaticContext(); RecorderFactory.MEASUREMENT_STORE.flush(); MeasurementStoreQuery query = RecorderFactory.MEASUREMENT_STORE.query(); Collection<Schema> measurements = query.getMeasurements((x) -> "heap_used".equals(x)); Assert.assertEquals(1, measurements.size()); MemoryUsageSampler.stop(); OpenFilesSampler.stop(); }