@Test public void timeMethod() throws Exception { Timeable cprime = new TestClass(); AspectJProxyFactory factory = new AspectJProxyFactory(cprime); factory.addAspect(MethodTimer.class); Timeable proxy = factory.getProxy(); proxy.timeMe(); final Double tot = CollectorRegistry.defaultRegistry.getSampleValue("test_class_sum"); Assert.assertNotNull(tot); assertEquals(0.02, tot, 0.01); }
@Around("timeable()") public Object timeMethod(ProceedingJoinPoint pjp) throws Throwable { String key = pjp.getSignature().toLongString(); Summary summary; final Lock r = summaryLock.readLock(); r.lock(); try { summary = summaries.get(key); } finally { r.unlock(); } if (summary == null) { summary = ensureSummary(pjp, key); } final Summary.Timer t = summary.startTimer(); try { return pjp.proceed(); } finally { t.observeDuration(); } }
MethodTimer { @Around("timeable()") public Object timeMethod(ProceedingJoinPoint pjp) throws Throwable { String key = pjp.getSignature().toLongString(); Summary summary; final Lock r = summaryLock.readLock(); r.lock(); try { summary = summaries.get(key); } finally { r.unlock(); } if (summary == null) { summary = ensureSummary(pjp, key); } final Summary.Timer t = summary.startTimer(); try { return pjp.proceed(); } finally { t.observeDuration(); } } }
MethodTimer { @Around("timeable()") public Object timeMethod(ProceedingJoinPoint pjp) throws Throwable { String key = pjp.getSignature().toLongString(); Summary summary; final Lock r = summaryLock.readLock(); r.lock(); try { summary = summaries.get(key); } finally { r.unlock(); } if (summary == null) { summary = ensureSummary(pjp, key); } final Summary.Timer t = summary.startTimer(); try { return pjp.proceed(); } finally { t.observeDuration(); } }  }
MethodTimer { @Around("timeable()") public Object timeMethod(ProceedingJoinPoint pjp) throws Throwable { String key = pjp.getSignature().toLongString(); Summary summary; final Lock r = summaryLock.readLock(); r.lock(); try { summary = summaries.get(key); } finally { r.unlock(); } if (summary == null) { summary = ensureSummary(pjp, key); } final Summary.Timer t = summary.startTimer(); try { return pjp.proceed(); } finally { t.observeDuration(); } }  @Pointcut("@annotation(io.prometheus.client.spring.web.PrometheusTimeMethod)") void annotatedMethod(); @Pointcut("annotatedMethod()") void timeable(); @Around("timeable()") Object timeMethod(ProceedingJoinPoint pjp); }
MethodTimer { @Around("timeable()") public Object timeMethod(ProceedingJoinPoint pjp) throws Throwable { String key = pjp.getSignature().toLongString(); Summary summary; final Lock r = summaryLock.readLock(); r.lock(); try { summary = summaries.get(key); } finally { r.unlock(); } if (summary == null) { summary = ensureSummary(pjp, key); } final Summary.Timer t = summary.startTimer(); try { return pjp.proceed(); } finally { t.observeDuration(); } }  @Pointcut("@annotation(io.prometheus.client.spring.web.PrometheusTimeMethod)") void annotatedMethod(); @Pointcut("annotatedMethod()") void timeable(); @Around("timeable()") Object timeMethod(ProceedingJoinPoint pjp);  }