@Override public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException { EtmPoint point = (EtmPoint) request.getAttribute(JETM_JAXRS_POINT); if (point != null) { point.collect(); } }
public void afterPhase(PhaseEvent event) { FacesContext facesContext = event.getFacesContext(); // stop recording current phase time EtmPoint point = (EtmPoint) facesContext.getAttributes().get(CURRENT_PHASE_POINT); if (point != null) { // alter name if we encounter an exception Iterator<ExceptionQueuedEvent> it = facesContext.getExceptionHandler().getUnhandledExceptionQueuedEvents().iterator(); if (it.hasNext()) { ExceptionQueuedEvent exceptionQueuedEvent = it.next(); point.alterName(point.getName() + " [" + exceptionQueuedEvent.getContext().getException().getClass().getSimpleName() + "]"); } point.collect(); facesContext.getAttributes().remove(CURRENT_PHASE_POINT); } }
public String format(EtmPoint aEtmPoint) { String parentName = aEtmPoint.getParent() == null ? "" : calculateParentHierarchie(aEtmPoint); return new StringBuffer(). append("measurementPoint=<"). append(aEtmPoint.getName()). append(">, parent=<"). append(parentName). append(">, transactionTime=<"). append(numberFormat.format(aEtmPoint.getTransactionTime())). append(">, recordingTime=<"). append(aEtmPoint.getStartTimeMillis()). append(">").toString(); }
protected String calculateParentHierarchie(EtmPoint aEtmPoint) { // todo remove string concat String hierarchie = ""; EtmPoint parent = aEtmPoint.getParent(); while (parent != null) { hierarchie = ";" + parent.getName() + hierarchie; parent = parent.getParent(); } return hierarchie.substring(1); } }
@AroundInvoke public Object measure(InvocationContext ctx) throws Exception { String targetMethod = calculateMethodName(ctx); EtmPoint point = EtmManager.getEtmMonitor().createPoint(targetMethod); try { return ctx.proceed(); } catch (Exception e) { point.alterName(targetMethod + "[ " + e.getClass().getSimpleName() + "]"); throw e; } finally { point.collect(); } }
public boolean matches(EtmPoint aPoint) { String name = aPoint.getName(); if (validNames.contains(name)) { return true; } for (int i = 0; i < pattern.length; i++) { Matcher matcher = pattern[i].matcher(name); if (matcher.matches()) { synchronized (validNames) { validNames.add(name); } return true; } } return false; } }
/** * Adds a transaction to the current aggregate. * * @param transaction The transaction to add. */ public void addTransaction(EtmPoint transaction) { double miliseconds = transaction.getTransactionTime(); measurements++; total += miliseconds; max = max > miliseconds ? max : miliseconds; min = min > miliseconds || min == 0 ? miliseconds : min; }
private void analyzeNested(Map aggregationPoints, EtmPoint[] aEtmPoints, int i) { EtmPoint current = aEtmPoints[i - 1]; ExecutionAggregate aggregate = (ExecutionAggregate) aggregationPoints.get(current.getName()); assertNotNull(aggregate); assertEquals(current.getName(), aggregate.getName()); assertEquals(1, aggregate.getMeasurements()); assertEquals(current.getTransactionTime(), aggregate.getTotal(), 0.0); assertEquals(current.getTransactionTime(), aggregate.getMin(), 0.0); assertEquals(current.getTransactionTime(), aggregate.getMax(), 0.0); i--; if (i != 0) { assertTrue(aggregate.hasChilds()); analyzeNested(aggregate.getChilds(), aEtmPoints, i); } }
protected long calculateTimestamp(EtmPoint measurement) { return Util.getTimestamp(new Date(measurement.getStartTimeMillis())); }
protected void doVisitPostCollect(MeasurementPoint aPoint) { EtmPoint point = (EtmPoint) currentParent.get(); if (point != null) { currentParent.set(point.getParent()); } }
public void processAction(ActionEvent actionEvent) throws AbortProcessingException { UIComponent component = actionEvent.getComponent(); EtmPoint etmRootPoint = (EtmPoint) FacesContext.getCurrentInstance().getAttributes().get(EtmJsfPlugin.ROOT_ETM_POINT); if (etmRootPoint != null) { MethodExpression methodExpression = null; if (component instanceof ActionSource2) { methodExpression = ((ActionSource2) component).getActionExpression(); if (methodExpression != null) { etmRootPoint.alterName("JSF Action " + methodExpression.getExpressionString()); } } if (methodExpression == null && component instanceof ActionSource) { MethodBinding methodBinding = ((ActionSource) component).getAction(); if (methodBinding != null) { etmRootPoint.alterName("JSF Action " + methodBinding.getExpressionString()); } } } delegate.processAction(actionEvent); } }
public void add(EtmPoint point) { // short cut for parent == null; if (point.getParent() == null) { super.add(point); return; } // TODO check alternative strategy to improve performance // find tree root node LinkedList path = new LinkedList(); path.add(point); EtmPoint rootNode = point.getParent(); while (rootNode != null) { path.addFirst(rootNode); rootNode = rootNode.getParent(); } rootNode = (EtmPoint) path.removeFirst(); ExecutionAggregate aggregate = getAggregate(rootNode.getName()); aggregate.appendPath(path); }
public void add(EtmPoint point) { ExecutionAggregate aggregate = getAggregate(point.getName()); aggregate.addTransaction(point); }
/** * Alter name in case an exception is caught during processing. Altering the * name takes place after executing target method. Ensure that you never cause * an exception within this code. * * @param aEtmPoint The EtmPoint to alter. * @param t The caught throwable t. */ protected void alterNamePostException(EtmPoint aEtmPoint, Throwable t) { aEtmPoint.alterName(aEtmPoint.getName() + " [" + calculateShortName(t.getClass()) + "]"); }
/** * Adds a transaction to the current aggregate. * * @param transaction The transaction to add. */ public void addTransaction(EtmPoint transaction) { double miliseconds = transaction.getTransactionTime(); measurements++; total += miliseconds; max = max > miliseconds ? max : miliseconds; min = min > miliseconds || min == 0 ? miliseconds : min; }
protected void doVisitPostCollect(MeasurementPoint aPoint) { EtmPoint point = (EtmPoint) currentParent.get(); if (point != null) { currentParent.set(point.getParent()); } }
public void nestedMethod() { EtmPoint point = etmMonitor.createPoint("BusinessService:nestedMethod"); try { Thread.sleep((long) (15d * Math.random())); } catch (InterruptedException e) { // ignored } finally { point.collect(); } } }
public void beforePhase(PhaseEvent event) { FacesContext facesContext = event.getFacesContext(); EtmPoint oldPoint = (EtmPoint) facesContext.getAttributes().get(CURRENT_PHASE_POINT); if (oldPoint != null) { // do some cleanup, should never happen actually oldPoint.alterName(oldPoint.getName() + " - uncollected"); oldPoint.collect(); } String symbolicName = "JSF Phase " + event.getPhaseId().getOrdinal() + " - " + String.valueOf(event.getPhaseId()); EtmPoint point = EtmManager.getEtmMonitor().createPoint(symbolicName); facesContext.getAttributes().put(CURRENT_PHASE_POINT, point); }
public void testOutput() { EtmPoint etmPoint = new TestPointGenerator().getEtmPoint(); DefaultOutputFormatter formatter = new DefaultOutputFormatter(); // validate MS format NumberFormat numberFormat = NumberFormat.getInstance(Locale.getDefault()); numberFormat.setMinimumFractionDigits(3); numberFormat.setMaximumFractionDigits(3); numberFormat.setGroupingUsed(false); String s = formatter.format(etmPoint); assertTrue(s.indexOf(etmPoint.getName()) > 0); if (etmPoint.getParent() != null) { assertTrue(s.indexOf("parent=<" + etmPoint.getParent().getName() + ">") > 0); } assertTrue(s.indexOf(String.valueOf(etmPoint.getStartTimeMillis())) > 0); assertTrue(s.indexOf(numberFormat.format(etmPoint.getTransactionTime())) > 0); }