未验证 提交 d47304e6 编写于 作者: C Chen Weihang 提交者: GitHub

Refine paddle error stack format (#25790)

* refine error stack format

* polish compile traceback format

* polish detail format
上级 c70f5920
......@@ -35,26 +35,14 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs,
}
std::ostringstream sout;
std::ostringstream sout_py_trace;
// Step 1. Construct python call stack string
if (callstack) {
sout_py_trace << "\n------------------------------------------\n";
sout_py_trace << "Python Call Stacks (More useful to users):";
sout_py_trace << "\n------------------------------------------\n";
sout << "\n\n Compile Traceback (most recent call last):";
for (auto &line : *callstack) {
sout_py_trace << line;
sout << "\n " << line;
}
}
// Step 2. Insert python traceback into err_str_
std::size_t found = exception->err_str_.rfind(
"\n----------------------\nError Message "
"Summary:\n----------------------\n");
if (found != std::string::npos) {
exception->err_str_.insert(found, sout_py_trace.str());
} else {
exception->err_str_.append(sout_py_trace.str());
}
// Step 3. Construct final call stack & append error op name
// Step 2. Construct final call stack & append error op name
sout << exception->err_str_;
sout << " [operator < " << type << " > error]";
exception->err_str_ = sout.str();
......
......@@ -700,7 +700,7 @@ void OpDesc::InferShape(const BlockDesc &block) const {
}
infer_shape(&ctx);
} catch (platform::EnforceNotMet &exception) {
framework::InsertCallStackInfo(Type(), attrs_, &exception);
framework::AppendErrorOpHint(Type(), &exception);
throw std::move(exception);
} catch (...) {
std::rethrow_exception(std::current_exception());
......
......@@ -232,16 +232,16 @@ inline std::string GetTraceBackString(StrType&& what, const char* file,
static constexpr int TRACE_STACK_LIMIT = 100;
std::ostringstream sout;
sout << "\n\n--------------------------------------------\n";
sout << "C++ Call Stacks (More useful to developers):";
sout << "\n--------------------------------------------\n";
sout << "\n\n--------------------------------------\n";
sout << "C++ Traceback (most recent call last):";
sout << "\n--------------------------------------\n";
#if !defined(_WIN32)
void* call_stack[TRACE_STACK_LIMIT];
auto size = backtrace(call_stack, TRACE_STACK_LIMIT);
auto symbols = backtrace_symbols(call_stack, size);
Dl_info info;
int idx = 0;
for (int i = 0; i < size; ++i) {
for (int i = size - 1; i >= 0; --i) {
if (dladdr(call_stack[i], &info) && info.dli_sname) {
auto demangled = demangle(info.dli_sname);
std::string path(info.dli_fname);
......
......@@ -1913,8 +1913,13 @@ class Operator(object):
"`type` to initialized an Operator can not be None.")
else:
callstack_var_name = op_maker.kOpCreationCallstackAttrName()
op_attrs[callstack_var_name] = list(
reversed(traceback.format_stack()))[1:]
op_attrs[callstack_var_name] = []
for frame in traceback.extract_stack():
op_attrs[callstack_var_name].append(
' File "{}", line {}, in {}'.format(frame[0], frame[1],
frame[2]))
op_attrs[callstack_var_name].append(' {}'.format(frame[
3]))
self.desc.set_type(type)
proto = OpProtoHolder.instance().get_op_proto(type)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册