public String getMetricName() { return metricSource.getMetricName(); }
public AbstractQuantity<?> totalValue() { Preconditions.checkState(endValue != null, "Can't measure time until timer is stopped"); return NumberQuantity.of(endValue - startValue, metricSource.getUnit()); }
public long inProgressValue() { Long start = startValue; Long snapshot = metricSource.getValueForThread(thread); if (start == null || snapshot == null) { return 0; } return snapshot - start; }
private EventCounters getCounterSet(String eventGroup) { EventMetricCounters invocationCounter = createEventMetricCounters(eventGroup, "count", "Total number of times the event was directly triggered", ONE); EventCounters counters = new EventCounters(invocationCounter, cleanName(eventGroup)); for (ThreadMetric metric : metricSuite.metrics()) { EventMetricCounters timingCounter = createEventMetricCounters(eventGroup, metric .getCounterSuffix(), metric.getDescription(), metric.getUnit()); counters.addMetric(metric, timingCounter); } return counters; }
names.add(metric.getMetricName()); descriptions.add(metric.getDescription()); classes.add(Long.class); keyedValues.put("Event", event); for (ThreadMetric metric : timer.getMetricSuite().metrics()) { keyedValues.put(metric.getMetricName(), snapshotValues.get(metric)); LOG.trace(String.format("Thread %s in event %s, metric %s has value %s", entry .getKey(), event, metric, snapshotValues.get(metric)));
public void startTimer() { Preconditions.checkState(startValue == null, "Can't start running timer"); this.startValue = metricSource.getValueForThread(thread); this.lastStartOwnTimeValue = this.startValue; this.ownValueSoFar = 0L; }
public AbstractQuantity<?> ownTimeValue() { Preconditions.checkState(endValue != null, "Can't measure time until timer is stopped"); return NumberQuantity.of(ownValueSoFar, metricSource.getUnit()); }
public void testMetricName() { MetricMeasurement timing = new MetricMeasurement(StandardThreadMetrics.CLOCK_TIME, Thread .currentThread()); assertEquals(StandardThreadMetrics.CLOCK_TIME.getMetricName(), timing.getMetricName()); }
public void pauseOwnTime() { Preconditions.checkState(startValue != null, "Can't pause own time while timer is stopped"); Preconditions.checkState(lastStartOwnTimeValue != null, "Can't pause own time while already paused"); this.ownValueSoFar += (metricSource.getValueForThread(thread) - lastStartOwnTimeValue); this.lastStartOwnTimeValue = null; }
@SuppressWarnings({ "unchecked", "rawtypes" }) String buildSingleMetricResult(MetricMeasurement metric) { Unit canonicalUnit = normalizations.get(metric.getMetricSource().getUnit()); if (canonicalUnit == null) { canonicalUnit = metric.getMetricSource().getUnit(); } return metric.getMetricName() + ": own " + metric.ownTimeValue().to(canonicalUnit) + ", total " + metric.totalValue().to(canonicalUnit); }
public void testTotalMonitoredCounterSingletons() { metricFactory.registerTimeable(logonControl, "/Logon"); metricFactory.registerTimeable(workflowWizardControl, "/WorkflowWizard"); metricFactory.registerTimeable(attachmentControl, "/Attachments"); EventCounters wizardCounterSet = metricFactory.getCounterSetForEventGroup(workflowWizardControl); EventCounters logonCounterSet = metricFactory.getCounterSetForEventGroup(logonControl); EventCounters attachmentsCounterSet = metricFactory .getCounterSetForEventGroup(attachmentControl); assertNotNull("Couldnt obtain counter set for workflow wizard event", wizardCounterSet); assertNotNull("Couldnt obtain counter set for logon event", logonCounterSet); assertNotNull("Couldnt obtain counter set for attachments event", attachmentsCounterSet); for (ThreadMetric metric : wizardCounterSet.getMetrics().keySet()) { EventMetricCounters wizardCounter = wizardCounterSet.getMetrics().get(metric); assertNotNull("Couldnt obtain wizard counter for metric " + metric.getMetricName(), wizardCounter); EventMetricCounters logonCounter = logonCounterSet.getMetrics().get(metric); assertNotNull("Couldnt obtain logon counter for metric " + metric.getMetricName(), logonCounter); EventMetricCounters attachmentsCounter = attachmentsCounterSet.getMetrics() .get(metric); assertNotNull( "Couldnt obtain attachments counter for metric " + metric.getMetricName(), attachmentsCounter); assertEquals("Total counter for metric " + metric + " is not a singleton", wizardCounter.getTotalCounter(), logonCounter.getTotalCounter()); assertEquals("Total counter for metric " + metric + " is not a singleton", logonCounter .getTotalCounter(), attachmentsCounter.getTotalCounter()); } }
public void resumeOwnTime() { Preconditions.checkState(startValue != null, "Can't resume own time while timer is stopped"); Preconditions.checkState(lastStartOwnTimeValue == null, "Can't resume own time - already counting"); Preconditions.checkState(endValue == null, "Can't resume own time - stopped"); this.lastStartOwnTimeValue = metricSource.getValueForThread(thread); }
public void testUnitDisplay() { MetricMeasurement timing = new MetricMeasurement(StandardThreadMetrics.CLOCK_TIME, Thread .currentThread()); timing.startTimer(); timing.stopTimer(); assertTrue("Metric value should end with correct unit name", timing.ownTimeValue().toString() .endsWith(StandardThreadMetrics.CLOCK_TIME.getUnit().toString())); } }
public void stopTimer() { pauseOwnTime(); endValue = metricSource.getValueForThread(thread); }
@Test public void testExecutionCountForCurrentThread() throws SQLException { Statement s = dataSource.getConnection().createStatement(); ThreadMetric counter = dataSource.getCounterMetric(); assertEquals(0, counter.getValueForThread(Thread.currentThread())); s.execute("ROLLBACK"); assertEquals(1, counter.getValueForThread(Thread.currentThread())); }