public void testCannotAccessOwnTimeUntilStopped() { MetricMeasurement timing = new MetricMeasurement(StandardThreadMetrics.CLOCK_TIME, Thread .currentThread()); timing.startTimer(); try { timing.ownTimeValue(); fail(); } catch (IllegalStateException e) { // Expected } }
@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 testSanityOfNumbers() { // This test is unlikely to ever pick anything up but we may as well sanity check that the // numbers make sense (own time isn't > than total time) MetricMeasurement timing = new MetricMeasurement(StandardThreadMetrics.CLOCK_TIME, Thread .currentThread()); timing.startTimer(); timing.pauseOwnTime(); timing.resumeOwnTime(); timing.stopTimer(); assertTrue(timing.ownTimeValue().getValue().longValue() >= 0); assertTrue(timing.totalValue().getValue().longValue() >= 0); assertTrue(timing.ownTimeValue().getValue().longValue() <= timing.totalValue().getValue().longValue()); }
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())); } }