From b8aa37d529e4bb66d555d03e537f7c26255a2fdd Mon Sep 17 00:00:00 2001 From: wopeizl Date: Tue, 27 Aug 2019 18:51:02 +0800 Subject: [PATCH] =?UTF-8?q?save=20the=20callstack=20information=20to=20fil?= =?UTF-8?q?e=20when=20exception=20throws=20test=3Ddev=E2=80=A6=20(#19324)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * save the callstack information to file when exception throws test=develop --- paddle/fluid/platform/enforce.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/paddle/fluid/platform/enforce.h b/paddle/fluid/platform/enforce.h index 03802f38538..862ea8979ab 100644 --- a/paddle/fluid/platform/enforce.h +++ b/paddle/fluid/platform/enforce.h @@ -26,6 +26,7 @@ limitations under the License. */ #include #endif // PADDLE_WITH_CUDA +#include #include #include #include @@ -82,6 +83,22 @@ struct EnforceNotMet : public std::exception { const char* what() const noexcept override { return err_str_.c_str(); } private: + const std::string output_file_name{"paddle_err_info"}; + void saveErrorInformation(const std::string& err) { + std::stringstream ss; + ss << output_file_name; + std::time_t t = std::time(nullptr); + std::tm* tm = std::localtime(&t); + char mbstr[100]; + std::strftime(mbstr, sizeof(mbstr), "%F-%H-%M-%S", tm); + ss << "_" << mbstr << ".log"; + std::ofstream err_file(ss.str(), std::ofstream::out); + if (err_file.is_open()) { + err_file << err; + err_file.close(); + } + } + template inline void Init(StrType what, const char* f, int l) { static constexpr int TRACE_STACK_LIMIT = 100; @@ -112,6 +129,8 @@ struct EnforceNotMet : public std::exception { sout << "Windows not support stack backtrace yet."; #endif err_str_ = sout.str(); + + saveErrorInformation(err_str_); } }; -- GitLab