public SimpleStatSampler(CancelCriterion stopper, StatisticsManager sm, NanoTimer timer) { super(stopper, new StatSamplerStats(sm, 0), timer); this.sm = sm; logger.info(LogMarker.STATISTICS_MARKER, "stats.sample-rate={}", getSampleRate()); }
@Override public boolean waitForSample(long timeout) throws InterruptedException { final long endTime = System.currentTimeMillis() + timeout; final int startSampleCount = this.samplerStats.getSampleCount(); while (System.currentTimeMillis() < endTime && this.samplerStats.getSampleCount() <= startSampleCount) { Thread.sleep(WAIT_FOR_SLEEP_INTERVAL); } return this.samplerStats.getSampleCount() > startSampleCount; }
private void sampleCallbacks() { if (cancelCriterion.isCancelInProgress()) { executor.shutdown(); } int errors = 0; int suppliers = 0; long start = System.nanoTime(); try { for (Statistics stats : statisticsManager.getStatsList()) { StatisticsImpl statistics = (StatisticsImpl) stats; errors += statistics.invokeSuppliers(); suppliers += statistics.getSupplierCount(); } } catch (VirtualMachineError e) { SystemFailure.initiateFailure(e); } catch (Throwable throwable) { logger.error("Error invoking statistic suppliers", throwable); } finally { long end = System.nanoTime(); statSamplerStats.incSampleCallbackDuration(TimeUnit.NANOSECONDS.toMillis(end - start)); statSamplerStats.incSampleCallbackErrors(errors); statSamplerStats.setSampleCallbacks(suppliers); } }
/** * Called when this sampler has spent some time working and wants it to be accounted for. */ private void accountForTimeSpentWorking(long nanosSpentWorking, long nanosSpentSleeping) { this.samplerStats.tookSample(nanosSpentWorking, getStatisticsManager().getStatisticsCount(), nanosSpentSleeping); }
/** * 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)); } } } }
public void addSystemStats() { GemFireStatSampler sampler = system.getStatSampler(); ProcessStats processStats = sampler.getProcessStats(); StatSamplerStats samplerStats = sampler.getStatSamplerStats(); if (processStats != null) { systemStatsMonitor.addStatisticsToMonitor(processStats.getStatistics()); } if (samplerStats != null) { systemStatsMonitor.addStatisticsToMonitor(samplerStats.getStats()); } }
@Test public void taskShouldSampleStatistics() { Runnable sampleTask = invokeStartAndGetTask(); StatisticsImpl stats1 = mock(StatisticsImpl.class); StatisticsImpl stats2 = mock(StatisticsImpl.class); when(stats1.invokeSuppliers()).thenReturn(3); when(stats2.invokeSuppliers()).thenReturn(2); when(stats1.getSupplierCount()).thenReturn(7); when(stats2.getSupplierCount()).thenReturn(8); when(statisticsManager.getStatsList()).thenReturn(Arrays.asList(stats1, stats2)); sampleTask.run(); verify(statSamplerStats).setSampleCallbacks(eq(15)); verify(statSamplerStats).incSampleCallbackErrors(5); verify(statSamplerStats).incSampleCallbackDuration(anyLong()); }
public GemFireStatSampler(InternalDistributedSystem con) { super(con.getCancelCriterion(), new StatSamplerStats(con, con.getId())); this.con = con; }
public GemFireStatSampler(InternalDistributedSystem con, LogFile logFile) { super(con.getCancelCriterion(), new StatSamplerStats(con, con.getId()), logFile); this.con = con; }