/** * Waits for the special statistics to be initialized. This overridden version of * {@link #waitForInitialization()} should always be used within tests. * * @see #initSpecialStats * @since GemFire 7.0 */ public boolean waitForInitialization(long ms) throws InterruptedException { return awaitInitialization(ms, TimeUnit.MILLISECONDS); }
/** * Closes down anything initialied by initSpecialStats. */ private synchronized void closeSpecialStats() { if (this.vmStats != null) { this.vmStats.close(); } closeProcessStats(); }
initSpecialStats(); long nanosLastTimeStamp = timer.getLastResetTime() - getNanoRate(); while (!stopRequested()) { SystemFailure.checkFailure(); if (Thread.currentThread().isInterrupted()) { final long nanosToDelay = nanosLastTimeStamp + getNanoRate(); delay(nanosToDelay); nanosLastTimeStamp = timer.getLastResetTime(); if (!stopRequested() && isSamplingEnabled()) { final long nanosTimeStamp = timer.getLastResetTime(); final long nanosElapsedSleeping = nanosTimeStamp - nanosBeforeSleep; checkElapsedSleepTime(nanosElapsedSleeping); if (stopRequested()) break; sampleSpecialStats(false); if (stopRequested()) break; checkListeners(); if (stopRequested()) break; accountForTimeSpentWorking(nanosSpentWorking, nanosElapsedSleeping); } else if (!stopRequested() && !isSamplingEnabled()) { sampleSpecialStats(true); // fixes bug 42527 } finally { try {
if (statThread != null) { try { int msToWait = getSampleRate() + 100; statThread.join(msToWait); } catch (InterruptedException ex) { this.callbackSampler.start(getStatisticsManager(), getSampleRate(), TimeUnit.MILLISECONDS); statThread = new LoggingThread("StatSampler", this); statThread.setPriority(Thread.MAX_PRIORITY); waitForInitialization(INITIALIZATION_TIMEOUT_MILLIS); } catch (InterruptedException e) { Thread.currentThread().interrupt();
private Map<StatisticsType, Set<Statistics>> initAllStatistics() throws InterruptedException { assertTrue(this.statSampler.waitForInitialization(5000)); Map<StatisticsType, Set<Statistics>> statsTypeToStats = new HashMap<StatisticsType, Set<Statistics>>(); Statistics[] stats = this.statSampler.getStatistics(); for (int i = 0; i < stats.length; i++) { StatisticsType statsType = stats[i].getType(); Set<Statistics> statsSet = statsTypeToStats.get(statsType); if (statsSet == null) { statsSet = new HashSet<Statistics>(); statsSet.add(stats[i]); statsTypeToStats.put(statsType, statsSet); } else { statsSet.add(stats[i]); } } return statsTypeToStats; }
private long getNanoRate() { return NanoTimer.millisToNanos(getSampleRate()); }
/** * Check the elapsed sleep time upon wakeup, and log a warning if it is longer than the delay * threshold. * * @param elapsedSleepTime duration of sleep in nanoseconds */ private void checkElapsedSleepTime(long elapsedSleepTime) { if (STAT_SAMPLER_DELAY_THRESHOLD > 0) { final long wakeupDelay = elapsedSleepTime - getNanoRate(); if (wakeupDelay > STAT_SAMPLER_DELAY_THRESHOLD_NANOS) { this.samplerStats.incJvmPauses(); logger.warn(LogMarker.STATISTICS_MARKER, "Statistics sampling thread detected a wakeup delay of {} ms, indicating a possible resource issue. Check the GC, memory, and CPU statistics.", NanoTimer.nanosToMillis(wakeupDelay)); } } } }