report: add cpu info to report output · nodejs/node@6821055 · GitHub
Skip to content

Commit 6821055

Browse files
boneskullBridgeAR
authored andcommitted
report: add cpu info to report output
The report shows CPU consumption %, but without the number of CPU cores, a consumer cannot tell if the percent (given across all cores) is actually problematic. E.g., 100% on one CPU is a problem, but 100% on four CPUs is not necessarily. This change adds CPU information (similar to `os.cpus()`) to the report output. Extra info besides the count is also provided as to avoid future breaking changes in the eventuality that someone needs it; changing the datatype of `header.cpus` would be breaking. PR-URL: #28188 Refs: nodejs/diagnostics#307 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent ae7789a commit 6821055

3 files changed

Lines changed: 57 additions & 2 deletions

File tree

doc/api/report.md

Lines changed: 20 additions & 0 deletions

src/node_report.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ static void PrintSystemInformation(JSONWriter* writer);
6565
static void PrintLoadedLibraries(JSONWriter* writer);
6666
static void PrintComponentVersions(JSONWriter* writer);
6767
static void PrintRelease(JSONWriter* writer);
68+
static void PrintCpuInfo(JSONWriter* writer);
6869

6970
// External function to trigger a report, writing to file.
7071
// The 'name' parameter is in/out: an input filename is used
@@ -315,13 +316,37 @@ static void PrintVersionInformation(JSONWriter* writer) {
315316
writer->json_keyvalue("osMachine", os_info.machine);
316317
}
317318

319+
PrintCpuInfo(writer);
320+
318321
char host[UV_MAXHOSTNAMESIZE];
319322
size_t host_size = sizeof(host);
320323

321324
if (uv_os_gethostname(host, &host_size) == 0)
322325
writer->json_keyvalue("host", host);
323326
}
324327

328+
// Report CPU info
329+
static void PrintCpuInfo(JSONWriter* writer) {
330+
uv_cpu_info_t* cpu_info;
331+
int count;
332+
if (uv_cpu_info(&cpu_info, &count) == 0) {
333+
writer->json_arraystart("cpus");
334+
for (int i = 0; i < count; i++) {
335+
writer->json_start();
336+
writer->json_keyvalue("model", cpu_info->model);
337+
writer->json_keyvalue("speed", cpu_info->speed);
338+
writer->json_keyvalue("user", cpu_info->cpu_times.user);
339+
writer->json_keyvalue("nice", cpu_info->cpu_times.nice);
340+
writer->json_keyvalue("sys", cpu_info->cpu_times.sys);
341+
writer->json_keyvalue("idle", cpu_info->cpu_times.idle);
342+
writer->json_keyvalue("irq", cpu_info->cpu_times.irq);
343+
writer->json_end();
344+
}
345+
writer->json_arrayend();
346+
uv_free_cpu_info(cpu_info, count);
347+
}
348+
}
349+
325350
// Report the JavaScript stack.
326351
static void PrintJavaScriptStack(JSONWriter* writer,
327352
Isolate* isolate,

test/common/report.js

Lines changed: 12 additions & 2 deletions

0 commit comments

Comments
 (0)