mirror of
https://github.com/wassname/ray.git
synced 2026-07-30 12:30:30 +08:00
[Log] dump stacktrace from glog lib (#11360)
* dump stacktrace from glog lib * fix windows compile * add comments for getcallstack
This commit is contained in:
@@ -47,6 +47,14 @@
|
||||
|
||||
namespace ray {
|
||||
|
||||
std::string GetCallTrace() {
|
||||
std::string return_message = "Cannot get callstack information.";
|
||||
#ifdef RAY_USE_GLOG
|
||||
return google::GetStackTraceToString();
|
||||
#endif
|
||||
return return_message;
|
||||
}
|
||||
|
||||
#ifdef RAY_USE_GLOG
|
||||
struct StdoutLogger : public google::base::Logger {
|
||||
std::ostream &out() { return std::cout; }
|
||||
|
||||
@@ -43,6 +43,11 @@ enum { ERROR = 0 };
|
||||
#endif
|
||||
|
||||
namespace ray {
|
||||
/// In order to use the get stacktrace method in other non-glog scenarios, we
|
||||
/// have added a patch to allow glog to return the current call stack information
|
||||
/// through the internal interface. This function `GetCallTrace` is a wrapper
|
||||
/// providing a new detection function for debug or something like that.
|
||||
std::string GetCallTrace();
|
||||
|
||||
enum class RayLogLevel { DEBUG = -1, INFO = 0, WARNING = 1, ERROR = 2, FATAL = 3 };
|
||||
|
||||
|
||||
@@ -97,6 +97,31 @@ TEST(LogPerfTest, PerfTest) {
|
||||
RayLog::ShutDownRayLog();
|
||||
}
|
||||
|
||||
std::string TestFunctionLevel0() {
|
||||
std::string call_trace = GetCallTrace();
|
||||
RAY_LOG(INFO) << "TestFunctionLevel0\n" << call_trace;
|
||||
return call_trace;
|
||||
}
|
||||
|
||||
std::string TestFunctionLevel1() {
|
||||
RAY_LOG(INFO) << "TestFunctionLevel1:";
|
||||
return TestFunctionLevel0();
|
||||
}
|
||||
|
||||
std::string TestFunctionLevel2() {
|
||||
RAY_LOG(INFO) << "TestFunctionLevel2:";
|
||||
return TestFunctionLevel1();
|
||||
}
|
||||
|
||||
TEST(PrintLogTest, CallstackTraceTest) {
|
||||
auto ret0 = TestFunctionLevel0();
|
||||
EXPECT_TRUE(ret0.find("TestFunctionLevel0") != std::string::npos);
|
||||
auto ret1 = TestFunctionLevel1();
|
||||
EXPECT_TRUE(ret1.find("TestFunctionLevel1") != std::string::npos);
|
||||
auto ret2 = TestFunctionLevel2();
|
||||
EXPECT_TRUE(ret2.find("TestFunctionLevel2") != std::string::npos);
|
||||
}
|
||||
|
||||
} // namespace ray
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
|
||||
Reference in New Issue
Block a user