summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristopher Hiller <boneskull@boneskull.com>2019-06-12 07:51:15 -0700
committerRich Trott <rtrott@gmail.com>2019-06-15 20:53:07 -0700
commit7561a38ccd7cc6b543a81a62fdbd455f600f684e (patch)
treeca1cadfc5c72b4288183d9f2dea3ef8cadf88c35
parent9939762322de29224fcbc2f08c4a6a4bc08d6ccd (diff)
downloadandroid-node-v8-7561a38ccd7cc6b543a81a62fdbd455f600f684e.tar.gz
android-node-v8-7561a38ccd7cc6b543a81a62fdbd455f600f684e.tar.bz2
android-node-v8-7561a38ccd7cc6b543a81a62fdbd455f600f684e.zip
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: https://github.com/nodejs/node/pull/28188 Refs: https://github.com/nodejs/diagnostics/issues/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>
-rw-r--r--doc/api/report.md20
-rw-r--r--src/node_report.cc25
-rw-r--r--test/common/report.js14
3 files changed, 57 insertions, 2 deletions
diff --git a/doc/api/report.md b/doc/api/report.md
index 40e3050ee4..9d773f25ee 100644
--- a/doc/api/report.md
+++ b/doc/api/report.md
@@ -62,6 +62,26 @@ is provided below for reference.
"osRelease": "3.10.0-862.el7.x86_64",
"osVersion": "#1 SMP Wed Mar 21 18:14:51 EDT 2018",
"osMachine": "x86_64",
+ "osCpus": [
+ {
+ "model": "Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz",
+ "speed": 2700,
+ "user": 88902660,
+ "nice": 0,
+ "sys": 50902570,
+ "idle": 241732220,
+ "irq": 0
+ },
+ {
+ "model": "Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz",
+ "speed": 2700,
+ "user": 88902660,
+ "nice": 0,
+ "sys": 50902570,
+ "idle": 241732220,
+ "irq": 0
+ }
+ ],
"host": "test_machine"
},
"javascriptStack": {
diff --git a/src/node_report.cc b/src/node_report.cc
index 1860765625..b448ffd099 100644
--- a/src/node_report.cc
+++ b/src/node_report.cc
@@ -65,6 +65,7 @@ static void PrintSystemInformation(JSONWriter* writer);
static void PrintLoadedLibraries(JSONWriter* writer);
static void PrintComponentVersions(JSONWriter* writer);
static void PrintRelease(JSONWriter* writer);
+static void PrintCpuInfo(JSONWriter* writer);
// External function to trigger a report, writing to file.
// The 'name' parameter is in/out: an input filename is used
@@ -315,6 +316,8 @@ static void PrintVersionInformation(JSONWriter* writer) {
writer->json_keyvalue("osMachine", os_info.machine);
}
+ PrintCpuInfo(writer);
+
char host[UV_MAXHOSTNAMESIZE];
size_t host_size = sizeof(host);
@@ -322,6 +325,28 @@ static void PrintVersionInformation(JSONWriter* writer) {
writer->json_keyvalue("host", host);
}
+// Report CPU info
+static void PrintCpuInfo(JSONWriter* writer) {
+ uv_cpu_info_t* cpu_info;
+ int count;
+ if (uv_cpu_info(&cpu_info, &count) == 0) {
+ 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_end();
+ }
+ writer->json_arrayend();
+ uv_free_cpu_info(cpu_info, count);
+ }
+}
+
// Report the JavaScript stack.
static void PrintJavaScriptStack(JSONWriter* writer,
Isolate* isolate,
diff --git a/test/common/report.js b/test/common/report.js
index 163daf286e..f415b66dcc 100644
--- a/test/common/report.js
+++ b/test/common/report.js
@@ -62,8 +62,8 @@ function _validateContent(data) {
'dumpEventTimeStamp', 'processId', 'commandLine',
'nodejsVersion', 'wordSize', 'arch', 'platform',
'componentVersions', 'release', 'osName', 'osRelease',
- 'osVersion', 'osMachine', 'host', 'glibcVersionRuntime',
- 'glibcVersionCompiler', 'cwd'];
+ 'osVersion', 'osMachine', 'cpus', 'host',
+ 'glibcVersionRuntime', 'glibcVersionCompiler', 'cwd'];
checkForUnknownFields(header, headerFields);
assert.strictEqual(typeof header.event, 'string');
assert.strictEqual(typeof header.trigger, 'string');
@@ -87,6 +87,16 @@ function _validateContent(data) {
assert.strictEqual(header.osRelease, os.release());
assert.strictEqual(typeof header.osVersion, 'string');
assert.strictEqual(typeof header.osMachine, 'string');
+ assert(Array.isArray(header.cpus));
+ header.cpus.forEach((cpu) => {
+ assert.strictEqual(typeof cpu.model, 'string');
+ assert.strictEqual(typeof cpu.speed, 'number');
+ assert.strictEqual(typeof cpu.user, 'number');
+ assert.strictEqual(typeof cpu.nice, 'number');
+ assert.strictEqual(typeof cpu.sys, 'number');
+ assert.strictEqual(typeof cpu.idle, 'number');
+ assert.strictEqual(typeof cpu.irq, 'number');
+ });
assert.strictEqual(header.host, os.hostname());
// Verify the format of the javascriptStack section.