@Override public EncodableHistogram read() throws DataFormatException { // prevent double calls to this method if (gotIt) { throw new IllegalStateException(); } gotIt = true; final String compressedPayloadString = scanner.next(); final ByteBuffer buffer = ByteBuffer.wrap(Base64Helper.parseBase64Binary(compressedPayloadString)); EncodableHistogram histogram = EncodableHistogram.decodeFromCompressedByteBuffer(buffer, 0); return histogram; } }
final EncodableHistogram histogram, final double maxValueUnitRatio) { if ((targetBuffer == null) || targetBuffer.capacity() < histogram.getNeededByteBufferCapacity()) { targetBuffer = ByteBuffer.allocate(histogram.getNeededByteBufferCapacity()).order(BIG_ENDIAN); int compressedLength = histogram.encodeIntoCompressedByteBuffer(targetBuffer, Deflater.BEST_COMPRESSION); byte[] compressedArray = Arrays.copyOf(targetBuffer.array(), compressedLength); String tag = histogram.getTag(); if (tag == null) { log.format(Locale.US, "%.3f,%.3f,%.3f,%s\n", startTimeStampSec, endTimeStampSec - startTimeStampSec, histogram.getMaxValueAsDouble() / maxValueUnitRatio, Base64Helper.printBase64Binary(compressedArray) ); startTimeStampSec, endTimeStampSec - startTimeStampSec, histogram.getMaxValueAsDouble() / maxValueUnitRatio, Base64Helper.printBase64Binary(compressedArray) );
/** * Output an interval histogram, using the start/end timestamp indicated in the histogram, * and the [optional] tag associated with the histogram. * The histogram start and end timestamps are assumed to be in msec units. Logging will be * in seconds, realtive by a base time (if set via {@link org.HdrHistogram.HistogramLogWriter#setBaseTime}). * The default base time is 0. * <p> * By covention, histogram start/end time are generally stamped with absolute times in msec * since the epoch. For logging with absolute time stamps, the base time would remain zero. For * logging with relative time stamps (time since a start point), the base time should be set * with {@link org.HdrHistogram.HistogramLogWriter#setBaseTime}. * <p> * The max value in the histogram will be reported scaled down by a default maxValueUnitRatio of * 1,000,000 (which is the msec : nsec ratio). Caller should use the direct form specifying * maxValueUnitRatio if some other ratio is needed for the max value output. * @param histogram The interval histogram to log. */ public void outputIntervalHistogram(final EncodableHistogram histogram) { outputIntervalHistogram((histogram.getStartTimeStamp() - baseTime)/1000.0, (histogram.getEndTimeStamp() - baseTime)/1000.0, histogram); }
histogram.setStartTimeStamp((long) (absoluteStartTimeStampSec * 1000.0)); histogram.setEndTimeStamp((long) (absoluteEndTimeStampSec * 1000.0)); histogram.setTag(tag); nextHistogram = histogram; return true;
boolean nullTagFound = false; while ((histogram = getIntervalHistogram()) != null) { String tag = histogram.getTag(); if (tag != null) { tags.add(histogram.getTag()); } else { nullTagFound = true; long windowCutOffTimeStamp = intervalHistogram.getEndTimeStamp() - config.movingWindowLengthInMsec; (movingWindowQueue.peek().getEndTimeStamp() <= windowCutOffTimeStamp)) { EncodableHistogram prevHist = movingWindowQueue.remove(); if (movingWindowSumHistogram instanceof DoubleHistogram) { ((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()), } else { timeIntervalLog.format(Locale.US, logFormat, ((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()), ((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()), } else { movingWindowLog.format(Locale.US, movingWindowLogFormat, ((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()),
private EncodableHistogram getIntervalHistogram(String tag) { EncodableHistogram histogram; if (tag == null) { do { histogram = getIntervalHistogram(); } while ((histogram != null) && histogram.getTag() != null); } else { do { histogram = getIntervalHistogram(); } while ((histogram != null) && !tag.equals(histogram.getTag())); } return histogram; }
histogram.setStartTimeStamp((long) (absoluteStartTimeStampSec * 1000.0)); histogram.setEndTimeStamp((long) (absoluteEndTimeStampSec * 1000.0)); histogram.setTag(tag); nextHistogram = histogram; return true;
boolean nullTagFound = false; while ((histogram = getIntervalHistogram()) != null) { String tag = histogram.getTag(); if (tag != null) { tags.add(histogram.getTag()); } else { nullTagFound = true; long windowCutOffTimeStamp = intervalHistogram.getEndTimeStamp() - config.movingWindowLengthInMsec; (movingWindowQueue.peek().getEndTimeStamp() <= windowCutOffTimeStamp)) { EncodableHistogram prevHist = movingWindowQueue.remove(); if (movingWindowSumHistogram instanceof DoubleHistogram) { ((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()), } else { timeIntervalLog.format(Locale.US, logFormat, ((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()), ((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()), } else { movingWindowLog.format(Locale.US, movingWindowLogFormat, ((intervalHistogram.getEndTimeStamp() / 1000.0) - logReader.getStartTimeSec()),
private EncodableHistogram getIntervalHistogram(String tag) { EncodableHistogram histogram; if (tag == null) { do { histogram = getIntervalHistogram(); } while ((histogram != null) && histogram.getTag() != null); } else { do { histogram = getIntervalHistogram(); } while ((histogram != null) && !tag.equals(histogram.getTag())); } return histogram; }
final EncodableHistogram histogram, final double maxValueUnitRatio) { if ((targetBuffer == null) || targetBuffer.capacity() < histogram.getNeededByteBufferCapacity()) { targetBuffer = ByteBuffer.allocate(histogram.getNeededByteBufferCapacity()).order(BIG_ENDIAN); int compressedLength = histogram.encodeIntoCompressedByteBuffer(targetBuffer, Deflater.BEST_COMPRESSION); byte[] compressedArray = Arrays.copyOf(targetBuffer.array(), compressedLength); String tag = histogram.getTag(); if (tag == null) { log.format(Locale.US, "%.3f,%.3f,%.3f,%s\n", startTimeStampSec, endTimeStampSec - startTimeStampSec, histogram.getMaxValueAsDouble() / maxValueUnitRatio, Base64Helper.printBase64Binary(compressedArray) ); startTimeStampSec, endTimeStampSec - startTimeStampSec, histogram.getMaxValueAsDouble() / maxValueUnitRatio, Base64Helper.printBase64Binary(compressedArray) );
private EncodableHistogram getIntervalHistogram(String tag) { EncodableHistogram histogram; if (tag == null) { do { histogram = getIntervalHistogram(); } while ((histogram != null) && histogram.getTag() != null); } else { do { histogram = getIntervalHistogram(); } while ((histogram != null) && !tag.equals(histogram.getTag())); } return histogram; }
@Override public Histogram deserialize(String serialized) { try { byte[] rawBytes = DatatypeConverter.parseBase64Binary(serialized); final ByteBuffer buffer = ByteBuffer.wrap(rawBytes, 0, rawBytes.length - (2 * Long.BYTES)); Histogram histogram = (Histogram) EncodableHistogram.decodeFromCompressedByteBuffer(buffer, 0); final ByteBuffer timestamps = ByteBuffer.wrap(rawBytes, 0, rawBytes.length); histogram.setStartTimeStamp(timestamps.getLong(rawBytes.length - (2 * Long.BYTES))); histogram.setEndTimeStamp(timestamps.getLong(rawBytes.length - (2 * Long.BYTES) + Long.BYTES)); return histogram; } catch (DataFormatException e) { throw new RuntimeException(e); } }
/** * Output an interval histogram, using the start/end timestamp indicated in the histogram, * and the [optional] tag associated with the histogram. * The histogram start and end timestamps are assumed to be in msec units. Logging will be * in seconds, realtive by a base time (if set via {@link org.HdrHistogram.HistogramLogWriter#setBaseTime}). * The default base time is 0. * <p> * By covention, histogram start/end time are generally stamped with absolute times in msec * since the epoch. For logging with absolute time stamps, the base time would remain zero. For * logging with relative time stamps (time since a start point), the base time should be set * with {@link org.HdrHistogram.HistogramLogWriter#setBaseTime}. * <p> * The max value in the histogram will be reported scaled down by a default maxValueUnitRatio of * 1,000,000 (which is the msec : nsec ratio). Caller should use the direct form specifying * maxValueUnitRatio if some other ratio is needed for the max value output. * @param histogram The interval histogram to log. */ public void outputIntervalHistogram(final EncodableHistogram histogram) { outputIntervalHistogram((histogram.getStartTimeStamp() - baseTime)/1000.0, (histogram.getEndTimeStamp() - baseTime)/1000.0, histogram); }
@Override public EncodableHistogram read() throws DataFormatException { // prevent double calls to this method if (gotIt) throw new IllegalStateException(); gotIt = true; final String compressedPayloadString = scanner.next(); final ByteBuffer buffer = ByteBuffer.wrap(Base64Helper.parseBase64Binary(compressedPayloadString)); EncodableHistogram histogram = EncodableHistogram.decodeFromCompressedByteBuffer(buffer, 0); return histogram; } }