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(); } }
@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(); } } }
@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")); }