From ff562cee1ee21bda43aa196a11fcf6400c0a9d62 Mon Sep 17 00:00:00 2001
From: nitsanw <nitsanw@yahoo.com>
Date: Wed, 5 Aug 2015 16:57:33 +0200
Subject: [PATCH] [core] Fix recorder/logger initialization timing issue.

The HdrHistogramReader makes some problematic assumptions on the roles
played by start time, base time and histogram start/end times. This is
to be revisited in a future release of HdrHistogram (see
https://github.com/HdrHistogram/HdrHistogram/issues/69). In the meantime
this change will make YCSB record as expected by the reader:
a. Set histogram log base time (same as start time)
b. Only create the recorder after the log has been setup
---
 .../OneMeasurementHdrHistogram.java           | 30 ++++++++++---------
 1 file changed, 16 insertions(+), 14 deletions(-)

diff --git a/core/src/main/java/com/yahoo/ycsb/measurements/OneMeasurementHdrHistogram.java b/core/src/main/java/com/yahoo/ycsb/measurements/OneMeasurementHdrHistogram.java
index 07316324..4754825f 100644
--- a/core/src/main/java/com/yahoo/ycsb/measurements/OneMeasurementHdrHistogram.java
+++ b/core/src/main/java/com/yahoo/ycsb/measurements/OneMeasurementHdrHistogram.java
@@ -46,8 +46,7 @@ public class OneMeasurementHdrHistogram extends OneMeasurement {
   final PrintStream log;
   final HistogramLogWriter histogramLogWriter;
 
-  final Recorder histogram = new Recorder(3);
-
+  final Recorder histogram;
   Histogram totalHistogram;
 
   public OneMeasurementHdrHistogram(String name, Properties props) {
@@ -56,19 +55,22 @@ public class OneMeasurementHdrHistogram extends OneMeasurement {
     if (!shouldLog) {
       log = null;
       histogramLogWriter = null;
-      return;
-    }
-    try {
-      final String hdrOutputFilename = props.getProperty("hdrhistogram.output.path", "") +name+".hdr";
-      log = new PrintStream(new FileOutputStream(hdrOutputFilename), false);
-    } catch (FileNotFoundException e) {
-      throw new RuntimeException("Failed to open hdr histogram output file", e);
+    } else {
+      try {
+        final String hdrOutputFilename = props.getProperty("hdrhistogram.output.path", "") + name + ".hdr";
+        log = new PrintStream(new FileOutputStream(hdrOutputFilename), false);
+      } catch (FileNotFoundException e) {
+        throw new RuntimeException("Failed to open hdr histogram output file", e);
+      }
+      histogramLogWriter = new HistogramLogWriter(log);
+      histogramLogWriter.outputComment("[Logging for: " + name + "]");
+      histogramLogWriter.outputLogFormatVersion();
+      long now = System.currentTimeMillis();
+      histogramLogWriter.outputStartTime(now);
+      histogramLogWriter.setBaseTime(now);
+      histogramLogWriter.outputLegend();
     }
-    histogramLogWriter = new HistogramLogWriter(log);
-    histogramLogWriter.outputComment("[Logging for: " + name + "]");
-    histogramLogWriter.outputLogFormatVersion();
-    histogramLogWriter.outputStartTime(System.currentTimeMillis());
-    histogramLogWriter.outputLegend();
+    histogram = new Recorder(3);
   }
 
   /**
-- 
GitLab