UNPKG

4.33 kBJavaScriptView Raw
1"use strict";
2/**
3 * @license
4 * Copyright (c) 2019 The Polymer Project Authors. All rights reserved.
5 * This code may only be used under the BSD style license found at
6 * http://polymer.github.io/LICENSE.txt The complete set of authors may be found
7 * at http://polymer.github.io/AUTHORS.txt The complete set of contributors may
8 * be found at http://polymer.github.io/CONTRIBUTORS.txt Code distributed by
9 * Google as part of the polymer project is also subject to an additional IP
10 * rights grant found at http://polymer.github.io/PATENTS.txt
11 */
12var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
13 if (k2 === undefined) k2 = k;
14 Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
15}) : (function(o, m, k, k2) {
16 if (k2 === undefined) k2 = k;
17 o[k2] = m[k];
18}));
19var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20 Object.defineProperty(o, "default", { enumerable: true, value: v });
21}) : function(o, v) {
22 o["default"] = v;
23});
24var __importStar = (this && this.__importStar) || function (mod) {
25 if (mod && mod.__esModule) return mod;
26 var result = {};
27 if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
28 __setModuleDefault(result, mod);
29 return result;
30};
31Object.defineProperty(exports, "__esModule", { value: true });
32exports.legacyJsonOutput = exports.jsonOutput = void 0;
33const systeminformation = __importStar(require("systeminformation"));
34const measure_1 = require("./measure");
35function jsonOutput(results) {
36 const benchmarks = [];
37 for (const result of results) {
38 const differences = [];
39 for (const difference of result.differences) {
40 if (difference === null) {
41 differences.push(null);
42 }
43 else {
44 differences.push({
45 absolute: {
46 low: difference.absolute.low,
47 high: difference.absolute.high,
48 },
49 percentChange: {
50 low: difference.relative.low * 100,
51 high: difference.relative.high * 100,
52 },
53 });
54 }
55 }
56 benchmarks.push({
57 name: result.result.name,
58 bytesSent: result.result.bytesSent,
59 version: result.result.version ? result.result.version : undefined,
60 measurement: Object.assign({ name: measure_1.measurementName(result.result.measurement) }, result.result.measurement),
61 browser: Object.assign(Object.assign({}, result.result.browser), { userAgent: result.result.userAgent }),
62 mean: {
63 low: result.stats.meanCI.low,
64 high: result.stats.meanCI.high,
65 },
66 differences,
67 samples: result.result.millis,
68 });
69 }
70 return { benchmarks };
71}
72exports.jsonOutput = jsonOutput;
73// TODO(aomarks) Remove this in next major version.
74async function legacyJsonOutput(results) {
75 // TODO Add git info.
76 const battery = await systeminformation.battery();
77 const cpu = await systeminformation.cpu();
78 const currentLoad = await systeminformation.currentLoad();
79 const memory = await systeminformation.mem();
80 return {
81 benchmarks: results,
82 datetime: new Date().toISOString(),
83 system: {
84 cpu: {
85 manufacturer: cpu.manufacturer,
86 model: cpu.model,
87 family: cpu.family,
88 speed: cpu.speed,
89 cores: cpu.cores,
90 },
91 load: {
92 average: currentLoad.avgload,
93 current: currentLoad.currentload,
94 },
95 battery: {
96 hasBattery: battery.hasbattery,
97 connected: battery.acconnected,
98 },
99 memory: {
100 total: memory.total,
101 free: memory.free,
102 used: memory.used,
103 active: memory.active,
104 available: memory.available,
105 },
106 },
107 };
108}
109exports.legacyJsonOutput = legacyJsonOutput;
110//# sourceMappingURL=json-output.js.map
\No newline at end of file