source: trip-planner-front/node_modules/hdr-histogram-js/dist/HistogramLogWriter.js@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 3.3 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const Histogram_1 = require("./Histogram");
4const encoding_1 = require("./encoding");
5const formatters_1 = require("./formatters");
6const HISTOGRAM_LOG_FORMAT_VERSION = "1.3";
7const timeFormatter = formatters_1.floatFormatter(5, 3);
8class HistogramLogWriter {
9 constructor(log) {
10 this.log = log;
11 /**
12 * Base time to subtract from supplied histogram start/end timestamps when
13 * logging based on histogram timestamps.
14 * Base time is expected to be in msec since the epoch, as histogram start/end times
15 * are typically stamped with absolute times in msec since the epoch.
16 */
17 this.baseTime = 0;
18 }
19 /**
20 * Output an interval histogram, with the given timestamp information and the [optional] tag
21 * associated with the histogram, using a configurable maxValueUnitRatio. (note that the
22 * specified timestamp information will be used, and the timestamp information in the actual
23 * histogram will be ignored).
24 * The max value reported with the interval line will be scaled by the given maxValueUnitRatio.
25 * @param startTimeStampSec The start timestamp to log with the interval histogram, in seconds.
26 * @param endTimeStampSec The end timestamp to log with the interval histogram, in seconds.
27 * @param histogram The interval histogram to log.
28 * @param maxValueUnitRatio The ratio by which to divide the histogram's max value when reporting on it.
29 */
30 outputIntervalHistogram(histogram, startTimeStampSec = (histogram.startTimeStampMsec - this.baseTime) / 1000, endTimeStampSec = (histogram.endTimeStampMsec - this.baseTime) / 1000, maxValueUnitRatio = 1000) {
31 const base64 = encoding_1.encodeIntoCompressedBase64(histogram);
32 const start = timeFormatter(startTimeStampSec);
33 const duration = timeFormatter(endTimeStampSec - startTimeStampSec);
34 const max = timeFormatter(histogram.maxValue / maxValueUnitRatio);
35 const lineContent = `${start},${duration},${max},${base64}\n`;
36 if (histogram.tag && histogram.tag !== Histogram_1.NO_TAG) {
37 this.log(`Tag=${histogram.tag},${lineContent}`);
38 }
39 else {
40 this.log(lineContent);
41 }
42 }
43 /**
44 * Log a comment to the log.
45 * Comments will be preceded with with the '#' character.
46 * @param comment the comment string.
47 */
48 outputComment(comment) {
49 this.log(`#${comment}\n`);
50 }
51 /**
52 * Log a start time in the log.
53 * @param startTimeMsec time (in milliseconds) since the absolute start time (the epoch)
54 */
55 outputStartTime(startTimeMsec) {
56 this.outputComment(`[StartTime: ${formatters_1.floatFormatter(5, 3)(startTimeMsec / 1000)} (seconds since epoch), ${new Date(startTimeMsec)}]\n`);
57 }
58 /**
59 * Output a legend line to the log.
60 */
61 outputLegend() {
62 this.log('"StartTimestamp","Interval_Length","Interval_Max","Interval_Compressed_Histogram"\n');
63 }
64 /**
65 * Output a log format version to the log.
66 */
67 outputLogFormatVersion() {
68 this.outputComment("[Histogram log format version " + HISTOGRAM_LOG_FORMAT_VERSION + "]");
69 }
70}
71exports.default = HistogramLogWriter;
72//# sourceMappingURL=HistogramLogWriter.js.map
Note: See TracBrowser for help on using the repository browser.