未验证 提交 b8aa37d5 编写于 作者: W wopeizl 提交者: GitHub

save the callstack information to file when exception throws test=dev… (#19324)

* save the callstack information to file when exception throws test=develop
上级 3f392fd4
......@@ -26,6 +26,7 @@ limitations under the License. */
#include <thrust/system_error.h>
#endif // PADDLE_WITH_CUDA
#include <fstream>
#include <iomanip>
#include <iostream>
#include <memory>
......@@ -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 <typename StrType>
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_);
}
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册