public Object profileMethod(ProceedingJoinPoint pjp) throws Throwable { Timeable timeable = map.get(pjp.getTarget()); if (timeable == null) { return pjp.proceed(); } EventMetricCollector collector = timer.getCollector(); try { collector.startTiming(timeable, pjp.getSignature().getName()); return pjp.proceed(); } finally { collector.stopTiming(); } }
@Test public void itShouldNotIncrementNestedCountersForNestedCollectors() { collector.startTiming(TOP_LEVEL_GROUP, "topLevelEvent"); collector.startTiming(NESTED_GROUP, "nestedEvent"); collector.stopTiming(); collector.stopTiming(); verify(nestedCounter, never()).getCounterForMetric(any(ThreadMetric.class)); }
@Test public void itShouldIncrementTopLevelCountersForNestedCollectors() { collector.startTiming(TOP_LEVEL_GROUP, "topLevelEvent"); collector.startTiming(NESTED_GROUP, "nestedEvent"); collector.stopTiming(); collector.stopTiming(); verify(topLevelCounter).getCounterForMetric(any(ThreadMetric.class)); verify(topLevelMetricCounters).incrementCounters(anyLong()); }
@Test public void itShouldIncrementCountersForSingleCollectors() { collector.startTiming(TOP_LEVEL_GROUP, "topLevelEvent"); collector.stopTiming(); verify(topLevelCounter).getCounterForMetric(any(ThreadMetric.class)); verify(topLevelMetricCounters).incrementCounters(anyLong()); }
@Override public void run() { EventMetricCollector collector = timer.getCollector(); for (int i = 1; i < 30; i++) { try { context.put("Name", randomName()); context.put("Company", randomCompany()); collector.startTiming(this, action); doJob(i); collector.pauseForForward(); collector.startTiming(this, "frog"); collector.stopTiming(); collector.resumeAfterForward(); collector.stopTiming(); context.remove("Name"); context.remove("Company"); } catch (Exception e) { throw new RuntimeException(e); } } }
@Override public void handleMessage(XMLMessage message) throws Fault { Exchange exchange = message.getExchange(); // TODO break out into a strategy (not JAXRS-specific) OperationResourceInfo operationResourceInfo = exchange.get(OperationResourceInfo.class); if (operationResourceInfo == null) { message.getInterceptorChain().doIntercept(message); return; } // TODO annotate with a better name? String methodName = operationResourceInfo.getMethodToInvoke().getName(); // TODO annotate with a better name? Object key = operationResourceInfo.getClassResourceInfo().getResourceProvider() .getInstance(); if (!(key instanceof Timeable)) { message.getInterceptorChain().doIntercept(message); return; } EventMetricCollector collector = timer.getCollector(); collector.startTiming((Timeable) key, methodName); try { message.getInterceptorChain().doIntercept(message); } finally { collector.stopTiming(); } } }