/** * Returns the current NanoTime or, if clock stats are disabled, zero. * @since 5.0 */ public static final long getStatTimeNoCheck() { return NanoTimer.getTime(); } ////////////////////// Instance Methods //////////////////////
public static final long nanoTimeThread() { return NanoTimer.nativeNanoTime(NativeCalls.CLOCKID_THREAD_CPUTIME_ID, true); }
public void testReset() { final long slop = calculateSlop(); NanoTimer nt = new NanoTimer(); long createTime = NanoTimer.getTime(); assertApproximate("create time", slop, 0, nt.getTimeSinceConstruction()); assertApproximate("construction vs. reset", slop, nt.getTimeSinceConstruction(), nt.getTimeSinceReset()); assertApproximate("time since reset time same as construct", slop, NanoTimer.getTime() - createTime, nt.getTimeSinceReset()); assertApproximate("reset time same as construct", slop, NanoTimer.getTime() - createTime, nt.reset()); long resetTime = NanoTimer.getTime(); assertApproximate("reset time updated", slop, NanoTimer.getTime() - resetTime, nt.getTimeSinceReset()); }
public static final void setNativeTimer(boolean nativeTimer, String timerType) { setNativeTimer(nativeTimer, getNativeTimerTypeFromString(timerType)); }
private long calculateSlop() { // calculate how much time this vm takes to do some basic stuff. long startTime = NanoTimer.getTime(); new NanoTimer(); assertApproximate("should never fail", 0, 0, 0); long result = NanoTimer.getTime() - startTime; return result * 3; // triple to be on the safe side }
public void testInitialTimes() { final long nanoTime = NanoTimer.getTime(); final NanoTimer timer = new NanoTimer(); assertEquals(timer.getConstructionTime(), timer.getLastResetTime()); assertTrue(timer.getTimeSinceConstruction() <= timer.getTimeSinceReset()); assertTrue(timer.getLastResetTime() >= nanoTime); assertTrue(timer.getConstructionTime() >= nanoTime); assertTrue(NanoTimer.getTime() >= nanoTime); final long nanosOne = NanoTimer.getTime(); waitMillis(10); assertTrue(timer.getTimeSinceConstruction() > NanoTimer.NANOS_PER_MILLISECOND * 10); assertTrue(timer.getTimeSinceConstruction() <= NanoTimer.getTime()); final long nanosTwo = NanoTimer.getTime(); assertTrue(timer.getTimeSinceConstruction() >= nanosTwo - nanosOne); }
NanoTimer timer = new NanoTimer(); this.sampleCollector.initialize(this, NanoTimer.getTime()); timer.reset(); long nanosLastTimeStamp = timer.getLastResetTime() - getNanoRate(); while (!stopRequested()) { SystemFailure.checkFailure(); break; final long nanosBeforeSleep = timer.getLastResetTime(); final long nanosToDelay = nanosLastTimeStamp + getNanoRate(); delay(timer, nanosToDelay); nanosLastTimeStamp = timer.getLastResetTime(); if (!stopRequested() && isSamplingEnabled()) { final long nanosTimeStamp = timer.getLastResetTime(); final long nanosElapsedSleeping = nanosTimeStamp - nanosBeforeSleep; checkElapsedSleepTime(nanosElapsedSleeping); final long nanosSpentWorking = timer.reset(); accountForTimeSpentWorking(nanosSpentWorking, nanosElapsedSleeping); } else if (!stopRequested() && !isSamplingEnabled()) {
timer.reset(); long now = timer.getLastResetTime(); long remainingNanos = nanosToDelay - now; if (remainingNanos <= 0) { remainingNanos = NanoTimer.millisToNanos(MIN_MS_SLEEP); long ms = NanoTimer.nanosToMillis(remainingNanos); if (ms <= 0) { Thread.yield(); timer.reset(); now = timer.getLastResetTime(); remainingNanos = nanosToDelay - now;
/** * A hydra TASK that populates the remote queue */ public static void populate() throws RemoteException, InterruptedException { RemoteBlockingQueue queue = getQueue(); NanoTimer timer = new NanoTimer(); for (int i = 0; i < 500; i++) { QueueElement element = new QueueElement(); if (RBQPrms.debug()) { Log.getLogWriter().info("Offering " + element); } timer.reset(); queue.offer(element, Integer.MAX_VALUE, TimeUnit.SECONDS); long duration = timer.reset(); if (RBQPrms.useBlackboard()) { RBQBlackboard.getBB().noteOffer(duration); } } }
sampleCollector.initialize(mockStatArchiveHandlerConfig, NanoTimer.getTime()); assertEquals(log, sampleCollector.getLogWriterI18n()); long timeStamp = NanoTimer.getTime(); sampleCollector.sample(timeStamp); st1_1.incLong("long_counter_3", 3); timeStamp += NanoTimer.millisToNanos(1000); sampleCollector.sample(timeStamp); timeStamp += NanoTimer.millisToNanos(1000); sampleCollector.sample(timeStamp); st1_2.incLong("long_counter_3", 2); timeStamp += NanoTimer.millisToNanos(1000); sampleCollector.sample(timeStamp); timeStamp += NanoTimer.millisToNanos(1000); sampleCollector.sample(timeStamp);
public void startOperation() { t.reset(); } public void endOperation() {
public static final long nanoTime() { return NanoTimer.nanoTime(); }
@Override public void processMessage(Object[] params, DistributedMember sender) { Boolean useNativeTimer = (Boolean)params[0]; String nativeTimerType = (String)params[1]; SanityManager.DEBUG_PRINT(GfxdConstants.TRACE_SYS_PROCEDURES, "GfxdSystemProcedureMessage:SET_NANOTIMER_TYPE native timer: " + useNativeTimer + " NativeTimerType: " + nativeTimerType ); NanoTimer.setNativeTimer(useNativeTimer, nativeTimerType); }
/** * Get whether the NanoTimer is internally making a native call to get the nanoTime. */ public static Boolean GET_IS_NATIVE_NANOTIMER() { return NanoTimer.getIsNativeTimer(); }
/** * Get the type of the native NanoTimer being used. */ public static String GET_NATIVE_NANOTIMER_TYPE() { return NanoTimer.getNativeTimerType(); }
/** * Gets the timer, lazily setting it and stashing it in a HydraThreadLocal. */ private NanoTimer getTimer() { NanoTimer t = (NanoTimer)localtimer.get(); if (t == null) { t = new NanoTimer(); localtimer.set(t); } return t; }
private long getNanoRate() { return NanoTimer.millisToNanos(getSampleRate()); }
public void testReset() { final NanoTimer timer = new NanoTimer(); final long nanosOne = NanoTimer.getTime(); assertEquals(timer.getConstructionTime(), timer.getLastResetTime()); assertTrue(timer.getTimeSinceConstruction() <= timer.getTimeSinceReset()); final long nanosTwo = NanoTimer.getTime(); final long resetOne = timer.reset(); assertFalse(timer.getConstructionTime() == timer.getLastResetTime()); final long nanosThree = NanoTimer.getTime(); assertTrue(timer.getLastResetTime() >= nanosTwo); assertTrue(timer.getTimeSinceReset() < timer.getTimeSinceConstruction()); assertTrue(timer.getLastResetTime() <= nanosThree); assertTrue(timer.getTimeSinceReset() < NanoTimer.getTime()); assertTrue(timer.getTimeSinceReset() <= NanoTimer.getTime() - timer.getLastResetTime()); final long nanosFour = NanoTimer.getTime(); final long resetTwo = timer.reset(); assertTrue(timer.getLastResetTime() >= nanosFour); assertTrue(timer.getTimeSinceReset() < timer.getTimeSinceConstruction()); assertTrue(timer.getLastResetTime() <= NanoTimer.getTime()); assertTrue(timer.getTimeSinceReset() <= NanoTimer.getTime() - timer.getLastResetTime());
NanoTimer timer = new NanoTimer(); this.sampleCollector.initialize(this, NanoTimer.getTime()); timer.reset(); long nanosLastTimeStamp = timer.getLastResetTime() - getNanoRate(); while (!stopRequested()) { SystemFailure.checkFailure(); break; final long nanosBeforeSleep = timer.getLastResetTime(); final long nanosToDelay = nanosLastTimeStamp + getNanoRate(); delay(timer, nanosToDelay); nanosLastTimeStamp = timer.getLastResetTime(); if (!stopRequested() && isSamplingEnabled()) { final long nanosTimeStamp = timer.getLastResetTime(); final long nanosElapsedSleeping = nanosTimeStamp - nanosBeforeSleep; checkElapsedSleepTime(nanosElapsedSleeping); final long nanosSpentWorking = timer.reset(); accountForTimeSpentWorking(nanosSpentWorking, nanosElapsedSleeping); } else if (!stopRequested() && !isSamplingEnabled()) {
timer.reset(); long now = timer.getLastResetTime(); long remainingNanos = nanosToDelay - now; if (remainingNanos <= 0) { remainingNanos = NanoTimer.millisToNanos(MIN_MS_SLEEP); long ms = NanoTimer.nanosToMillis(remainingNanos); if (ms <= 0) { Thread.yield(); timer.reset(); now = timer.getLastResetTime(); remainingNanos = nanosToDelay - now;