Skip to content

Commit

Permalink
report: print libuv handle addresses as hex
Browse files Browse the repository at this point in the history
PR-URL: #25910
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: Richard Lau <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
cjihrig authored and addaleax committed Feb 6, 2019
1 parent c959d60 commit 30a4e89
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 9 deletions.
14 changes: 7 additions & 7 deletions doc/api/report.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,49 +171,49 @@ is provided below for reference.
"type": "async",
"is_active": true,
"is_referenced": false,
"address": "68090592",
"address": "0x0000000102910900",
"details": ""
},
{
"type": "timer",
"is_active": false,
"is_referenced": false,
"address": "140723513949920",
"address": "0x00007fff5fbfeab0",
"details": "repeat: 0, timeout expired: 18075165916 ms ago"
},
{
"type": "check",
"is_active": true,
"is_referenced": false,
"address": "140723513950072",
"address": "0x00007fff5fbfeb48",
"details": ""
},
{
"type": "idle",
"is_active": false,
"is_referenced": true,
"address": "140723513950192",
"address": "0x00007fff5fbfebc0",
"details": ""
},
{
"type": "prepare",
"is_active": false,
"is_referenced": false,
"address": "140723513950312",
"address": "0x00007fff5fbfec38",
"details": ""
},
{
"type": "check",
"is_active": false,
"is_referenced": false,
"address": "140723513950432",
"address": "0x00007fff5fbfecb0",
"details": ""
},
{
"type": "async",
"is_active": true,
"is_referenced": false,
"address": "39353856",
"address": "0x000000010188f2e0",
"details": ""
}
],
Expand Down
4 changes: 3 additions & 1 deletion src/node_report.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,12 @@ void GetNodeReport(v8::Isolate* isolate,
v8::Local<v8::String> stackstr,
std::ostream& out);

// Function declarations - utility functions in src/utilities.cc
// Function declarations - utility functions in src/node_report_utils.cc
void ReportEndpoints(uv_handle_t* h, std::ostringstream& out);
void WalkHandle(uv_handle_t* h, void* arg);
std::string EscapeJsonChars(const std::string& str);
template <typename T>
std::string ValueToHexString(T value);

// Function declarations - export functions in src/node_report_module.cc
void TriggerReport(const v8::FunctionCallbackInfo<v8::Value>& info);
Expand Down
11 changes: 10 additions & 1 deletion src/node_report_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,20 @@ void WalkHandle(uv_handle_t* h, void* arg) {
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",
std::to_string(reinterpret_cast<int64_t>(h)));
ValueToHexString(reinterpret_cast<uint64_t>(h)));
writer->json_keyvalue("details", data.str());
writer->json_end();
}

template <typename T>
std::string ValueToHexString(T value) {
std::stringstream hex;

hex << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex <<
value;
return hex.str();
}

std::string EscapeJsonChars(const std::string& str) {
const std::string control_symbols[0x20] = {
"\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005",
Expand Down

0 comments on commit 30a4e89

Please sign in to comment.