UNPKG

1.56 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.SizeStack = void 0;
4const js_lib_1 = require("@naturalcycles/js-lib");
5const colors_1 = require("../colors");
6const zip_util_1 = require("../util/zip.util");
7class SizeStack extends js_lib_1.NumberStack {
8 constructor(name, size) {
9 super(size);
10 this.name = name;
11 this.total = 0;
12 }
13 push(item) {
14 this.total += item;
15 return super.push(item);
16 }
17 getStats() {
18 // const pcs = this.percentiles([50, 90])
19 return [
20 ' ' + this.name,
21 'avg',
22 (0, colors_1.yellow)((0, js_lib_1._hb)(this.avg())),
23 // 'p50',
24 // yellow(_hb(pcs[50])),
25 // 'p90',
26 // yellow(_hb(pcs[90])),
27 'total',
28 (0, colors_1.yellow)((0, js_lib_1._hb)(this.total)),
29 ].join(' ');
30 }
31 static async countItem(item, logger, sizes, sizesZipped) {
32 if (!sizes)
33 return;
34 // try-catch, because we don't want to fail the pipeline on logProgress
35 try {
36 const buf = Buffer.from(JSON.stringify(item));
37 sizes.push(buf.byteLength);
38 if (sizesZipped) {
39 const { byteLength } = await (0, zip_util_1.gzipBuffer)(buf);
40 sizesZipped.push(byteLength);
41 }
42 }
43 catch (err) {
44 logger.warn(`transformLogProgress failed to JSON.stringify the chunk: ${err.message}`);
45 }
46 }
47}
48exports.SizeStack = SizeStack;