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; }
/** * Closes down anything initialied by initSpecialStats. */ private synchronized void closeSpecialStats() { if (this.vmStats != null) { this.vmStats.close(); } closeProcessStats(); }
private long getNanoRate() { return NanoTimer.millisToNanos(getSampleRate()); }
/** * Initialize any special sampler stats */ private synchronized void initSpecialStats() { // add a vm resource long id = getSpecialStatsId(); this.vmStats = VMStatsContractFactory.create(getStatisticsManager(), id); initProcessStats(id); }
getLogger().fine("HostStatSampler started"); boolean latchCountedDown = false; try { initSpecialStats(); long nanosLastTimeStamp = timer.getLastResetTime() - getNanoRate(); while (!stopRequested()) { SystemFailure.checkFailure(); if (Thread.currentThread().isInterrupted()) { 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); if (stopRequested()) break; prepareGFXDStats(false); if (stopRequested()) break; sampleSpecialStats(false); if (stopRequested()) break; checkListeners(); if (stopRequested()) break; accountForTimeSpentWorking(nanosSpentWorking, nanosElapsedSleeping); } else if (!stopRequested() && !isSamplingEnabled()) { prepareGFXDStats(true); if (stopRequested()) break;
if (statThread != null) { try { int msToWait = getSampleRate() + 100; statThread.join(msToWait); } catch (InterruptedException ex) { waitForInitialization(INITIALIZATION_TIMEOUT_MILLIS); } catch (InterruptedException e) { Thread.currentThread().interrupt();
/** * 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(); getLogger().warning(LocalizedStrings.HostStatSampler_STATISTICS_SAMPLING_THREAD_DETECTED_A_WAKEUP_DELAY_OF_0_MS_INDICATING_A_POSSIBLE_RESOURCE_ISSUE, NanoTimer.nanosToMillis(wakeupDelay)); } } }
/** * 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, LocalizedMessage.create(LocalizedStrings.HostStatSampler_STATISTICS_SAMPLING_THREAD_DETECTED_A_WAKEUP_DELAY_OF_0_MS_INDICATING_A_POSSIBLE_RESOURCE_ISSUE, NanoTimer.nanosToMillis(wakeupDelay))); } } } }
initSpecialStats(); long nanosLastTimeStamp = timer.getLastResetTime() - getNanoRate(); while (!stopRequested()) { SystemFailure.checkFailure(); if (Thread.currentThread().isInterrupted()) { 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); 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 { closeSpecialStats(); if (this.sampleCollector != null) { this.sampleCollector.close();
/** * Initialize any special sampler stats */ private synchronized void initSpecialStats() { // add a vm resource long id = getSpecialStatsId(); this.vmStats = new VMStats(getStatisticsManager(), id); initProcessStats(id); }
if (statThread != null) { try { int msToWait = getSampleRate() + 100; statThread.join(msToWait); } catch (InterruptedException ex) { waitForInitialization(INITIALIZATION_TIMEOUT_MILLIS); } catch (InterruptedException e) { Thread.currentThread().interrupt();
/** * Closes down anything initialied by initSpecialStats. */ private synchronized void closeSpecialStats() { if (this.vmStats != null) { this.vmStats.close(); } closeProcessStats(); }
private long getNanoRate() { return NanoTimer.millisToNanos(getSampleRate()); }