Skip to content

Commit dfd47aa

Browse files
committed
report: make more items programmatically accessible
Prefer structured output over stringified information for libuv handles and the native stack trace. PR-URL: #26019 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
1 parent 23868ba commit dfd47aa

File tree

4 files changed

+132
-75
lines changed

4 files changed

+132
-75
lines changed

doc/api/report.md

+61-18
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,26 @@ is provided below for reference.
7878
]
7979
},
8080
"nativeStack": [
81-
" [pc=0xa7ef87] [/home/nodeuser/project/node/out/Release/node]",
82-
" [pc=0xa81adb] report::TriggerNodeReport(v8::Isolate*, node::Environment*, char const*, char const*, std::string, v8::Local<v8::String>) [/home/nodeuser/project/node/out/Release/node]",
83-
" [pc=0xa834f2] report::OnUncaughtException(v8::FunctionCallbackInfo<v8::Value> const&) [/home/nodeuser/project/node/out/Release/node]",
84-
" [pc=0xbe6b78] [/home/nodeuser/project/node/out/Release/node]",
85-
" [pc=0xbe7596] v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [/home/nodeuser/project/node/out/Release/node]",
86-
" [pc=0x1930cae] [/home/nodeuser/project/node/out/Release/node]"
81+
{
82+
"pc": "0x000055b57f07a9ef",
83+
"symbol": "report::GetNodeReport(v8::Isolate*, node::Environment*, char const*, char const*, v8::Local<v8::String>, std::ostream&) [./node]"
84+
},
85+
{
86+
"pc": "0x000055b57f07cf03",
87+
"symbol": "report::GetReport(v8::FunctionCallbackInfo<v8::Value> const&) [./node]"
88+
},
89+
{
90+
"pc": "0x000055b57f1bccfd",
91+
"symbol": " [./node]"
92+
},
93+
{
94+
"pc": "0x000055b57f1be048",
95+
"symbol": "v8::internal::Builtin_HandleApiCall(int, v8::internal::Object**, v8::internal::Isolate*) [./node]"
96+
},
97+
{
98+
"pc": "0x000055b57feeda0e",
99+
"symbol": " [./node]"
100+
}
87101
],
88102
"javascriptHeap": {
89103
"totalMemory": 6127616,
@@ -175,46 +189,75 @@ is provided below for reference.
175189
"details": ""
176190
},
177191
{
192+
"repeat": 0,
193+
"firesInMsFromNow": 94403548320796,
194+
"expired": true,
178195
"type": "timer",
179196
"is_active": false,
180197
"is_referenced": false,
181-
"address": "0x00007fff5fbfeab0",
182-
"details": "repeat: 0, timeout expired: 18075165916 ms ago"
198+
"address": "0x00007fff5fbfeab0"
183199
},
184200
{
185201
"type": "check",
186202
"is_active": true,
187203
"is_referenced": false,
188-
"address": "0x00007fff5fbfeb48",
189-
"details": ""
204+
"address": "0x00007fff5fbfeb48"
190205
},
191206
{
192207
"type": "idle",
193208
"is_active": false,
194209
"is_referenced": true,
195-
"address": "0x00007fff5fbfebc0",
196-
"details": ""
210+
"address": "0x00007fff5fbfebc0"
197211
},
198212
{
199213
"type": "prepare",
200214
"is_active": false,
201215
"is_referenced": false,
202-
"address": "0x00007fff5fbfec38",
203-
"details": ""
216+
"address": "0x00007fff5fbfec38"
204217
},
205218
{
206219
"type": "check",
207220
"is_active": false,
208221
"is_referenced": false,
209-
"address": "0x00007fff5fbfecb0",
210-
"details": ""
222+
"address": "0x00007fff5fbfecb0"
211223
},
212224
{
213225
"type": "async",
214226
"is_active": true,
215227
"is_referenced": false,
216-
"address": "0x000000010188f2e0",
217-
"details": ""
228+
"address": "0x000000010188f2e0"
229+
},
230+
{
231+
"width": 204,
232+
"height": 55,
233+
"fd": 17,
234+
"writeQueueSize": 0,
235+
"readable": true,
236+
"writable": true,
237+
"type": "tty",
238+
"is_active": false,
239+
"is_referenced": true,
240+
"address": "0x000055b581db0e18"
241+
},
242+
{
243+
"signum": 28,
244+
"signal": "SIGWINCH",
245+
"type": "signal",
246+
"is_active": true,
247+
"is_referenced": false,
248+
"address": "0x000055b581d80010"
249+
},
250+
{
251+
"width": 204,
252+
"height": 55,
253+
"fd": 19,
254+
"writeQueueSize": 0,
255+
"readable": true,
256+
"writable": true,
257+
"type": "tty",
258+
"is_active": true,
259+
"is_referenced": true,
260+
"address": "0x000055b581df59f8"
218261
},
219262
{
220263
"type": "loop",

src/node_report.cc

+7-8
Original file line numberDiff line numberDiff line change
@@ -216,9 +216,8 @@ void GetNodeReport(Isolate* isolate,
216216
// Obtain the current time and the pid (platform dependent)
217217
TIME_TYPE tm_struct;
218218
LocalTime(&tm_struct);
219-
std::string str = "NA";
220219
WriteNodeReport(
221-
isolate, env, message, location, str, out, stackstr, &tm_struct);
220+
isolate, env, message, location, "", out, stackstr, &tm_struct);
222221
}
223222

224223
// Internal function to coordinate and write the various
@@ -249,7 +248,7 @@ static void WriteNodeReport(Isolate* isolate,
249248
if (!filename.empty())
250249
writer.json_keyvalue("filename", filename);
251250
else
252-
writer.json_keyvalue("filename", "''");
251+
writer.json_keyvalue("filename", JSONWriter::Null{});
253252

254253
// Report dump event and module load date/time stamps
255254
char timebuf[64];
@@ -431,13 +430,13 @@ static void PrintNativeStack(JSONWriter* writer) {
431430
const int size = sym_ctx->GetStackTrace(frames, arraysize(frames));
432431
writer->json_arraystart("nativeStack");
433432
int i;
434-
std::ostringstream buf;
435433
for (i = 1; i < size; i++) {
436434
void* frame = frames[i];
437-
buf.str("");
438-
buf << " [pc=" << frame << "] ";
439-
buf << sym_ctx->LookupSymbol(frame).Display().c_str();
440-
writer->json_element(buf.str());
435+
writer->json_start();
436+
writer->json_keyvalue("pc",
437+
ValueToHexString(reinterpret_cast<uintptr_t>(frame)));
438+
writer->json_keyvalue("symbol", sym_ctx->LookupSymbol(frame).Display());
439+
writer->json_end();
441440
}
442441
writer->json_arrayend();
443442
}

src/node_report.h

+3-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ void GetNodeReport(v8::Isolate* isolate,
5454
std::ostream& out);
5555

5656
// Function declarations - utility functions in src/node_report_utils.cc
57-
void ReportEndpoints(uv_handle_t* h, std::ostringstream& out);
5857
void WalkHandle(uv_handle_t* h, void* arg);
5958
std::string EscapeJsonChars(const std::string& str);
6059

@@ -157,6 +156,8 @@ class JSONWriter {
157156
state_ = kAfterValue;
158157
}
159158

159+
struct Null {}; // Usable as a JSON value.
160+
160161
private:
161162
template <typename T,
162163
typename test_for_number = typename std::
@@ -168,6 +169,7 @@ class JSONWriter {
168169
out_ << number;
169170
}
170171

172+
inline void write_value(Null null) { out_ << "null"; }
171173
inline void write_value(const char* str) { write_string(str); }
172174
inline void write_value(const std::string& str) { write_string(str); }
173175

0 commit comments

Comments
 (0)