Skip to content

Commit

Permalink
report: print common items first for readability
Browse files Browse the repository at this point in the history
PR-URL: #27367
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com>
  • Loading branch information
gengjiawen authored and targos committed Apr 27, 2019
1 parent 31ac8b9 commit 38f3526
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 22 deletions.
34 changes: 17 additions & 17 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,13 @@ is provided below for reference.
"details": ""
},
{
"repeat": 0,
"firesInMsFromNow": 94403548320796,
"expired": true,
"type": "timer",
"is_active": false,
"is_referenced": false,
"address": "0x00007fff5fbfeab0"
"address": "0x00007fff5fbfeab0",
"repeat": 0,
"firesInMsFromNow": 94403548320796,
"expired": true
},
{
"type": "check",
Expand Down Expand Up @@ -229,36 +229,36 @@ is provided below for reference.
"address": "0x000000010188f2e0"
},
{
"type": "tty",
"is_active": false,
"is_referenced": true,
"address": "0x000055b581db0e18",
"width": 204,
"height": 55,
"fd": 17,
"writeQueueSize": 0,
"readable": true,
"writable": true,
"type": "tty",
"is_active": false,
"is_referenced": true,
"address": "0x000055b581db0e18"
"writable": true
},
{
"signum": 28,
"signal": "SIGWINCH",
"type": "signal",
"is_active": true,
"is_referenced": false,
"address": "0x000055b581d80010"
"address": "0x000055b581d80010",
"signum": 28,
"signal": "SIGWINCH"
},
{
"type": "tty",
"is_active": true,
"is_referenced": true,
"address": "0x000055b581df59f8",
"width": 204,
"height": 55,
"fd": 19,
"writeQueueSize": 0,
"readable": true,
"writable": true,
"type": "tty",
"is_active": true,
"is_referenced": true,
"address": "0x000055b581df59f8"
"writable": true
},
{
"type": "loop",
Expand Down
10 changes: 5 additions & 5 deletions src/node_report_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ void WalkHandle(uv_handle_t* h, void* arg) {
uv_any_handle* handle = reinterpret_cast<uv_any_handle*>(h);

writer->json_start();
writer->json_keyvalue("type", type);
writer->json_keyvalue("is_active", static_cast<bool>(uv_is_active(h)));
writer->json_keyvalue("is_referenced", static_cast<bool>(uv_has_ref(h)));
writer->json_keyvalue("address",
ValueToHexString(reinterpret_cast<uint64_t>(h)));

switch (h->type) {
case UV_FS_EVENT:
Expand Down Expand Up @@ -216,11 +221,6 @@ void WalkHandle(uv_handle_t* h, void* arg) {
static_cast<bool>(uv_is_writable(&handle->stream)));
}

writer->json_keyvalue("type", type);
writer->json_keyvalue("is_active", static_cast<bool>(uv_is_active(h)));
writer->json_keyvalue("is_referenced", static_cast<bool>(uv_has_ref(h)));
writer->json_keyvalue("address",
ValueToHexString(reinterpret_cast<uint64_t>(h)));
writer->json_end();
}

Expand Down
16 changes: 16 additions & 0 deletions test/report/test-report-uv-handles.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,22 @@ if (process.argv[2] === 'child') {
const reports = helper.findReports(child.pid, tmpdir.path);
assert.deepStrictEqual(reports, [], report_msg, reports);

// Test libuv handle key order
{
const get_libuv = /"libuv":\s\[([\s\S]*?)\]/gm;
const get_handle_inner = /{([\s\S]*?),*?}/gm;
const libuv_handles_str = get_libuv.exec(stdout)[1];
const libuv_handles_array = libuv_handles_str.match(get_handle_inner);
for (const i of libuv_handles_array) {
// Exclude nested structure
if (i.includes('type')) {
const handle_keys = i.match(/(".*"):/gm);
assert(handle_keys[0], 'type');
assert(handle_keys[1], 'is_active');
}
}
}

const report = JSON.parse(stdout);
const prefix = common.isWindows ? '\\\\?\\' : '';
const expected_filename = `${prefix}${__filename}`;
Expand Down

0 comments on commit 38f3526

Please sign in to comment.