Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 6821055

Browse filesBrowse 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
Copy full SHA for 6821055

File tree

Expand file treeCollapse file tree

3 files changed

+57
-2
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+57
-2
lines changed
Open diff view settings
Collapse file

‎doc/api/report.md‎

Copy file name to clipboardExpand all lines: doc/api/report.md
+20Lines changed: 20 additions & 0 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ is provided below for reference.
6262
"osRelease": "3.10.0-862.el7.x86_64",
6363
"osVersion": "#1 SMP Wed Mar 21 18:14:51 EDT 2018",
6464
"osMachine": "x86_64",
65+
"osCpus": [
66+
{
67+
"model": "Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz",
68+
"speed": 2700,
69+
"user": 88902660,
70+
"nice": 0,
71+
"sys": 50902570,
72+
"idle": 241732220,
73+
"irq": 0
74+
},
75+
{
76+
"model": "Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz",
77+
"speed": 2700,
78+
"user": 88902660,
79+
"nice": 0,
80+
"sys": 50902570,
81+
"idle": 241732220,
82+
"irq": 0
83+
}
84+
],
6585
"host": "test_machine"
6686
},
6787
"javascriptStack": {
Collapse file

‎src/node_report.cc‎

Copy file name to clipboardExpand all lines: src/node_report.cc
+25Lines 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,
Collapse file

‎test/common/report.js‎

Copy file name to clipboardExpand all lines: test/common/report.js
+12-2Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ function _validateContent(data) {
6262
'dumpEventTimeStamp', 'processId', 'commandLine',
6363
'nodejsVersion', 'wordSize', 'arch', 'platform',
6464
'componentVersions', 'release', 'osName', 'osRelease',
65-
'osVersion', 'osMachine', 'host', 'glibcVersionRuntime',
66-
'glibcVersionCompiler', 'cwd'];
65+
'osVersion', 'osMachine', 'cpus', 'host',
66+
'glibcVersionRuntime', 'glibcVersionCompiler', 'cwd'];
6767
checkForUnknownFields(header, headerFields);
6868
assert.strictEqual(typeof header.event, 'string');
6969
assert.strictEqual(typeof header.trigger, 'string');
@@ -87,6 +87,16 @@ function _validateContent(data) {
8787
assert.strictEqual(header.osRelease, os.release());
8888
assert.strictEqual(typeof header.osVersion, 'string');
8989
assert.strictEqual(typeof header.osMachine, 'string');
90+
assert(Array.isArray(header.cpus));
91+
header.cpus.forEach((cpu) => {
92+
assert.strictEqual(typeof cpu.model, 'string');
93+
assert.strictEqual(typeof cpu.speed, 'number');
94+
assert.strictEqual(typeof cpu.user, 'number');
95+
assert.strictEqual(typeof cpu.nice, 'number');
96+
assert.strictEqual(typeof cpu.sys, 'number');
97+
assert.strictEqual(typeof cpu.idle, 'number');
98+
assert.strictEqual(typeof cpu.irq, 'number');
99+
});
90100
assert.strictEqual(header.host, os.hostname());
91101

92102
// Verify the format of the javascriptStack section.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.