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(); } }
StepMeasurements m = entry.getValue().getInProgressMeasurements(); if (m != null) { String event = m.getBackTrace();
@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); } } }
@Test public void testValuesConvertedToStringsForExport() { ThreadContext context = new ThreadContext(); context.put("stringvalue", "floop"); context.put("intvalue", 99); Timeable t = new Timeable() { @Override public void setEventTimer(EventTimer timer) { } }; EventTimer timer = new EventTimer("foo", new MonitorableRegistry(), ThreadMetricSuite.blank(), false, false, Collections.<StepMeasurementSink>singletonList(new LoggerSink())); timer.registerTimeable(t, "foo"); timer.getCollector().startTiming(t, "stuff"); InProgressSnapshot snapshot = InProgressSnapshot.capture(timer, context); TabularData data = JmxInProgressMonitor.TO_TABULAR_DATA.apply(snapshot); assertEquals(SimpleType.STRING, data.getTabularType().getRowType().getType("stringvalue")); assertEquals(SimpleType.STRING, data.getTabularType().getRowType().getType("intvalue")); }
@Before public void givenAnEventMetricCollector() { MockitoAnnotations.initMocks(this); Map<Object, EventCounters> perEventCounters = Maps.newHashMap(); perEventCounters.put(TOP_LEVEL_GROUP, topLevelCounter); perEventCounters.put(NESTED_GROUP, nestedCounter); collector = new EventMetricCollector(perEventCounters, newArrayList(stepMeasurementSink)); when(topLevelCounter.getEventGroupName()).thenReturn(TOP_LEVEL_GROUP); when(nestedCounter.getEventGroupName()).thenReturn(NESTED_GROUP); EventMetricCounters invocationCounter = mock(EventMetricCounters.class); when(topLevelCounter.getInvocationCounter()).thenReturn(invocationCounter); ThreadMetric threadMetric = mock(ThreadMetric.class); when(topLevelCounter.getMetricSources()).thenReturn(newArrayList(threadMetric)); when(topLevelCounter.getCounterForMetric(threadMetric)).thenReturn(topLevelMetricCounters); }
@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 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(); } } }