@jsenv/test 3.0.9 → 3.0.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/jsenv_test.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import os, { cpus, totalmem,
|
|
1
|
+
import os, { cpus, totalmem, availableParallelism } from "node:os";
|
|
2
|
+
import process$1, { cpuUsage, memoryUsage } from "node:process";
|
|
2
3
|
import { readdir, chmod, stat, lstat, promises, readFile as readFile$1, writeFileSync as writeFileSync$1, mkdirSync, unlink, openSync, closeSync, rmdir, chmodSync, statSync, lstatSync, unlinkSync, readdirSync, rmdirSync, readFileSync, existsSync } from "node:fs";
|
|
3
4
|
import { takeCoverage } from "node:v8";
|
|
4
5
|
import stripAnsi from "strip-ansi";
|
|
5
6
|
import { URL_META, createException } from "./js/exception.js";
|
|
6
7
|
import stringWidth from "string-width";
|
|
7
|
-
import process$1, { memoryUsage } from "node:process";
|
|
8
8
|
import tty from "node:tty";
|
|
9
9
|
import { pathToFileURL, fileURLToPath } from "node:url";
|
|
10
10
|
import { dirname } from "node:path";
|
|
@@ -3292,9 +3292,10 @@ process.platform === "linux";
|
|
|
3292
3292
|
// https://gist.github.com/GaetanoPiazzolla/c40e1ebb9f709d091208e89baf9f4e00
|
|
3293
3293
|
|
|
3294
3294
|
|
|
3295
|
-
const
|
|
3295
|
+
const startMeasuringTotalCpuUsage = () => {
|
|
3296
3296
|
let previousCpuArray = cpus();
|
|
3297
3297
|
let previousMs = Date.now();
|
|
3298
|
+
let previousCpuUsage = cpuUsage();
|
|
3298
3299
|
|
|
3299
3300
|
const overall = {
|
|
3300
3301
|
inactive: 100,
|
|
@@ -3302,6 +3303,12 @@ const startMeasuringCpuUsage = () => {
|
|
|
3302
3303
|
system: 0,
|
|
3303
3304
|
user: 0,
|
|
3304
3305
|
};
|
|
3306
|
+
|
|
3307
|
+
const thisProcess = {
|
|
3308
|
+
active: 0,
|
|
3309
|
+
system: 0,
|
|
3310
|
+
user: 0,
|
|
3311
|
+
};
|
|
3305
3312
|
const details = previousCpuArray.map(() => {
|
|
3306
3313
|
return {
|
|
3307
3314
|
inactive: 100,
|
|
@@ -3358,6 +3365,19 @@ const startMeasuringCpuUsage = () => {
|
|
|
3358
3365
|
overallUsageSample,
|
|
3359
3366
|
});
|
|
3360
3367
|
|
|
3368
|
+
const processCpuUsage = cpuUsage();
|
|
3369
|
+
const thisProcessSystemMs = Math.round(
|
|
3370
|
+
(processCpuUsage.system - previousCpuUsage.system) / 1000,
|
|
3371
|
+
);
|
|
3372
|
+
const thisProcessUserMs = Math.round(
|
|
3373
|
+
(processCpuUsage.user - previousCpuUsage.user) / 1000,
|
|
3374
|
+
);
|
|
3375
|
+
previousCpuUsage = processCpuUsage;
|
|
3376
|
+
const thisProcessActiveMs = thisProcessSystemMs + thisProcessUserMs;
|
|
3377
|
+
thisProcess.active = thisProcessActiveMs / overallActiveMs;
|
|
3378
|
+
thisProcess.system = thisProcessSystemMs / overallSystemMs;
|
|
3379
|
+
thisProcess.user = thisProcessUserMs / overallUserMs;
|
|
3380
|
+
|
|
3361
3381
|
if (samples.length === 10) {
|
|
3362
3382
|
let index = 0;
|
|
3363
3383
|
for (const detail of details) {
|
|
@@ -3407,6 +3427,7 @@ const startMeasuringCpuUsage = () => {
|
|
|
3407
3427
|
|
|
3408
3428
|
return {
|
|
3409
3429
|
overall,
|
|
3430
|
+
thisProcess,
|
|
3410
3431
|
details,
|
|
3411
3432
|
stop: () => {
|
|
3412
3433
|
clearInterval(interval);
|
|
@@ -5671,8 +5692,8 @@ const coverageDefault = {
|
|
|
5671
5692
|
};
|
|
5672
5693
|
const parallelDefault = {
|
|
5673
5694
|
max: "80%", // percentage resolved against the available cpus
|
|
5674
|
-
maxCpu: "
|
|
5675
|
-
maxMemory: "
|
|
5695
|
+
maxCpu: "80%",
|
|
5696
|
+
maxMemory: "50%",
|
|
5676
5697
|
};
|
|
5677
5698
|
|
|
5678
5699
|
const executeTestPlan = async ({
|
|
@@ -5780,7 +5801,7 @@ const executeTestPlan = async ({
|
|
|
5780
5801
|
let finalizeCoverage;
|
|
5781
5802
|
|
|
5782
5803
|
try {
|
|
5783
|
-
const cpuUsage =
|
|
5804
|
+
const cpuUsage = startMeasuringTotalCpuUsage();
|
|
5784
5805
|
operation.addEndCallback(cpuUsage.stop);
|
|
5785
5806
|
|
|
5786
5807
|
let logger;
|
|
@@ -6425,16 +6446,15 @@ To fix this warning:
|
|
|
6425
6446
|
// if nothing is executing these limitations don't apply
|
|
6426
6447
|
executionExecutingSet.size > 0
|
|
6427
6448
|
) {
|
|
6428
|
-
const
|
|
6429
|
-
|
|
6430
|
-
const usedMemory = totalMemory - freeMemory;
|
|
6431
|
-
if (usedMemory > parallel.maxMemory) {
|
|
6449
|
+
const memoryUsedByThisProcess = memoryUsage().rss;
|
|
6450
|
+
if (memoryUsedByThisProcess > parallel.maxMemory) {
|
|
6432
6451
|
// retry after Xms in case memory usage decreases
|
|
6433
6452
|
const promise = operation.wait(200);
|
|
6434
6453
|
promises.push(promise);
|
|
6435
6454
|
break;
|
|
6436
6455
|
}
|
|
6437
|
-
|
|
6456
|
+
|
|
6457
|
+
if (cpuUsage.thisProcess.active > parallel.maxCpu) {
|
|
6438
6458
|
// retry after Xms in case cpu usage decreases
|
|
6439
6459
|
const promise = operation.wait(200);
|
|
6440
6460
|
promises.push(promise);
|
package/package.json
CHANGED
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
*
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
|
-
import { cpus, availableParallelism,
|
|
5
|
+
import { cpus, availableParallelism, totalmem } from "node:os";
|
|
6
|
+
import { memoryUsage } from "node:process";
|
|
6
7
|
import { existsSync } from "node:fs";
|
|
7
8
|
import { takeCoverage } from "node:v8";
|
|
8
9
|
import stripAnsi from "strip-ansi";
|
|
@@ -19,7 +20,7 @@ import {
|
|
|
19
20
|
readGitHubWorkflowEnv,
|
|
20
21
|
} from "@jsenv/github-check-run";
|
|
21
22
|
|
|
22
|
-
import {
|
|
23
|
+
import { startMeasuringTotalCpuUsage } from "../helpers/cpu_usage.js";
|
|
23
24
|
import { createCallOrderer } from "../helpers/call_orderer.js";
|
|
24
25
|
import { generateCoverage } from "../coverage/generate_coverage.js";
|
|
25
26
|
import { assertAndNormalizeWebServer } from "./web_server_param.js";
|
|
@@ -87,8 +88,8 @@ const coverageDefault = {
|
|
|
87
88
|
};
|
|
88
89
|
const parallelDefault = {
|
|
89
90
|
max: "80%", // percentage resolved against the available cpus
|
|
90
|
-
maxCpu: "
|
|
91
|
-
maxMemory: "
|
|
91
|
+
maxCpu: "80%",
|
|
92
|
+
maxMemory: "50%",
|
|
92
93
|
};
|
|
93
94
|
|
|
94
95
|
export const executeTestPlan = async ({
|
|
@@ -196,7 +197,7 @@ export const executeTestPlan = async ({
|
|
|
196
197
|
let finalizeCoverage;
|
|
197
198
|
|
|
198
199
|
try {
|
|
199
|
-
const cpuUsage =
|
|
200
|
+
const cpuUsage = startMeasuringTotalCpuUsage();
|
|
200
201
|
operation.addEndCallback(cpuUsage.stop);
|
|
201
202
|
|
|
202
203
|
let logger;
|
|
@@ -841,16 +842,15 @@ To fix this warning:
|
|
|
841
842
|
// if nothing is executing these limitations don't apply
|
|
842
843
|
executionExecutingSet.size > 0
|
|
843
844
|
) {
|
|
844
|
-
const
|
|
845
|
-
|
|
846
|
-
const usedMemory = totalMemory - freeMemory;
|
|
847
|
-
if (usedMemory > parallel.maxMemory) {
|
|
845
|
+
const memoryUsedByThisProcess = memoryUsage().rss;
|
|
846
|
+
if (memoryUsedByThisProcess > parallel.maxMemory) {
|
|
848
847
|
// retry after Xms in case memory usage decreases
|
|
849
848
|
const promise = operation.wait(200);
|
|
850
849
|
promises.push(promise);
|
|
851
850
|
break;
|
|
852
851
|
}
|
|
853
|
-
|
|
852
|
+
|
|
853
|
+
if (cpuUsage.thisProcess.active > parallel.maxCpu) {
|
|
854
854
|
// retry after Xms in case cpu usage decreases
|
|
855
855
|
const promise = operation.wait(200);
|
|
856
856
|
promises.push(promise);
|
package/src/helpers/cpu_usage.js
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// https://gist.github.com/GaetanoPiazzolla/c40e1ebb9f709d091208e89baf9f4e00
|
|
2
2
|
|
|
3
3
|
import { cpus } from "node:os";
|
|
4
|
+
import { cpuUsage } from "node:process";
|
|
4
5
|
|
|
5
|
-
export const
|
|
6
|
+
export const startMeasuringTotalCpuUsage = () => {
|
|
6
7
|
let previousCpuArray = cpus();
|
|
7
8
|
let previousMs = Date.now();
|
|
9
|
+
let previousCpuUsage = cpuUsage();
|
|
8
10
|
|
|
9
11
|
const overall = {
|
|
10
12
|
inactive: 100,
|
|
@@ -12,6 +14,12 @@ export const startMeasuringCpuUsage = () => {
|
|
|
12
14
|
system: 0,
|
|
13
15
|
user: 0,
|
|
14
16
|
};
|
|
17
|
+
|
|
18
|
+
const thisProcess = {
|
|
19
|
+
active: 0,
|
|
20
|
+
system: 0,
|
|
21
|
+
user: 0,
|
|
22
|
+
};
|
|
15
23
|
const details = previousCpuArray.map(() => {
|
|
16
24
|
return {
|
|
17
25
|
inactive: 100,
|
|
@@ -68,6 +76,19 @@ export const startMeasuringCpuUsage = () => {
|
|
|
68
76
|
overallUsageSample,
|
|
69
77
|
});
|
|
70
78
|
|
|
79
|
+
const processCpuUsage = cpuUsage();
|
|
80
|
+
const thisProcessSystemMs = Math.round(
|
|
81
|
+
(processCpuUsage.system - previousCpuUsage.system) / 1000,
|
|
82
|
+
);
|
|
83
|
+
const thisProcessUserMs = Math.round(
|
|
84
|
+
(processCpuUsage.user - previousCpuUsage.user) / 1000,
|
|
85
|
+
);
|
|
86
|
+
previousCpuUsage = processCpuUsage;
|
|
87
|
+
const thisProcessActiveMs = thisProcessSystemMs + thisProcessUserMs;
|
|
88
|
+
thisProcess.active = thisProcessActiveMs / overallActiveMs;
|
|
89
|
+
thisProcess.system = thisProcessSystemMs / overallSystemMs;
|
|
90
|
+
thisProcess.user = thisProcessUserMs / overallUserMs;
|
|
91
|
+
|
|
71
92
|
if (samples.length === 10) {
|
|
72
93
|
let index = 0;
|
|
73
94
|
for (const detail of details) {
|
|
@@ -117,6 +138,7 @@ export const startMeasuringCpuUsage = () => {
|
|
|
117
138
|
|
|
118
139
|
return {
|
|
119
140
|
overall,
|
|
141
|
+
thisProcess,
|
|
120
142
|
details,
|
|
121
143
|
stop: () => {
|
|
122
144
|
clearInterval(interval);
|
|
@@ -140,3 +162,35 @@ export const ratioAsPercentage = (ratio) => {
|
|
|
140
162
|
const percentage = `${percentageAsNumberRounded}%`;
|
|
141
163
|
return percentage;
|
|
142
164
|
};
|
|
165
|
+
|
|
166
|
+
export const startMeasuringCpuUsage = () => {
|
|
167
|
+
let previousHrtime = process.hrtime();
|
|
168
|
+
let previousCpuUsage = process.cpuUsage();
|
|
169
|
+
|
|
170
|
+
const info = {
|
|
171
|
+
used: 0,
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
const interval = setInterval(() => {
|
|
175
|
+
const hrtime = process.hrtime(previousHrtime);
|
|
176
|
+
previousHrtime = hrtime;
|
|
177
|
+
const cpuUsage = process.cpuUsage(previousCpuUsage);
|
|
178
|
+
previousCpuUsage = cpuUsage;
|
|
179
|
+
|
|
180
|
+
const ellapsedMs = hrtime[0] * 1000 + hrtime[1] / 1000000;
|
|
181
|
+
const userMs = Math.round(cpuUsage.user / 1000);
|
|
182
|
+
const systemMs = Math.round(cpuUsage.system / 1000);
|
|
183
|
+
const activeMs = userMs + systemMs;
|
|
184
|
+
const usedRatio = activeMs / ellapsedMs;
|
|
185
|
+
const used = Math.round(usedRatio * 100) / 100;
|
|
186
|
+
info.used = used;
|
|
187
|
+
}, 15);
|
|
188
|
+
interval.unref();
|
|
189
|
+
|
|
190
|
+
return {
|
|
191
|
+
info,
|
|
192
|
+
stop: () => {
|
|
193
|
+
clearInterval(interval);
|
|
194
|
+
},
|
|
195
|
+
};
|
|
196
|
+
};
|
|
@@ -1,7 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
startMeasuringCpuUsage,
|
|
3
|
+
startMeasuringTotalCpuUsage,
|
|
4
|
+
formatUsage,
|
|
5
|
+
} from "./cpu_usage.js";
|
|
2
6
|
|
|
3
7
|
const cpuUsage = startMeasuringCpuUsage();
|
|
8
|
+
setInterval(() => {
|
|
9
|
+
console.log(cpuUsage.info.used);
|
|
10
|
+
}, 400);
|
|
4
11
|
|
|
12
|
+
const totalCpuUsage = startMeasuringTotalCpuUsage();
|
|
5
13
|
setInterval(() => {
|
|
6
|
-
console.log(formatUsage(
|
|
14
|
+
console.log(formatUsage(totalCpuUsage.overall));
|
|
7
15
|
}, 400);
|