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

report: add cpu info to report output #28188

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
20 changes: 20 additions & 0 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
boneskull marked this conversation as resolved.
Show resolved Hide resolved
{
"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": {
Expand Down
25 changes: 25 additions & 0 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -315,13 +316,37 @@ static void PrintVersionInformation(JSONWriter* writer) {
writer->json_keyvalue("osMachine", os_info.machine);
}

PrintCpuInfo(writer);

char host[UV_MAXHOSTNAMESIZE];
size_t host_size = sizeof(host);

if (uv_os_gethostname(host, &host_size) == 0)
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,
Expand Down
14 changes: 12 additions & 2 deletions test/common/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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.
Expand Down