Java Code Examples for org.HdrHistogram.Histogram#setEndTimeStamp()

The following examples show how to use org.HdrHistogram.Histogram#setEndTimeStamp() . 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: WorkerLatencyWriter.java    From maestro-java with Apache License 2.0 6 votes vote down vote up
/**
 * @param snapshotLatencies {@code true} if is needed to force the snapshot of the interval latencies at the end of a test
 */
void updateReport(final boolean snapshotLatencies) {
    final long reportTime = System.currentTimeMillis();
    if (snapshotLatencies || this.reportIntervalLatencies) {
        final Histogram intervalHistogram = this.worker.takeLatenciesSnapshot(this.intervalHistogram);
        //there are workers that doesn't support taking latencies histograms
        if (intervalHistogram != null) {
            //the first time the startTimeStamp is the first one: useful when aren't performed
            //snapshots of interval latencies
            if (this.intervalHistogram == null) {
                intervalHistogram.setStartTimeStamp(this.startReportingTime);
            } else {
                //if it is the first snapshot taken then it is from the beginning of the worker lifecycle
                intervalHistogram.setStartTimeStamp(this.lastReportTime);
            }
            intervalHistogram.setEndTimeStamp(reportTime);
            this.intervalHistogram = intervalHistogram;
        }
    }
    this.lastReportTime = reportTime;
}
 
Example 2
Source File: PersistedHistogramTest.java    From benchmarks with Apache License 2.0 6 votes vote down vote up
@Test
void saveToFileCreatesNewFileWithIndexZero(final @TempDir Path tempDir) throws IOException
{
    Files.createFile(tempDir.resolve("another-one-13.hdr"));

    final Histogram histogram = new Histogram(3);
    histogram.setStartTimeStamp(123456789);
    histogram.setEndTimeStamp(987654321);
    histogram.recordValue(100);
    histogram.recordValue(1000);
    histogram.recordValue(250);

    final PersistedHistogram persistedHistogram = new PersistedHistogram(histogram.copy());

    final Path file = persistedHistogram.saveToFile(tempDir, "test-histogram");

    assertNotNull(file);
    assertTrue(Files.exists(file));
    assertEquals("test-histogram-0.hdr", file.getFileName().toString());
    final Histogram savedHistogram = readHistogram(file);
    assertEquals(histogram, savedHistogram);
    assertEquals(histogram.getStartTimeStamp(), savedHistogram.getStartTimeStamp());
    assertEquals(histogram.getEndTimeStamp(), savedHistogram.getEndTimeStamp());
}
 
Example 3
Source File: ResultsAggregatorTest.java    From benchmarks with Apache License 2.0 5 votes vote down vote up
private Histogram createHistogram(final long startTimeMs, final long endTimeMs, final long... values)
{
    final Histogram histogram = new Histogram(3);
    histogram.setStartTimeStamp(startTimeMs);
    histogram.setEndTimeStamp(endTimeMs);

    for (final long value : values)
    {
        histogram.recordValue(value);
    }

    return histogram;
}
 
Example 4
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 5
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 6
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 7
Source File: ResponseTimeTest.java    From logging-log4j2 with Apache License 2.0 5 votes vote down vote up
private static Histogram createResultHistogram(final List<Histogram> list, final long start, final long end) {
    final Histogram result = new Histogram(TimeUnit.SECONDS.toNanos(10), 3);
    result.setStartTimeStamp(start);
    result.setEndTimeStamp(end);
    for (final Histogram hist : list) {
        result.add(hist);
    }
    return result;
}
 
Example 8
Source File: TestPerformanceTracker.java    From hazelcast-simulator with Apache License 2.0 4 votes vote down vote up
private void makeUpdate(long updateIntervalMillis, long currentTimeMillis) {
    Map<String, Probe> probeMap = testContainer.getProbeMap();
    Map<String, Histogram> intervalHistograms = new HashMap<>(probeMap.size());

    long intervalPercentileLatency = -1;
    double intervalMean = -1;
    long intervalMaxLatency = -1;

    long iterations = testContainer.iteration() - iterationsDuringWarmup;
    long intervalOperationCount = iterations - lastIterations;

    for (Map.Entry<String, Probe> entry : probeMap.entrySet()) {
        String probeName = entry.getKey();
        Probe probe = entry.getValue();
        if (!(probe instanceof HdrProbe)) {
            continue;
        }

        HdrProbe hdrProbe = (HdrProbe) probe;
        Histogram intervalHistogram = hdrProbe.getRecorder().getIntervalHistogram();
        intervalHistogram.setStartTimeStamp(lastUpdateMillis);
        intervalHistogram.setEndTimeStamp(currentTimeMillis);
        intervalHistograms.put(probeName, intervalHistogram);

        long percentileValue = intervalHistogram.getValueAtPercentile(INTERVAL_LATENCY_PERCENTILE);
        if (percentileValue > intervalPercentileLatency) {
            intervalPercentileLatency = percentileValue;
        }

        double meanLatency = intervalHistogram.getMean();
        if (meanLatency > intervalMean) {
            intervalMean = meanLatency;
        }

        long maxValue = intervalHistogram.getMaxValue();
        if (maxValue > intervalMaxLatency) {
            intervalMaxLatency = maxValue;
        }

        if (probe.isPartOfTotalThroughput()) {
            intervalOperationCount += intervalHistogram.getTotalCount();
        }
    }

    this.intervalHistogramMap = intervalHistograms;

    this.intervalLatency999PercentileNanos = intervalPercentileLatency;
    this.intervalLatencyAvgNanos = intervalMean;
    this.intervalLatencyMaxNanos = intervalMaxLatency;

    this.intervalOperationCount = intervalOperationCount;
    this.totalOperationCount += intervalOperationCount;

    long intervalTimeDelta = currentTimeMillis - lastUpdateMillis;
    long totalTimeDelta = currentTimeMillis - testContainer.getRunStartedMillis();

    this.intervalThroughput = (intervalOperationCount * ONE_SECOND_IN_MILLIS) / (double) intervalTimeDelta;
    this.totalThroughput = (totalOperationCount * ONE_SECOND_IN_MILLIS / (double) totalTimeDelta);

    this.lastIterations = iterations;
    this.nextUpdateMillis += updateIntervalMillis;
    this.lastUpdateMillis = currentTimeMillis;
}