@Override public void handle(StepMeasurements measurements, int depth) { String depthText = buildDepthString(depth); String metricData = buildMetricDataString(measurements.getMetricInstances()); logger.info(String.format("%s\t%s\t%s\t%s", depthText, measurements.getForwardTrace(), measurements .getBackTrace(), metricData)); }
public StepMeasurements(StepMeasurements parent, String eventName, String action) { this.parent = parent; if (parent != null) { parent.addChildExecution(this); } this.eventName = eventName; this.action = action; }
public void pauseForForward() { current.pauseAll(); }
/** * @return a nicely-formatted list of all the events taken to reach the one under * measurement (including that one as the last element) */ String getBackTrace() { if (parent == null) { return stackTraceElement(); } return parent.getBackTrace() + "/" + stackTraceElement(); }
/** * @return a nicely-formatted list of all the events invoked after the one under * measurement (including that one as the first element) */ String getForwardTrace() { if (children.isEmpty()) { return stackTraceElement(); } else if (children.size() == 1) { return stackTraceElement() + "/" + children.get(0).getForwardTrace(); } else { // Handles the 'freak case' where one event may forward directly to MORE than one // 'child'. I have no idea if this ever happens, but we might as well handle it. List<String> childTraces = new ArrayList<String>(children.size()); for (StepMeasurements child : children) { childTraces.add(child.getForwardTrace()); } return stackTraceElement() + "/{" + Joiner.on('|').join(childTraces) + "}"; } }
public void testForwardTraceWithMultipleChildrenShowsCorrectPath() { StepMeasurements timing = new StepMeasurements(null, PARENT, null); new StepMeasurements(timing, CHILD, null); new StepMeasurements(timing, OTHER_CHILD, null); assertEquals("floop/{bloop|gloop}", timing .getForwardTrace()); }
public void testBackTraceWithParentShowsCorrectPath() { StepMeasurements mummy = new StepMeasurements(null, PARENT, null); StepMeasurements timing = new StepMeasurements(mummy, CHILD, null); assertEquals("floop/bloop", timing.getBackTrace()); }
public void testParentSettingInConstructor() { StepMeasurements mummy = new StepMeasurements(null, PARENT, null); StepMeasurements timing = new StepMeasurements(mummy, CHILD, null); assertEquals(mummy, timing.getParent()); }
public void startTiming(Object eventGroup, String event) { StepMeasurements newTiming = new StepMeasurements(current, perEventCounters.get(eventGroup).getEventGroupName(), event); for (ThreadMetric metric : perEventCounters.get(eventGroup).getMetricSources()) { newTiming.addMetricInstance(new MetricMeasurement(metric, Thread.currentThread())); } current = newTiming; topLevelEvent.addFirst(eventGroup); depth++; if (top == null) { top = newTiming; } current.startAll(); }
public void stopTiming() { current.stopAll(); depth--; Object event = topLevelEvent.removeFirst(); for (MetricMeasurement metric : current.getMetricInstances()) { EventMetricCounters counter = counters.getCounterForMetric(metric .getMetricSource()); current = current.getParent(); if (depth == 0) { top = null;
StepMeasurements m = entry.getValue().getInProgressMeasurements(); if (m != null) { String event = m.getBackTrace(); Map<ThreadMetric, Long> snapshotValues = m.snapshotValues(); Map<String, Object> keyedValues = new HashMap<String, Object>(); keyedValues.put("Thread name", entry.getKey().getName());
public void resumeAfterForward() { current.resumeAll(); }
public void testForwardTraceWithOneChildShowsCorrectPath() { StepMeasurements timing = new StepMeasurements(null, PARENT, null); new StepMeasurements(timing, CHILD, null); assertEquals("floop/bloop", timing.getForwardTrace()); }
public void testBackTraceShowsAction() { StepMeasurements timing = new StepMeasurements(null, PARENT, "scratchButt"); assertEquals("floop:scratchButt", timing.getBackTrace()); }
public void testNullParent() { StepMeasurements timing = new StepMeasurements(null, PARENT, null); assertNull(timing.getParent()); }
public void testForwardTraceShowsAction() { StepMeasurements timing = new StepMeasurements(null, PARENT, "scratchButt"); assertEquals("floop:scratchButt", timing.getForwardTrace()); }
public void testBackTraceWithNoParentShowsOnlySelf() { StepMeasurements timing = new StepMeasurements(null, PARENT, null); assertEquals(PARENT, timing.getBackTrace()); }
public void testForwardTraceWithNoChildrenShowsOnlySelf() { StepMeasurements timing = new StepMeasurements(null, PARENT, null); assertEquals(PARENT, timing.getForwardTrace()); }