org.HdrHistogram.HistogramLogWriter Java Examples

The following examples show how to use org.HdrHistogram.HistogramLogWriter. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: HistogramReporter.java    From perf-workshop with Apache License 2.0 6 votes vote down vote up
private void encodedHistogram(final Histogram histogram, final String histogramTitle, final PrintStream out, final String testLabel)
{
    try
    {
        final File histogramOutputFile = getHistogramOutputFile(outputDir, histogramTitle, testLabel);
        out.println("Writing full encoded histogram to " + histogramOutputFile.getAbsolutePath() + "\n");
        try (final PrintStream printStream = new PrintStream(histogramOutputFile))
        {
            new HistogramLogWriter(printStream).outputIntervalHistogram(0, 1, histogram, 1d);
        }
    }
    catch (FileNotFoundException e)
    {
        throw new RuntimeException("Failed to write histogram", e);
    }
}
 
Example #2
Source File: PersistedHistogram.java    From benchmarks with Apache License 2.0 6 votes vote down vote up
static Path saveToFile(final Histogram histogram, final Path file)
    throws FileNotFoundException
{
    final HistogramLogWriter logWriter = new HistogramLogWriter(file.toFile());
    try
    {
        logWriter.outputIntervalHistogram(
            histogram.getStartTimeStamp() / 1000.0,
            histogram.getEndTimeStamp() / 1000.0,
            histogram,
            1.0);
    }
    finally
    {
        logWriter.close();
    }

    return file;
}
 
Example #3
Source File: TestPerformanceTracker.java    From hazelcast-simulator with Apache License 2.0 6 votes vote down vote up
void persist(long currentTimeMillis, String currentTimeString) {
    performanceLogWriter.write(
            currentTimeMillis,
            currentTimeString,
            totalOperationCount,
            intervalOperationCount,
            intervalThroughput);

    // dumps all the Histograms that have been collected to file.
    for (Map.Entry<String, Histogram> histogramEntry : intervalHistogramMap.entrySet()) {
        String probeName = histogramEntry.getKey();
        HistogramLogWriter histogramLogWriter = histogramLogWriterMap.get(probeName);
        if (histogramLogWriter == null) {
            histogramLogWriter = createHistogramLogWriter(probeName);
            histogramLogWriterMap.put(probeName, histogramLogWriter);
        }
        Histogram intervalHistogram = histogramEntry.getValue();
        histogramLogWriter.outputIntervalHistogram(intervalHistogram);
    }
}
 
Example #4
Source File: Accumulator.java    From perf-workshop with Apache License 2.0 5 votes vote down vote up
private void outputHistogram(final Histogram histogram, final int streamNumber, final String qualifier)
{
    try
    {
        try(final PrintStream printStream = new PrintStream(getHistogramOutputFile(commandLineArgs, streamNumber, qualifier)))
        {
            new HistogramLogWriter(printStream).outputIntervalHistogram(streamNumber, streamNumber + 1, histogram, 1d);
        }
    }
    catch (FileNotFoundException e)
    {
        throw new RuntimeException("Failed to write histogram", e);
    }
}
 
Example #5
Source File: ResultsAggregatorTest.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
private void saveToDisc(final String fileName, final Histogram histogram) throws FileNotFoundException
{
    final HistogramLogWriter logWriter = new HistogramLogWriter(tempDir.resolve(fileName).toFile());
    try
    {
        logWriter.outputIntervalHistogram(
            histogram.getStartTimeStamp() / 1000.0, histogram.getEndTimeStamp() / 1000.0, histogram, 1);
    }
    finally
    {
        logWriter.close();
    }
}
 
Example #6
Source File: PeriodicHlogReporter.java    From Rainfall-core with Apache License 2.0 5 votes vote down vote up
@Override
public void report(final StatisticsPeekHolder<E> statisticsHolder) {
  long now = System.currentTimeMillis();

  Enum<E>[] results = statisticsHolder.getResultsReported();
  for (Enum<E> result : results) {
    Histogram histogram = statisticsHolder.fetchHistogram(result);
    Histogram copy = histogram.copy();
    histogram.setEndTimeStamp(now);

    Holder previous = this.previous.get(result);
    if (previous == null) {
      try {
        histogram.setStartTimeStamp(startTs);
        previous = new Holder();
        previous.previousTs = startTs;
        File hlogFile = new File(this.basedir + File.separatorChar + buildHlogFilename(result.name()));
        hlogFile.getParentFile().mkdirs();
        previous.writer = new HistogramLogWriter(new PrintStream(hlogFile));
        previous.writer.setBaseTime(startTs);
        previous.writer.outputLogFormatVersion();
        previous.writer.outputBaseTime(previous.writer.getBaseTime());
        previous.writer.outputLegend();
        this.previous.put(result, previous);
      } catch (FileNotFoundException e) {
        throw new RuntimeException(e);
      }
    } else {
      histogram.setStartTimeStamp(previous.previousTs);
      histogram.subtract(previous.histogram);
    }

    previous.histogram = copy;
    previous.writer.outputIntervalHistogram(histogram);
    previous.previousTs = now;
  }
}
 
Example #7
Source File: HlogReporter.java    From Rainfall-core with Apache License 2.0 5 votes vote down vote up
@Override
public void summarize(final StatisticsHolder<E> statisticsHolder) {
  // dump raw histograms as hlog files
  long startTime = ManagementFactory.getRuntimeMXBean().getStartTime();
  long endTime = System.currentTimeMillis();
  try {
    Enum<E>[] results = statisticsHolder.getResultsReported();
    for (Enum<E> result : results) {
      Histogram rawHistogram = statisticsHolder.fetchHistogram(result);
      rawHistogram.setStartTimeStamp(startTime);
      rawHistogram.setEndTimeStamp(endTime);

      File hlogFile = new File(this.basedir + File.separatorChar + buildHlogFilename(result.name()));
      hlogFile.getParentFile().mkdirs();
      HistogramLogWriter writer = new HistogramLogWriter(new PrintStream(hlogFile));
      writer.setBaseTime(startTime);

      writer.outputLogFormatVersion();
      writer.outputBaseTime(writer.getBaseTime());
      writer.outputLegend();
      writer.outputIntervalHistogram(rawHistogram);

      writer.close();
    }
  } catch (Exception e) {
    throw new RuntimeException("Can not report to hlog", e);
  }
}
 
Example #8
Source File: KafkaExtractorStatsTracker.java    From incubator-gobblin with Apache License 2.0 5 votes vote down vote up
/**
 * A helper method to serialize a {@link Histogram} to its string representation. This method uses the
 * compressed logging format provided by the {@link org.HdrHistogram.HistogramLogWriter}
 * to represent the Histogram as a string. The readers can use the {@link org.HdrHistogram.HistogramLogReader} to
 * deserialize the string back to a {@link Histogram} object.
 * @param observedLatencyHistogram
 * @return
 */
@VisibleForTesting
public static String convertHistogramToString(Histogram observedLatencyHistogram) {
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
  try (PrintStream stream = new PrintStream(baos, true, Charsets.UTF_8.name())) {
    HistogramLogWriter histogramLogWriter = new HistogramLogWriter(stream);
    histogramLogWriter.outputIntervalHistogram(observedLatencyHistogram);
    return new String(baos.toByteArray(), Charsets.UTF_8);
  } catch (UnsupportedEncodingException e) {
    log.error("Exception {} encountered when creating PrintStream; returning empty string", e);
    return EMPTY_STRING;
  }
}
 
Example #9
Source File: HistogramTrimmer.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
public static void main(String[] args) throws FileNotFoundException {
    File inputFile = new File(args[0]);
    File outputFile = new File(inputFile.getParent(), inputFile.getName() + ".tmp");
    long startMillis = Long.parseLong(args[1]);
    long endMillis = Long.parseLong(args[2]);

    HistogramLogReader reader = new HistogramLogReader(inputFile);
    HistogramLogWriter writer = new HistogramLogWriter(outputFile);
    for (; ; ) {
        Histogram histogram = (Histogram) reader.nextIntervalHistogram();
        if (histogram == null) {
            break;
        }

        if (histogram.getStartTimeStamp() >= startMillis && histogram.getEndTimeStamp() <= endMillis) {
            Histogram out = new Histogram(
                    histogram.getLowestDiscernibleValue(),
                    histogram.getHighestTrackableValue(),
                    histogram.getNumberOfSignificantValueDigits());
            out.setStartTimeStamp(histogram.getStartTimeStamp());
            out.setEndTimeStamp(histogram.getEndTimeStamp());
            out.add(histogram);
            writer.outputIntervalHistogram(out);
        }
    }

    outputFile.renameTo(new File(args[0]));
}
 
Example #10
Source File: TestPerformanceTracker.java    From hazelcast-simulator with Apache License 2.0 5 votes vote down vote up
HistogramLogWriter createHistogramLogWriter(String probeName) {
    String testId = testContainer.getTestCase().getId();
    try {
        File latencyFile = getLatencyFile(testId, probeName);
        HistogramLogWriter histogramLogWriter = new HistogramLogWriter(latencyFile);
        histogramLogWriter.setBaseTime(testContainer.getRunStartedMillis());
        histogramLogWriter.outputStartTime(testContainer.getRunStartedMillis());
        histogramLogWriter.outputComment("[Latency histograms for " + testId + '.' + probeName + ']');
        histogramLogWriter.outputLogFormatVersion();
        histogramLogWriter.outputLegend();
        return histogramLogWriter;
    } catch (IOException e) {
        throw new TestException("Could not initialize HistogramLogWriter for test " + testId, e);
    }
}
 
Example #11
Source File: LatencyWriter.java    From maestro-java with Apache License 2.0 2 votes vote down vote up
/**
 * Constructor
 *
 * @param path file path
 * @throws IOException on I/O errors
 */
public LatencyWriter(final File path) throws IOException {
    out = new FileOutputStream(path);
    logWriter = new HistogramLogWriter(this.out);
}