Skip to content

Commit 30a4e89

Browse files
cjihrigaddaleax
authored andcommittedFeb 6, 2019
report: print libuv handle addresses as hex
PR-URL: #25910 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent c959d60 commit 30a4e89

File tree

3 files changed

+20
-9
lines changed

3 files changed

+20
-9
lines changed
 

‎doc/api/report.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -171,49 +171,49 @@ is provided below for reference.
171171
"type": "async",
172172
"is_active": true,
173173
"is_referenced": false,
174-
"address": "68090592",
174+
"address": "0x0000000102910900",
175175
"details": ""
176176
},
177177
{
178178
"type": "timer",
179179
"is_active": false,
180180
"is_referenced": false,
181-
"address": "140723513949920",
181+
"address": "0x00007fff5fbfeab0",
182182
"details": "repeat: 0, timeout expired: 18075165916 ms ago"
183183
},
184184
{
185185
"type": "check",
186186
"is_active": true,
187187
"is_referenced": false,
188-
"address": "140723513950072",
188+
"address": "0x00007fff5fbfeb48",
189189
"details": ""
190190
},
191191
{
192192
"type": "idle",
193193
"is_active": false,
194194
"is_referenced": true,
195-
"address": "140723513950192",
195+
"address": "0x00007fff5fbfebc0",
196196
"details": ""
197197
},
198198
{
199199
"type": "prepare",
200200
"is_active": false,
201201
"is_referenced": false,
202-
"address": "140723513950312",
202+
"address": "0x00007fff5fbfec38",
203203
"details": ""
204204
},
205205
{
206206
"type": "check",
207207
"is_active": false,
208208
"is_referenced": false,
209-
"address": "140723513950432",
209+
"address": "0x00007fff5fbfecb0",
210210
"details": ""
211211
},
212212
{
213213
"type": "async",
214214
"is_active": true,
215215
"is_referenced": false,
216-
"address": "39353856",
216+
"address": "0x000000010188f2e0",
217217
"details": ""
218218
}
219219
],

‎src/node_report.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ void GetNodeReport(v8::Isolate* isolate,
5353
v8::Local<v8::String> stackstr,
5454
std::ostream& out);
5555

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

6163
// Function declarations - export functions in src/node_report_module.cc
6264
void TriggerReport(const v8::FunctionCallbackInfo<v8::Value>& info);

‎src/node_report_utils.cc

+10-1
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,20 @@ void WalkHandle(uv_handle_t* h, void* arg) {
209209
writer->json_keyvalue("is_active", static_cast<bool>(uv_is_active(h)));
210210
writer->json_keyvalue("is_referenced", static_cast<bool>(uv_has_ref(h)));
211211
writer->json_keyvalue("address",
212-
std::to_string(reinterpret_cast<int64_t>(h)));
212+
ValueToHexString(reinterpret_cast<uint64_t>(h)));
213213
writer->json_keyvalue("details", data.str());
214214
writer->json_end();
215215
}
216216

217+
template <typename T>
218+
std::string ValueToHexString(T value) {
219+
std::stringstream hex;
220+
221+
hex << "0x" << std::setfill('0') << std::setw(sizeof(T) * 2) << std::hex <<
222+
value;
223+
return hex.str();
224+
}
225+
217226
std::string EscapeJsonChars(const std::string& str) {
218227
const std::string control_symbols[0x20] = {
219228
"\\u0000", "\\u0001", "\\u0002", "\\u0003", "\\u0004", "\\u0005",

0 commit comments

Comments
 (0)
Please sign in to comment.