@jsenv/test 3.6.7 → 3.6.8
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 +234 -668
- package/dist/jsenv_test_node_modules.js +295 -0
- package/package.json +10 -10
- package/src/execution/execute_test_plan.js +21 -82
- package/src/execution/reporters/reporter_list.js +3 -73
- package/src/helpers/call_orderer.js +0 -39
- package/src/helpers/cpu_usage.js +0 -221
- package/src/helpers/cpu_usage.test_manual.js +0 -17
package/src/helpers/cpu_usage.js
DELETED
|
@@ -1,221 +0,0 @@
|
|
|
1
|
-
// https://gist.github.com/GaetanoPiazzolla/c40e1ebb9f709d091208e89baf9f4e00
|
|
2
|
-
|
|
3
|
-
import { cpus } from "node:os";
|
|
4
|
-
import { cpuUsage } from "node:process";
|
|
5
|
-
|
|
6
|
-
export const startMeasuringTotalCpuUsage = () => {
|
|
7
|
-
let previousCpuArray = cpus();
|
|
8
|
-
let previousMs = Date.now();
|
|
9
|
-
let previousCpuUsage = cpuUsage();
|
|
10
|
-
|
|
11
|
-
const overall = {
|
|
12
|
-
inactive: 100,
|
|
13
|
-
active: 0,
|
|
14
|
-
system: 0,
|
|
15
|
-
user: 0,
|
|
16
|
-
};
|
|
17
|
-
const thisProcess = {
|
|
18
|
-
active: 0,
|
|
19
|
-
system: 0,
|
|
20
|
-
user: 0,
|
|
21
|
-
};
|
|
22
|
-
const details = previousCpuArray.map(() => {
|
|
23
|
-
return {
|
|
24
|
-
inactive: 100,
|
|
25
|
-
active: 0,
|
|
26
|
-
system: 0,
|
|
27
|
-
user: 0,
|
|
28
|
-
};
|
|
29
|
-
});
|
|
30
|
-
|
|
31
|
-
const samples = [];
|
|
32
|
-
const interval = setInterval(() => {
|
|
33
|
-
let cpuArray = cpus();
|
|
34
|
-
const ms = Date.now();
|
|
35
|
-
const ellapsedMs = ms - previousMs;
|
|
36
|
-
const cpuUsageSampleArray = [];
|
|
37
|
-
let overallSystemMs = 0;
|
|
38
|
-
let overallUserMs = 0;
|
|
39
|
-
let overallInactiveMs = 0;
|
|
40
|
-
let overallActiveMs = 0;
|
|
41
|
-
let overallMsEllapsed = 0;
|
|
42
|
-
let index = 0;
|
|
43
|
-
for (const cpu of cpuArray) {
|
|
44
|
-
const previousCpuTimes = previousCpuArray[index].times;
|
|
45
|
-
const cpuTimes = cpu.times;
|
|
46
|
-
const systemMs = cpuTimes.sys - previousCpuTimes.sys;
|
|
47
|
-
const userMs = cpuTimes.user - previousCpuTimes.user;
|
|
48
|
-
const activeMs = systemMs + userMs;
|
|
49
|
-
const inactiveMs = ellapsedMs - activeMs;
|
|
50
|
-
const cpuUsageSample = {
|
|
51
|
-
inactive: inactiveMs / ellapsedMs,
|
|
52
|
-
active: activeMs / ellapsedMs,
|
|
53
|
-
system: systemMs / ellapsedMs,
|
|
54
|
-
user: userMs / ellapsedMs,
|
|
55
|
-
};
|
|
56
|
-
cpuUsageSampleArray.push(cpuUsageSample);
|
|
57
|
-
|
|
58
|
-
overallSystemMs += systemMs;
|
|
59
|
-
overallUserMs += userMs;
|
|
60
|
-
overallInactiveMs += inactiveMs;
|
|
61
|
-
overallActiveMs += activeMs;
|
|
62
|
-
overallMsEllapsed += ellapsedMs;
|
|
63
|
-
index++;
|
|
64
|
-
}
|
|
65
|
-
const overallUsageSample = {
|
|
66
|
-
inactive: overallInactiveMs / overallMsEllapsed,
|
|
67
|
-
active: overallActiveMs / overallMsEllapsed,
|
|
68
|
-
system: overallSystemMs / overallMsEllapsed,
|
|
69
|
-
user: overallUserMs / overallMsEllapsed,
|
|
70
|
-
};
|
|
71
|
-
previousCpuArray = cpuArray;
|
|
72
|
-
previousMs = ms;
|
|
73
|
-
|
|
74
|
-
const processCpuUsage = cpuUsage();
|
|
75
|
-
const thisProcessSystemMs = Math.round(
|
|
76
|
-
(processCpuUsage.system - previousCpuUsage.system) / 1000,
|
|
77
|
-
);
|
|
78
|
-
const thisProcessUserMs = Math.round(
|
|
79
|
-
(processCpuUsage.user - previousCpuUsage.user) / 1000,
|
|
80
|
-
);
|
|
81
|
-
previousCpuUsage = processCpuUsage;
|
|
82
|
-
|
|
83
|
-
const thisProcessActiveMs = thisProcessSystemMs + thisProcessUserMs;
|
|
84
|
-
const thisProcessInactiveMs = overallMsEllapsed - thisProcessActiveMs;
|
|
85
|
-
const thisProcessSample = {
|
|
86
|
-
inactive: thisProcessInactiveMs / overallMsEllapsed,
|
|
87
|
-
active: thisProcessActiveMs / overallMsEllapsed,
|
|
88
|
-
system: thisProcessSystemMs / overallMsEllapsed,
|
|
89
|
-
user: thisProcessUserMs / overallMsEllapsed,
|
|
90
|
-
};
|
|
91
|
-
samples.push({
|
|
92
|
-
cpuUsageSampleArray,
|
|
93
|
-
overallUsageSample,
|
|
94
|
-
thisProcessSample,
|
|
95
|
-
});
|
|
96
|
-
if (samples.length === 10) {
|
|
97
|
-
per_cpu: {
|
|
98
|
-
let index = 0;
|
|
99
|
-
for (const detail of details) {
|
|
100
|
-
let systemSum = 0;
|
|
101
|
-
let userSum = 0;
|
|
102
|
-
let inactiveSum = 0;
|
|
103
|
-
let activeSum = 0;
|
|
104
|
-
for (const sample of samples) {
|
|
105
|
-
const { cpuUsageSampleArray } = sample;
|
|
106
|
-
const cpuUsageSample = cpuUsageSampleArray[index];
|
|
107
|
-
inactiveSum += cpuUsageSample.inactive;
|
|
108
|
-
activeSum += cpuUsageSample.active;
|
|
109
|
-
systemSum += cpuUsageSample.system;
|
|
110
|
-
userSum += cpuUsageSample.user;
|
|
111
|
-
}
|
|
112
|
-
Object.assign(detail, {
|
|
113
|
-
inactive: inactiveSum / samples.length,
|
|
114
|
-
active: activeSum / samples.length,
|
|
115
|
-
system: systemSum / samples.length,
|
|
116
|
-
user: userSum / samples.length,
|
|
117
|
-
});
|
|
118
|
-
index++;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
all: {
|
|
122
|
-
let overallSystemSum = 0;
|
|
123
|
-
let overallUserSum = 0;
|
|
124
|
-
let overallInactiveSum = 0;
|
|
125
|
-
let overallActiveSum = 0;
|
|
126
|
-
for (const sample of samples) {
|
|
127
|
-
const { overallUsageSample } = sample;
|
|
128
|
-
overallSystemSum += overallUsageSample.system;
|
|
129
|
-
overallUserSum += overallUsageSample.user;
|
|
130
|
-
overallInactiveSum += overallUsageSample.inactive;
|
|
131
|
-
overallActiveSum += overallUsageSample.active;
|
|
132
|
-
}
|
|
133
|
-
Object.assign(overall, {
|
|
134
|
-
inactive: overallInactiveSum / samples.length,
|
|
135
|
-
active: overallActiveSum / samples.length,
|
|
136
|
-
system: overallSystemSum / samples.length,
|
|
137
|
-
user: overallUserSum / samples.length,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
this_process: {
|
|
141
|
-
let thisProcessSystemSum = 0;
|
|
142
|
-
let thisProcessUserSum = 0;
|
|
143
|
-
let thisProcessInactiveSum = 0;
|
|
144
|
-
let thisProcessActiveSum = 0;
|
|
145
|
-
for (const sample of samples) {
|
|
146
|
-
const { thisProcessSample } = sample;
|
|
147
|
-
thisProcessSystemSum += thisProcessSample.system;
|
|
148
|
-
thisProcessUserSum += thisProcessSample.user;
|
|
149
|
-
thisProcessInactiveSum += thisProcessSample.inactive;
|
|
150
|
-
thisProcessActiveSum += thisProcessSample.active;
|
|
151
|
-
}
|
|
152
|
-
Object.assign(thisProcess, {
|
|
153
|
-
inactive: thisProcessInactiveSum / samples.length,
|
|
154
|
-
active: thisProcessActiveSum / samples.length,
|
|
155
|
-
system: thisProcessSystemSum / samples.length,
|
|
156
|
-
user: thisProcessUserSum / samples.length,
|
|
157
|
-
});
|
|
158
|
-
}
|
|
159
|
-
samples.length = 0;
|
|
160
|
-
}
|
|
161
|
-
}, 15);
|
|
162
|
-
interval.unref();
|
|
163
|
-
|
|
164
|
-
return {
|
|
165
|
-
overall,
|
|
166
|
-
thisProcess,
|
|
167
|
-
details,
|
|
168
|
-
stop: () => {
|
|
169
|
-
clearInterval(interval);
|
|
170
|
-
},
|
|
171
|
-
};
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
export const formatUsage = (usageInfo) => {
|
|
175
|
-
const { active, inactive, system, user } = usageInfo;
|
|
176
|
-
|
|
177
|
-
return `${ratioAsPercentage(active)} (system: ${ratioAsPercentage(
|
|
178
|
-
system,
|
|
179
|
-
)}, user: ${ratioAsPercentage(user)}), inactive: ${ratioAsPercentage(
|
|
180
|
-
inactive,
|
|
181
|
-
)}`;
|
|
182
|
-
};
|
|
183
|
-
|
|
184
|
-
export const ratioAsPercentage = (ratio) => {
|
|
185
|
-
const percentageAsNumber = ratio * 100;
|
|
186
|
-
const percentageAsNumberRounded = Math.round(percentageAsNumber);
|
|
187
|
-
const percentage = `${percentageAsNumberRounded}%`;
|
|
188
|
-
return percentage;
|
|
189
|
-
};
|
|
190
|
-
|
|
191
|
-
export const startMeasuringCpuUsage = () => {
|
|
192
|
-
let previousHrtime = process.hrtime();
|
|
193
|
-
let previousCpuUsage = process.cpuUsage();
|
|
194
|
-
|
|
195
|
-
const info = {
|
|
196
|
-
used: 0,
|
|
197
|
-
};
|
|
198
|
-
|
|
199
|
-
const interval = setInterval(() => {
|
|
200
|
-
const hrtime = process.hrtime(previousHrtime);
|
|
201
|
-
previousHrtime = hrtime;
|
|
202
|
-
const cpuUsage = process.cpuUsage(previousCpuUsage);
|
|
203
|
-
previousCpuUsage = cpuUsage;
|
|
204
|
-
|
|
205
|
-
const ellapsedMs = hrtime[0] * 1000 + hrtime[1] / 1000000;
|
|
206
|
-
const userMs = Math.round(cpuUsage.user / 1000);
|
|
207
|
-
const systemMs = Math.round(cpuUsage.system / 1000);
|
|
208
|
-
const activeMs = userMs + systemMs;
|
|
209
|
-
const usedRatio = activeMs / ellapsedMs;
|
|
210
|
-
const used = Math.round(usedRatio * 100) / 100;
|
|
211
|
-
info.used = used;
|
|
212
|
-
}, 15);
|
|
213
|
-
interval.unref();
|
|
214
|
-
|
|
215
|
-
return {
|
|
216
|
-
info,
|
|
217
|
-
stop: () => {
|
|
218
|
-
clearInterval(interval);
|
|
219
|
-
},
|
|
220
|
-
};
|
|
221
|
-
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
formatUsage,
|
|
3
|
-
startMeasuringCpuUsage,
|
|
4
|
-
startMeasuringTotalCpuUsage,
|
|
5
|
-
} from "./cpu_usage.js";
|
|
6
|
-
|
|
7
|
-
const cpuUsage = startMeasuringCpuUsage();
|
|
8
|
-
setInterval(() => {
|
|
9
|
-
console.log(cpuUsage.info.used);
|
|
10
|
-
}, 400);
|
|
11
|
-
|
|
12
|
-
const totalCpuUsage = startMeasuringTotalCpuUsage();
|
|
13
|
-
setInterval(() => {
|
|
14
|
-
console.log(`overall: ${formatUsage(totalCpuUsage.overall)}
|
|
15
|
-
this process: ${formatUsage(totalCpuUsage.thisProcess)}
|
|
16
|
-
`);
|
|
17
|
-
}, 400);
|