From 1d1552d106e118a005c39538bc3a1c87a9c5d804 Mon Sep 17 00:00:00 2001 From: Chen Weihang Date: Fri, 25 Oct 2019 09:55:12 +0800 Subject: [PATCH] Make formatted ENFORCE stack adapt to more situations (#20826) * Make formatted ENFORCE stack adapt to more situations and polish details, test=develop * restore template message position, test=develop --- paddle/fluid/framework/op_call_stack.cc | 12 ++++-------- paddle/fluid/platform/enforce.h | 7 ++++++- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/paddle/fluid/framework/op_call_stack.cc b/paddle/fluid/framework/op_call_stack.cc index db259bf038c..c3c56210b62 100644 --- a/paddle/fluid/framework/op_call_stack.cc +++ b/paddle/fluid/framework/op_call_stack.cc @@ -46,19 +46,15 @@ void InsertCallStackInfo(const std::string &type, const AttributeMap &attrs, } } // Step 2. Insert python traceback into err_str_ - std::size_t found = exception->err_str_.rfind("PaddleCheckError:"); + 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()); - exception->err_str_.insert(found + sout_py_trace.str().length(), - "\n----------------------\nError Message " - "Summary:\n----------------------\n"); } else { exception->err_str_.append(sout_py_trace.str()); } - // Step 3. Construct final call stack - sout << "\n\n--------------------------------------------\n"; - sout << "C++ Call Stacks (More useful to developers):"; - sout << "\n--------------------------------------------\n"; + // Step 3. Construct final call stack & append error op name sout << exception->err_str_; if (callstack) { sout << " [operator < " << type << " > error]"; diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index db01414a8bb..a1dc1718327 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -74,6 +74,9 @@ 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"; #if !defined(_WIN32) void* call_stack[TRACE_STACK_LIMIT]; auto size = backtrace(call_stack, TRACE_STACK_LIMIT); @@ -102,8 +105,10 @@ inline std::string GetTraceBackString(StrType&& what, const char* file, } free(symbols); #else - sout << "Windows not support stack backtrace yet."; + sout << "Windows not support stack backtrace yet.\n"; #endif + sout << "\n----------------------\nError Message " + "Summary:\n----------------------\n"; sout << string::Sprintf("PaddleCheckError: %s at [%s:%d]", std::forward(what), file, line) << std::endl; -- GitLab