@Test public final void testOrdering() throws Exception { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q0 = g_t.timerQueryAllocate(); g_t.timerQueryBegin(q0); // Do some work to waste time g_t.timerQueryAllocate(); g_t.timerQueryAllocate(); g_t.timerQueryAllocate(); g_t.timerQueryAllocate(); g_t.timerQueryAllocate(); g_t.timerQueryFinish(q0); while (g_t.timerQueryResultAvailability(q0) == JCGLQueryResultAvailability.QUERY_RESULT_NOT_YET_AVAILABLE) { System.out.println("Waiting for q0: " + q0); Thread.sleep(1000L); } final long q0_r = g_t.timerQueryResultGet(q0); System.out.println("q0_r: " + q0_r); Assert.assertTrue(q0_r > 0); }
@Test public final void testFinishNotRunningOther() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q0 = g_t.timerQueryAllocate(); final JCGLTimerQueryType q1 = g_t.timerQueryAllocate(); g_t.timerQueryBegin(q0); this.expected.expect(JCGLExceptionQueryNotRunning.class); g_t.timerQueryFinish(q1); } }
@Test public final void testBeginRunningOther() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q0 = g_t.timerQueryAllocate(); final JCGLTimerQueryType q1 = g_t.timerQueryAllocate(); g_t.timerQueryBegin(q0); this.expected.expect(JCGLExceptionQueryAlreadyRunning.class); g_t.timerQueryBegin(q1); }
@Test public final void testDeleteDeleted() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q = g_t.timerQueryAllocate(); Assert.assertFalse(q.isDeleted()); g_t.timerQueryDelete(q); Assert.assertTrue(q.isDeleted()); this.expected.expect(JCGLExceptionDeleted.class); g_t.timerQueryDelete(q); }
@Test public final void testFinishNotRunning() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q = g_t.timerQueryAllocate(); this.expected.expect(JCGLExceptionQueryNotRunning.class); g_t.timerQueryFinish(q); }
@Test public final void testNotAvailable() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q = g_t.timerQueryAllocate(); Assert.assertEquals( JCGLQueryResultAvailability.QUERY_RESULT_NOT_YET_REQUESTED, g_t.timerQueryResultAvailability(q)); }
@Override public JCGLTimerQueryUsableType getTimer() { if (this.timer.isPresent()) { return this.timer.get(); } final JCGLTimerQueryType t = JCGLProfiling.this.timers.timerQueryAllocate(); this.timer = Optional.of(t); return t; }
/** * Stop measuring the time if profiling is enabled. */ default void stopMeasuringIfEnabled() { // Checkstyle doesn't seem to understand "final" in interfaces // CHECKSTYLE:OFF if (this.isEnabled()) { final JCGLTimerQueryUsableType timer = this.getTimer(); this.getTimers().timerQueryFinish(timer); } // CHECKSTYLE:ON } }
/** * Start measuring the time if profiling is enabled. */ default void startMeasuringIfEnabled() { // Checkstyle doesn't seem to understand "final" in interfaces // CHECKSTYLE:OFF if (this.isEnabled()) { final JCGLTimerQueryUsableType timer = this.getTimer(); this.getTimers().timerQueryBegin(timer); } // CHECKSTYLE:ON }
long retrieveRecursive() { this.elapsed = 0L; this.elapsed_total = 0L; if (this.hasTimer()) { final long r = JCGLProfiling.this.timers.timerQueryResultGet(this.timer.get()); this.elapsed = r; this.elapsed_total = this.elapsed; } final ReferenceCollection<Context> os = this.children.values(); final ObjectIterator<Context> o_iter = os.iterator(); while (o_iter.hasNext()) { final Context c = o_iter.next(); this.elapsed_total += c.retrieveRecursive(); } return this.elapsed_total; } }
void trim() { if (this.timer.isPresent()) { final JCGLTimerQueryType t = this.timer.get(); JCGLProfiling.this.timers.timerQueryDelete(t); this.timer = Optional.empty(); } final ObjectBidirectionalIterator<String> k_iter = this.children.keySet().iterator(); while (k_iter.hasNext()) { final String k = k_iter.next(); final Context c = this.children.get(k); c.trim(); k_iter.remove(); } Postconditions.checkPostcondition( this.children, this.children.isEmpty(), ignored -> "Child nodes have been correctly cleared"); Postconditions.checkPostcondition( this.timer, !this.timer.isPresent(), ignored -> "Timer must have been deleted"); }
@Test public final void testFinishNotRunningOther() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q0 = g_t.timerQueryAllocate(); final JCGLTimerQueryType q1 = g_t.timerQueryAllocate(); g_t.timerQueryBegin(q0); this.expected.expect(JCGLExceptionQueryNotRunning.class); g_t.timerQueryFinish(q1); } }
@Test public final void testDeleteDeleted() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q = g_t.timerQueryAllocate(); Assert.assertFalse(q.isDeleted()); g_t.timerQueryDelete(q); Assert.assertTrue(q.isDeleted()); this.expected.expect(JCGLExceptionDeleted.class); g_t.timerQueryDelete(q); }
@Test public final void testBeginRunningOther() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q0 = g_t.timerQueryAllocate(); final JCGLTimerQueryType q1 = g_t.timerQueryAllocate(); g_t.timerQueryBegin(q0); this.expected.expect(JCGLExceptionQueryAlreadyRunning.class); g_t.timerQueryBegin(q1); }
@Test public final void testFinishNotRunning() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q = g_t.timerQueryAllocate(); this.expected.expect(JCGLExceptionQueryNotRunning.class); g_t.timerQueryFinish(q); }
@Test public final void testNotAvailable() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q = g_t.timerQueryAllocate(); Assert.assertEquals( JCGLQueryResultAvailability.QUERY_RESULT_NOT_YET_REQUESTED, g_t.timerQueryResultAvailability(q)); }
@Test public final void testOrdering() throws Exception { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q0 = g_t.timerQueryAllocate(); g_t.timerQueryBegin(q0); // Do some work to waste time g_t.timerQueryAllocate(); g_t.timerQueryAllocate(); g_t.timerQueryAllocate(); g_t.timerQueryAllocate(); g_t.timerQueryAllocate(); g_t.timerQueryFinish(q0); while (g_t.timerQueryResultAvailability(q0) == JCGLQueryResultAvailability.QUERY_RESULT_NOT_YET_AVAILABLE) { System.out.println("Waiting for q0: " + q0); Thread.sleep(1000L); } final long q0_r = g_t.timerQueryResultGet(q0); System.out.println("q0_r: " + q0_r); Assert.assertTrue(q0_r > 0); }
@Test public final void testIdentities() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q = g_t.timerQueryAllocate(); Assert.assertFalse(q.isDeleted()); g_t.timerQueryDelete(q); Assert.assertTrue(q.isDeleted()); }
@Test public final void testBeginRunning() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q = g_t.timerQueryAllocate(); g_t.timerQueryBegin(q); this.expected.expect(JCGLExceptionQueryAlreadyRunning.class); g_t.timerQueryBegin(q); }
@Test public final void testIdentities() { final JCGLTimersType g_t = this.getTimers("main"); final JCGLTimerQueryType q = g_t.timerQueryAllocate(); Assert.assertFalse(q.isDeleted()); g_t.timerQueryDelete(q); Assert.assertTrue(q.isDeleted()); }