Skip to content

Commit

Permalink
report: loop over uv_cpu_info() results
Browse files Browse the repository at this point in the history
The code currently loops over the results, but only the
first result is accessed.

PR-URL: #28829
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
cjihrig authored and Trott committed Jul 26, 2019
1 parent 306d240 commit 48e13d2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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

0 comments on commit 48e13d2

Please sign in to comment.