HistoIntervalLogger extends  CapabilityHook<HdrDeltaHistogramAttachment> implements Runnable, MetricsCloseable { @Override public void closeMetrics() { executor.close(); long potentialWriteTime = System.currentTimeMillis(); if (lastRunTime +1000 < potentialWriteTime) { logger.debug("Writing last partial histo log:" + this); run(); } else { logger.debug("Not writing last partial histo log <1s:" + this); } logStream.close(); } HistoIntervalLogger(String sessionName, File file, Pattern pattern, long intervalLength); File getLogfile(); boolean matches(String metricName); void startLogging(); String toString(); long getInterval(); @Override synchronized void onCapableAdded(String name, HdrDeltaHistogramAttachment chainedHistogram); @Override synchronized void onCapableRemoved(String name, HdrDeltaHistogramAttachment capable); @Override void run(); @Override void closeMetrics(); @Override void chart();  }
@Test public void testBasicLogger() throws IOException { File tempFile = File.createTempFile("testhistointlog", "hdr", new File("/tmp")); tempFile.deleteOnExit(); HistoIntervalLogger hil = new HistoIntervalLogger("loggertest", tempFile, Pattern.compile(".*"), 1000); final int significantDigits = 4; NicerHistogram nicerHistogram = new NicerHistogram( "histo1", new DeltaHdrHistogramReservoir("histo1", significantDigits)); hil.onHistogramAdded("histo1",nicerHistogram); List<Long> moments = new ArrayList<>(100); moments.add(System.currentTimeMillis()); nicerHistogram.update(1L); moments.add(System.currentTimeMillis()); delay(1001); moments.add(System.currentTimeMillis()); nicerHistogram.update(1000000L); moments.add(System.currentTimeMillis()); delay(1001); moments.add(System.currentTimeMillis()); nicerHistogram.update(1000L); moments.add(System.currentTimeMillis()); hil.onHistogramRemoved("histo1"); moments.add(System.currentTimeMillis()); hil.closeMetrics(); HistogramLogReader hlr = new HistogramLogReader(tempFile.getAbsolutePath()); List<EncodableHistogram> histos = new ArrayList<>(); EncodableHistogram histogram; while (true) { histogram = hlr.nextIntervalHistogram(); if (histogram==null) { break; } histos.add(histogram); }; assertThat(histos.size()).isEqualTo(2); assertThat(histos.get(0)).isInstanceOf(Histogram.class); assertThat(((Histogram)histos.get(0)).getNumberOfSignificantValueDigits()).isEqualTo(significantDigits); }