Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions lib/support/cpuStability.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,15 @@ export async function sampleCpu() {

export function getCpuStability(start, end) {
const total = end.total - start.total;
return {
const stability = {
stealPercent:
total > 0
? Number((((end.steal - start.steal) / total) * 100).toFixed(2))
: 0,
throttleCount:
start.throttleCount === undefined || end.throttleCount === undefined
? undefined
: end.throttleCount - start.throttleCount
: 0
};
// Leave the key out, the statistics log an error for undefined values
if (start.throttleCount !== undefined && end.throttleCount !== undefined) {
stability.throttleCount = end.throttleCount - start.throttleCount;
}
return stability;
}
7 changes: 3 additions & 4 deletions test/unittests/cpuStabilityTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ test('Give the steal time and throttle events between two samples', t => {
test('Give no throttle events when the CPU does not report them', t => {
const start = { total: 1000, steal: 0, throttleCount: undefined };
const end = { total: 1000, steal: 0, throttleCount: undefined };
t.deepEqual(getCpuStability(start, end), {
stealPercent: 0,
throttleCount: undefined
});
const stability = getCpuStability(start, end);
t.deepEqual(stability, { stealPercent: 0 });
t.false('throttleCount' in stability);
});
Loading