/** * Count the thrown exception and put the stack trace in the details portion of the key. * This will allow the stack trace to be viewed in the JAMon web application. */ protected void trackException(MonKey key, Throwable ex) { String stackTrace = "stackTrace=" + Misc.getExceptionTrace(ex); key.setDetails(stackTrace); // Specific exception counter. Example: java.lang.RuntimeException MonitorFactory.add(new MonKeyImp(ex.getClass().getName(), stackTrace, "Exception"), 1); // General exception counter which is a total for all exceptions thrown MonitorFactory.add(new MonKeyImp(MonitorFactory.EXCEPTIONS_LABEL, stackTrace, "Exception"), 1); }
public aspect MonitorAspect { pointcut monitor() : execution(* *.ClassToMonitor.methodToMonitor(..)); Object arround() : monitor() { Monitor monitor = MonitorFactory.start(thisJoinPoint.toShortString()); Object returnedObject = proceed(); monitor.stop(); return returnedObject; } }
CompositeListener composite = new CompositeListener(); composite.registerListener(listener1); composite.registerListener(listener2); component.setOnEventListener(composite);
/** * Wraps the invocation with a JAMon Monitor and writes the current * performance statistics to the log (if enabled). * @see com.jamonapi.MonitorFactory#start * @see com.jamonapi.Monitor#stop */ @Override protected Object invokeUnderTrace(MethodInvocation invocation, Log logger) throws Throwable { String name = createInvocationTraceName(invocation); MonKey key = new MonKeyImp(name, name, "ms."); Monitor monitor = MonitorFactory.start(key); try { return invocation.proceed(); } catch (Throwable ex) { trackException(key, ex); throw ex; } finally { monitor.stop(); if (!this.trackAllInvocations || isLogEnabled(logger)) { writeToLog(logger, "JAMon performance statistics for method [" + name + "]:\n" + monitor); } } }
private JAMonBufferListener getExceptionBufferListener() { if (MonitorFactory.exists(MonitorFactory.EXCEPTIONS_LABEL, EXCEPTION)) { Monitor mon = MonitorFactory.getMonitor(MonitorFactory.EXCEPTIONS_LABEL, EXCEPTION); if (mon.hasListener("value", "FIFOBuffer")) { JAMonListener bufferListener = mon.getListenerType("value").getListener("FIFOBuffer"); if (bufferListener instanceof JAMonBufferListener) { return (JAMonBufferListener) bufferListener; } } } return null; }
/** Ranges are implemented as JAMonListeners */ public void processEvent(Monitor mon) { double value=mon.getLastValue(); getFrequencyDist(value).add(value); }
public JAMonDetailRow getJAMonDetailRow() { if (monData.enabled) { synchronized (monData) { return new JAMonDetailValue(getMonKey().getDetailLabel(), monData.lastValue, monData.activityStats.thisActive.getCount(), monData.lastAccess); } } else return JAMonDetailValue.NULL_VALUE; }
private MonitorImp createMon(MonKey key, boolean isPrimary, boolean isTimeMonitor) { ActivityStats activityStats=new ActivityStats(new Counter(), primaryActive, allActive); // get default range for this type and assign it to the monitor RangeImp range=rangeFactory.getRangeDefault(key.getRangeKey(), activityStats); MonitorImp mon=new MonitorImp(key, range, activityStats, isTimeMonitor); mon.setPrimary(isPrimary); return mon; }
public TimeMon2() { super(new MonKeyImp("timer","ms."),new MonInternals()); monData.activityStats=new ActivityStats(); monData.isTimeMonitor=true; }
@Test public void testInvokeUnderTraceWithNormalProcessing() throws Throwable { given(mi.getMethod()).willReturn(String.class.getMethod("toString")); interceptor.invokeUnderTrace(mi, log); assertTrue("jamon must track the method being invoked", MonitorFactory.getNumRows() > 0); assertTrue("The jamon report must contain the toString method that was invoked", MonitorFactory.getReport().contains("toString")); }
public JAMonDetailValue getJAMonDetailRow() { if (monData.enabled) { synchronized (monData) { return new JAMonDetailValue(getMonKey(), monData.lastValue, monData.getThisActiveCount(), monData.lastAccess); } } else return JAMonDetailValue.NULL_VALUE; }
private static void init() { // enable the factory by default. boolean isKeySizeTrackingEnabled= (factory==null) ? false : factory.isTotalKeySizeTrackingEnabled(); factory = debugFactory = enabledFactory = new FactoryEnabled(); if (isKeySizeTrackingEnabled) { factory.enableTotalKeySizeTracking(); } disabledFactory = new FactoryDisabled(enabledFactory); setDebugEnabled(false); }
public List getRowData(List rowData) { monData.key.getRowData(rowData); getThisRowData(rowData); if (monData.range!=null) monData.range.getRowData(rowData); return rowData; }
public List getRowDisplayData(List rowData) { monData.key.getRowDisplayData(rowData); getThisRowData(rowData); if (monData.range!=null) monData.range.getRowDisplayData(rowData); return rowData; }
private void addExceptionFifoBufferListener() { Monitor mon = getMonitor(MonitorFactory.EXCEPTIONS_LABEL, "Exception"); if (!mon.hasListener("value", "FIFOBuffer")) { mon.addListener("value", JAMonListenerFactory.get("FIFOBuffer")); } }
private MonitorImp getNanoMonitor(MonKey key) { boolean isPrimary=false; boolean isTimeMon=true; MonitorImp mon=getMonitor.getMon(key, isPrimary, isTimeMon); if (mon.isEnabled()) { mon = new TimeMonNano(key, mon.getMonInternals()); } return mon; }
public List getDisplayHeader(List header) { monData.key.getDisplayHeader(header); getThisData(header); if (monData.range!=null) monData.range.getDisplayHeader(header); return header; }
@After public void tearDown() { MonitorFactory.reset(); }
@Test public void testInvokeUnderTraceWithExceptionTracking() throws Throwable { given(mi.getMethod()).willReturn(String.class.getMethod("toString")); given(mi.proceed()).willThrow(new IllegalArgumentException()); try { interceptor.invokeUnderTrace(mi, log); fail("Must have propagated the IllegalArgumentException"); } catch (IllegalArgumentException expected) { } assertEquals("Monitors must exist for the method invocation and 2 exceptions", 3, MonitorFactory.getNumRows()); assertTrue("The jamon report must contain the toString method that was invoked", MonitorFactory.getReport().contains("toString")); assertTrue("The jamon report must contain the generic exception: " + MonitorFactory.EXCEPTIONS_LABEL, MonitorFactory.getReport().contains(MonitorFactory.EXCEPTIONS_LABEL)); assertTrue("The jamon report must contain the specific exception: IllegalArgumentException'", MonitorFactory.getReport().contains("IllegalArgumentException")); }
@Before public void setUp() { MonitorFactory.reset(); }