Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions paddle/fluid/platform/enforce.h
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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();
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

能否明确一下哪些信息被写入文件了,哪些信息仍然保留在屏幕上?另外,好像没有看到给用户的提示信息,去哪个文件找详细信息?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

出错栈的信息都会被保存到文件中

template <typename StrType>
inline void Init(StrType what, const char* f, int l) {
static constexpr int TRACE_STACK_LIMIT = 100;
Expand Down Expand Up @@ -112,6 +129,8 @@ struct EnforceNotMet : public std::exception {
sout << "Windows not support stack backtrace yet.";
#endif
err_str_ = sout.str();

saveErrorInformation(err_str_);
}
};

Expand Down