mirror of
https://github.com/zebrajr/node.git
synced 2026-01-15 12:15:26 +00:00
Use the --trace-sync-io flag to print a stack trace whenever a sync method is used after the first tick, excluding during the process exit event. (e.g. fs.readFileSync()) It does not track if the warning has occurred at a specific location in the past and so will print the warning every time. Reason for not printing during the first tick of the appication is so all necessary resources can be required. Also by excluding synchronous calls during exit is necessary in case any data needs to be logged out by the application before it shuts down. Fixes: https://github.com/nodejs/io.js/issues/1674 PR-URL: https://github.com/nodejs/io.js/pull/1707 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Fedor Indutny <fedor@indutny.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Petka Antonov <petka_antonov@hotmail.com>
59 lines
1.5 KiB
C++
59 lines
1.5 KiB
C++
#include "env.h"
|
|
#include "env-inl.h"
|
|
#include "v8.h"
|
|
#include <stdio.h>
|
|
|
|
namespace node {
|
|
|
|
using v8::HandleScope;
|
|
using v8::Local;
|
|
using v8::Message;
|
|
using v8::StackFrame;
|
|
using v8::StackTrace;
|
|
|
|
void Environment::PrintSyncTrace() const {
|
|
if (!trace_sync_io_)
|
|
return;
|
|
|
|
HandleScope handle_scope(isolate());
|
|
Local<v8::StackTrace> stack =
|
|
StackTrace::CurrentStackTrace(isolate(), 10, StackTrace::kDetailed);
|
|
|
|
fprintf(stderr, "WARNING: Detected use of sync API\n");
|
|
|
|
for (int i = 0; i < stack->GetFrameCount() - 1; i++) {
|
|
Local<StackFrame> stack_frame = stack->GetFrame(i);
|
|
node::Utf8Value fn_name_s(isolate(), stack_frame->GetFunctionName());
|
|
node::Utf8Value script_name(isolate(), stack_frame->GetScriptName());
|
|
const int line_number = stack_frame->GetLineNumber();
|
|
const int column = stack_frame->GetColumn();
|
|
|
|
if (stack_frame->IsEval()) {
|
|
if (stack_frame->GetScriptId() == Message::kNoScriptIdInfo) {
|
|
fprintf(stderr, " at [eval]:%i:%i\n", line_number, column);
|
|
} else {
|
|
fprintf(stderr,
|
|
" at [eval] (%s:%i:%i)\n",
|
|
*script_name,
|
|
line_number,
|
|
column);
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (fn_name_s.length() == 0) {
|
|
fprintf(stderr, " at %s:%i:%i\n", *script_name, line_number, column);
|
|
} else {
|
|
fprintf(stderr,
|
|
" at %s (%s:%i:%i)\n",
|
|
*fn_name_s,
|
|
*script_name,
|
|
line_number,
|
|
column);
|
|
}
|
|
}
|
|
fflush(stderr);
|
|
}
|
|
|
|
} // namespace node
|