Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: loop over uv_cpu_info() results #28829

Closed
wants to merge 1 commit into from
Closed
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
14 changes: 7 additions & 7 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,13 @@ static void PrintCpuInfo(JSONWriter* writer) {
writer->json_arraystart("cpus");
for (int i = 0; i < count; i++) {
writer->json_start();
writer->json_keyvalue("model", cpu_info->model);
writer->json_keyvalue("speed", cpu_info->speed);
writer->json_keyvalue("user", cpu_info->cpu_times.user);
writer->json_keyvalue("nice", cpu_info->cpu_times.nice);
writer->json_keyvalue("sys", cpu_info->cpu_times.sys);
writer->json_keyvalue("idle", cpu_info->cpu_times.idle);
writer->json_keyvalue("irq", cpu_info->cpu_times.irq);
writer->json_keyvalue("model", cpu_info[i].model);
writer->json_keyvalue("speed", cpu_info[i].speed);
writer->json_keyvalue("user", cpu_info[i].cpu_times.user);
writer->json_keyvalue("nice", cpu_info[i].cpu_times.nice);
writer->json_keyvalue("sys", cpu_info[i].cpu_times.sys);
writer->json_keyvalue("idle", cpu_info[i].cpu_times.idle);
writer->json_keyvalue("irq", cpu_info[i].cpu_times.irq);
writer->json_end();
}
writer->json_arrayend();
Expand Down
5 changes: 5 additions & 0 deletions test/common/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ const fs = require('fs');
const os = require('os');
const path = require('path');
const util = require('util');
const cpus = os.cpus();

function findReports(pid, dir) {
// Default filenames are of the form
Expand Down Expand Up @@ -98,6 +99,7 @@ function _validateContent(report) {
assert.strictEqual(typeof header.osVersion, 'string');
assert.strictEqual(typeof header.osMachine, 'string');
assert(Array.isArray(header.cpus));
assert.strictEqual(header.cpus.length, cpus.length);
header.cpus.forEach((cpu) => {
assert.strictEqual(typeof cpu.model, 'string');
assert.strictEqual(typeof cpu.speed, 'number');
Expand All @@ -106,6 +108,9 @@ function _validateContent(report) {
assert.strictEqual(typeof cpu.sys, 'number');
assert.strictEqual(typeof cpu.idle, 'number');
assert.strictEqual(typeof cpu.irq, 'number');
assert(cpus.some((c) => {
return c.model === cpu.model && c.speed === cpu.speed;
}));
});
assert.strictEqual(header.host, os.hostname());

Expand Down