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 rss and use/kernel cpu usage fields #45043

Merged
merged 1 commit into from
Oct 24, 2022
Merged
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
19 changes: 12 additions & 7 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,10 +198,13 @@ is provided below for reference.
}
},
"resourceUsage": {
"userCpuSeconds": 0.069595,
"kernelCpuSeconds": 0.019163,
"cpuConsumptionPercent": 0.000000,
"maxRss": 18079744,
"rss": 45768704,
"userCpuSeconds": 0.040072,
"kernelCpuSeconds": 0.016029,
"cpuConsumptionPercent": 5.6101,
"userCpuConsumptionPercent": 4.0072,
"kernelCpuConsumptionPercent": 1.6029,
"maxRss": 45768704,
"pageFaults": {
"IORequired": 0,
"IONotRequired": 4610
Expand All @@ -212,9 +215,11 @@ is provided below for reference.
}
},
"uvthreadResourceUsage": {
"userCpuSeconds": 0.068457,
"kernelCpuSeconds": 0.019127,
"cpuConsumptionPercent": 0.000000,
"userCpuSeconds": 0.039843,
"kernelCpuSeconds": 0.015937,
"cpuConsumptionPercent": 5.578,
"userCpuConsumptionPercent": 3.9843,
"kernelCpuConsumptionPercent": 1.5937,
"fsActivity": {
"reads": 0,
"writes": 0
Expand Down
15 changes: 15 additions & 0 deletions src/node_report.cc
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ static void PrintResourceUsage(JSONWriter* writer) {
// Process and current thread usage statistics
uv_rusage_t rusage;
writer->json_objectstart("resourceUsage");

size_t rss;
int err = uv_resident_set_memory(&rss);
if (!err) {
writer->json_keyvalue("rss", rss);
}

if (uv_getrusage(&rusage) == 0) {
double user_cpu =
rusage.ru_utime.tv_sec + SEC_PER_MICROS * rusage.ru_utime.tv_usec;
Expand All @@ -636,7 +643,11 @@ static void PrintResourceUsage(JSONWriter* writer) {
writer->json_keyvalue("kernelCpuSeconds", kernel_cpu);
double cpu_abs = user_cpu + kernel_cpu;
double cpu_percentage = (cpu_abs / uptime) * 100.0;
double user_cpu_percentage = (user_cpu / uptime) * 100.0;
double kernel_cpu_percentage = (kernel_cpu / uptime) * 100.0;
writer->json_keyvalue("cpuConsumptionPercent", cpu_percentage);
writer->json_keyvalue("userCpuConsumptionPercent", user_cpu_percentage);
writer->json_keyvalue("kernelCpuConsumptionPercent", kernel_cpu_percentage);
writer->json_keyvalue("maxRss", rusage.ru_maxrss * 1024);
writer->json_objectstart("pageFaults");
writer->json_keyvalue("IORequired", rusage.ru_majflt);
Expand All @@ -660,7 +671,11 @@ static void PrintResourceUsage(JSONWriter* writer) {
writer->json_keyvalue("kernelCpuSeconds", kernel_cpu);
double cpu_abs = user_cpu + kernel_cpu;
double cpu_percentage = (cpu_abs / uptime) * 100.0;
double user_cpu_percentage = (user_cpu / uptime) * 100.0;
double kernel_cpu_percentage = (kernel_cpu / uptime) * 100.0;
writer->json_keyvalue("cpuConsumptionPercent", cpu_percentage);
writer->json_keyvalue("userCpuConsumptionPercent", user_cpu_percentage);
writer->json_keyvalue("kernelCpuConsumptionPercent", kernel_cpu_percentage);
writer->json_objectstart("fsActivity");
writer->json_keyvalue("reads", stats.ru_inblock);
writer->json_keyvalue("writes", stats.ru_oublock);
Expand Down
12 changes: 10 additions & 2 deletions test/common/report.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,12 +234,16 @@ function _validateContent(report, fields = []) {
// Verify the format of the resourceUsage section.
const usage = report.resourceUsage;
const resourceUsageFields = ['userCpuSeconds', 'kernelCpuSeconds',
'cpuConsumptionPercent', 'maxRss',
'cpuConsumptionPercent', 'userCpuConsumptionPercent',
'kernelCpuConsumptionPercent', 'rss', 'maxRss',
'pageFaults', 'fsActivity'];
checkForUnknownFields(usage, resourceUsageFields);
assert.strictEqual(typeof usage.userCpuSeconds, 'number');
assert.strictEqual(typeof usage.kernelCpuSeconds, 'number');
assert.strictEqual(typeof usage.cpuConsumptionPercent, 'number');
assert.strictEqual(typeof usage.userCpuConsumptionPercent, 'number');
assert.strictEqual(typeof usage.kernelCpuConsumptionPercent, 'number');
assert(Number.isSafeInteger(usage.rss));
assert(Number.isSafeInteger(usage.maxRss));
assert(typeof usage.pageFaults === 'object' && usage.pageFaults !== null);
checkForUnknownFields(usage.pageFaults, ['IORequired', 'IONotRequired']);
Expand All @@ -254,11 +258,15 @@ function _validateContent(report, fields = []) {
if (report.uvthreadResourceUsage) {
const usage = report.uvthreadResourceUsage;
const threadUsageFields = ['userCpuSeconds', 'kernelCpuSeconds',
'cpuConsumptionPercent', 'fsActivity'];
'cpuConsumptionPercent', 'fsActivity',
'userCpuConsumptionPercent',
'kernelCpuConsumptionPercent'];
checkForUnknownFields(usage, threadUsageFields);
assert.strictEqual(typeof usage.userCpuSeconds, 'number');
assert.strictEqual(typeof usage.kernelCpuSeconds, 'number');
assert.strictEqual(typeof usage.cpuConsumptionPercent, 'number');
assert.strictEqual(typeof usage.userCpuConsumptionPercent, 'number');
assert.strictEqual(typeof usage.kernelCpuConsumptionPercent, 'number');
assert(typeof usage.fsActivity === 'object' && usage.fsActivity !== null);
checkForUnknownFields(usage.fsActivity, ['reads', 'writes']);
assert(Number.isSafeInteger(usage.fsActivity.reads));
Expand Down