/** * 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); } } }
/** * 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); }
@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")); }
Monitor timer = MonitorFactory.start("totaltime"); for (int i = 1; i <= 10; i++) { System.out.println(MonitorFactory.add("NIC.bytes.sent", "bytes", i * 1000)); System.out.println(MonitorFactory.add("negativetest", "neg", -1000.0 * i)); m = MonitorFactory.start("purchasesTimeTestNoRange"); MonitorFactory.add("purchasesNoRange", "dollars", 1000.0); m = MonitorFactory.start("testTimerTimeTest"); for (int i = 1; i <= 1000000; i++) MonitorFactory.start("testTimer").stop(); MonitorFactory.add("purchases", "dollars", i * 50); System.out.println(MonitorFactory.add("NIC.bytes.received", "bytes", 250.0)); System.out.println(MonitorFactory.add("NIC.bytes.received", "bytes", 250.0)); MonitorFactory.add("timetest", "ms.", i * 5); System.out.println(MonitorFactory.getMonitor("purchases", "dollars").getHits()); System.out.println(MonitorFactory.getTimeMonitor("testTimer").getHits()); System.out.println(MonitorFactory.getTimeMonitor("testtimer").getHits()); System.out.println("Total time=" + timer.getTotal()); MonitorFactory.reset(); MonitorFactory.setRangeDefault("dollars", getTestHolder()); m = MonitorFactory.start("purchasesTimeTestRange");
/** * Run the code in a new thread took from a thread pool. * * @param invocation * The code to run * @return The future object, to know when the task is completed */ public static Future<?> invoke(Invocation invocation) { Monitor monitor = MonitorFactory.getMonitor("Invoker queue size", "elmts."); monitor.add(executor.getQueue().size()); invocation.waitInQueue = MonitorFactory.start("Waiting for execution"); return executor.submit(invocation); }
@Override public MonitorComposite get(String instanceKey) { if (INSTANCE.equalsIgnoreCase(instanceKey)) { return MonitorFactory.getRootMonitor(); } return null; }
@SuppressWarnings("all") public static Monitor getTimeMonitor(Class clazz, String label) { String labeltmp = getMonitorPrefix(clazz)+label; return MonitorFactory.getTimeMonitor(labeltmp); }
public void nullMonitor2() throws Exception { // The null monitor has the best possible performance System.out.println("\nNullMonitor2() - Factory disabled so a NullMonitor is returned"); System.out.println("\tMonitorFactory.setEnabled(false);"); System.out.println("\tMonitor mon=MonitorFactory.start('pages.admin');"); System.out.println("\tmon.stop()"); MonitorFactory.setEnabled(false); for (int i=0; i<testIterations; i++) { testMon=MonitorFactory.start("pages.admin"); testMon.stop(); } MonitorFactory.setEnabled(true); }
MonitorFactory.getTimeMonitor("addNode").start(); Monitor mon = MonitorFactory.start("lp"); double accuracy = learningProblem.getAccuracyOrTooWeak(description, noise); mon.stop();
@SuppressWarnings("all") public static Monitor getStatisticMonitor( String label) { return MonitorFactory.getMonitor(label, "double"); } @SuppressWarnings("all")
@Override public void remove(String instanceKey) { localJamonData.remove(instanceKey); Monitor mon = MonitorFactory.start(getJamonLabel(".remove()")); try { jamonDataPersister.remove(instanceKey); } catch(Throwable t) { MonitorFactory.addException(mon, t); } finally { mon.stop(); } }
/** * Return hits/count of the passed in monitor if it exists otherwise return 0 * * @param label jamon label * @param units jamon units * @return count */ static long getCount(String label, String units) { if (MonitorFactory.exists(label, units)) { Monitor mon = MonitorFactory.getMonitor(label, units); return (long) mon.getHits(); } return 0; }
public void addMonitor() throws Exception { System.out.println("Calling add...\n"); System.out.println("\tMonitorFactory.add('label','units',1);"); for (int i=0; i<testIterations; i++) { MonitorFactory.add("label","units",1); } System.out.println(MonitorFactory.getMonitor("label", "units")); }
public void init(MonKeyImp oldMonkey) { Monitor[] marr = new Monitor[sizeOfResultVector]; for (int i = 0; i < sizeOfResultVector; i++) { MonKeyImp newMonKey = mon(oldMonkey, i); if (newMonKey.getUnits().equals(JamonMonitorLogger.MS)) { marr[i] = MonitorFactory.getTimeMonitor(newMonKey); } else { marr[i] = MonitorFactory.getMonitor(newMonKey); } } MonitorComposite m = new MonitorComposite(marr); mcs.add(m); put(oldMonkey, m); putRev(m, oldMonkey); }
/** * Start the monitor. */ public void start() { if(this.isActive) { // when reseting using the JAMon GUI the custom ranges are discarded MonitorFactory.setRangeDefault(MONITOR_LABEL, Jamon2PerformanceMonitorImpl.rangeHolder); // do the internal house-keeping this.startTime = System.currentTimeMillis(); MethodToStringBuilderImpl methodToStringBuilder = new MethodToStringBuilderImpl(this.method, 0); String methodSignature = methodToStringBuilder.toString(); this.monitor = MonitorFactory.getMonitor(methodSignature, MONITOR_LABEL); this.monitor.start(); } }
.getExceptionDetail()); printDebug(testCounter + ".3) " + "jamon data - " + message, MonitorFactory.getRootMonitor().getBasicData()); MonitorFactory.reset();
@After public void tearDown() { MonitorFactory.reset(); }
@Override public void put(String instanceKey) { Monitor mon = MonitorFactory.getTimeMonitor(getJamonLabel(".put()")); // only allow 1 process to put at the sametime. if (mon.getActive() < 1) { mon.start(); try { if (instanceKey!=null) { jamonDataPersister.put(instanceKey); } } catch(Throwable t) { MonitorFactory.addException(mon, t); } finally { mon.stop(); } } }
public static void main(String[] args) throws Exception { JamonHelloWorld helloWorld = new JamonHelloWorld(); System.out.println(helloWorld.hiSteve()); helloWorld.run(args); System.out.println(MonitorFactory.getReport()); } }