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

refine init signal handler meg dumper (#25911)

上级 ff717d51
......@@ -58,7 +58,6 @@ namespace framework {
std::once_flag gflags_init_flag;
std::once_flag glog_init_flag;
std::once_flag p2p_init_flag;
std::once_flag glog_warning_once_flag;
bool InitGflags(std::vector<std::string> args) {
bool successed = false;
......@@ -260,22 +259,22 @@ const char *ParseSignalErrorString(const std::string &str) {
}
// Handle SIGSEGV, SIGILL, SIGFPE, SIGABRT, SIGBUS, and SIGTERM.
std::ostringstream signal_msg_dumper;
void SignalHandle(const char *data, int size) {
try {
// NOTE1: The glog FailureSignalHandler dumped messages
// are deal with line by line
auto signal_msg_dunmer_ptr = SignalMessageDumper::Instance().Get();
// NOTE2: we only deal with the time info ane signal info,
// the stack trace will generated by paddle self
if (StartsWith(data, "*** Aborted at")) {
signal_msg_dumper << " [TimeInfo: " << std::string(data, size - 1)
<< "]\n";
*signal_msg_dunmer_ptr << " [TimeInfo: " << std::string(data, size - 1)
<< "]\n";
} else if (StartsWith(data, "***")) {
std::string signal_info(data, size - 1);
std::string useless_substr("; stack trace:");
size_t start_pos = signal_info.rfind(useless_substr);
signal_info.replace(start_pos, useless_substr.length(), "");
signal_msg_dumper << " [SignalInfo: " << signal_info << "]\n";
*signal_msg_dunmer_ptr << " [SignalInfo: " << signal_info << "]\n";
// NOTE3: Here does not throw an exception,
// otherwise it will casue "terminate called recursively"
auto exp = platform::EnforceNotMet(
......@@ -283,7 +282,7 @@ void SignalHandle(const char *data, int size) {
"A serious error (%s) is detected by the operating system.",
ParseSignalErrorString(signal_info)),
__FILE__, __LINE__);
std::cout << exp.what() << signal_msg_dumper.str() << std::endl;
std::cout << exp.what() << (*signal_msg_dunmer_ptr).str() << std::endl;
}
} catch (...) {
// Since the program has already triggered a system error,
......
......@@ -12,6 +12,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License. */
#pragma once
#include <memory>
#include <mutex> // NOLINT
#include <string>
#include <vector>
......@@ -22,7 +23,7 @@ limitations under the License. */
namespace paddle {
namespace platform {
void ParseCommandLineFlags(int argc, char **argv, bool remove);
void ParseCommandLineFlags(int argc, char** argv, bool remove);
} // namespace platform
} // namespace paddle
......@@ -32,14 +33,32 @@ namespace framework {
bool InitGflags(std::vector<std::string> argv);
void InitGLOG(const std::string &prog_name);
void InitGLOG(const std::string& prog_name);
void InitDevices(bool init_p2p);
void InitDevices(bool init_p2p, const std::vector<int> devices);
#ifndef _WIN32
void SignalHandle(const char *data, int size);
class SignalMessageDumper {
public:
~SignalMessageDumper() {}
SignalMessageDumper(const SignalMessageDumper& o) = delete;
const SignalMessageDumper& operator=(const SignalMessageDumper& o) = delete;
static SignalMessageDumper& Instance() {
static SignalMessageDumper instance;
return instance;
}
std::shared_ptr<std::ostringstream> Get() { return dumper_; }
private:
SignalMessageDumper() : dumper_(new std::ostringstream()) {}
std::shared_ptr<std::ostringstream> dumper_;
};
void SignalHandle(const char* data, int size);
#endif
} // namespace framework
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册