diff --git a/be/CMakeLists.txt b/be/CMakeLists.txt index 51cf86fe4083cf..e7d0849c5ff7ae 100644 --- a/be/CMakeLists.txt +++ b/be/CMakeLists.txt @@ -358,10 +358,6 @@ if (USE_UNWIND) endif() endif() -if (ENABLE_STACKTRACE) - add_definitions(-DENABLE_STACKTRACE) -endif() - if (USE_DWARF) add_compile_options(-gdwarf-5) endif() diff --git a/be/src/common/config.cpp b/be/src/common/config.cpp index 28c19df70bcb80..3c372c7dec19e5 100644 --- a/be/src/common/config.cpp +++ b/be/src/common/config.cpp @@ -135,6 +135,8 @@ DEFINE_mBool(enable_query_memory_overcommit, "true"); DEFINE_mBool(disable_memory_gc, "false"); +DEFINE_mBool(enable_stacktrace, "true"); + DEFINE_mBool(enable_stacktrace_in_allocator_check_failed, "false"); DEFINE_mInt64(large_memory_check_bytes, "2147483648"); diff --git a/be/src/common/config.h b/be/src/common/config.h index dd44f56fd300a9..71acd116ac71b9 100644 --- a/be/src/common/config.h +++ b/be/src/common/config.h @@ -183,6 +183,9 @@ DECLARE_mBool(enable_query_memory_overcommit); // default gc strategy is conservative, if you want to exclude the interference of gc, let it be true DECLARE_mBool(disable_memory_gc); +// if false, turn off all stacktrace +DECLARE_mBool(enable_stacktrace); + // Allocator check failed log stacktrace if not catch exception DECLARE_mBool(enable_stacktrace_in_allocator_check_failed); diff --git a/be/src/common/status.h b/be/src/common/status.h index c7b815e6b4e03f..11c7c42ac99496 100644 --- a/be/src/common/status.h +++ b/be/src/common/status.h @@ -17,11 +17,9 @@ #include #include "common/compiler_util.h" // IWYU pragma: keep -#ifdef ENABLE_STACKTRACE -#include "util/stack_util.h" -#endif - +#include "common/config.h" #include "common/expected.h" +#include "util/stack_util.h" namespace doris { @@ -363,9 +361,9 @@ class [[nodiscard]] Status { Status(int code, std::string msg, std::string stack = "") : _code(code) { _err_msg = std::make_unique(); _err_msg->_msg = std::move(msg); -#ifdef ENABLE_STACKTRACE - _err_msg->_stack = std::move(stack); -#endif + if (config::enable_stacktrace) { + _err_msg->_stack = std::move(stack); + } } // copy c'tor makes copy of error detail so Status can be returned by value @@ -416,13 +414,12 @@ class [[nodiscard]] Status { } else { status._err_msg->_msg = fmt::format(msg, std::forward(args)...); } -#ifdef ENABLE_STACKTRACE - if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) { + if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace && + config::enable_stacktrace) { // Delete the first one frame pointers, which are inside the status.h status._err_msg->_stack = get_stack_trace(1); LOG(WARNING) << "meet error status: " << status; // may print too many stacks. } -#endif return status; } @@ -436,12 +433,11 @@ class [[nodiscard]] Status { } else { status._err_msg->_msg = fmt::format(msg, std::forward(args)...); } -#ifdef ENABLE_STACKTRACE - if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace) { + if (stacktrace && ErrorCode::error_states[abs(code)].stacktrace && + config::enable_stacktrace) { status._err_msg->_stack = get_stack_trace(1); LOG(WARNING) << "meet error status: " << status; // may print too many stacks. } -#endif return status; } @@ -545,9 +541,7 @@ class [[nodiscard]] Status { int _code; struct ErrMsg { std::string _msg; -#ifdef ENABLE_STACKTRACE std::string _stack; -#endif }; std::unique_ptr _err_msg; @@ -604,11 +598,9 @@ class AtomicStatus { inline std::ostream& operator<<(std::ostream& ostr, const Status& status) { ostr << '[' << status.code_as_string() << ']'; ostr << status.msg(); -#ifdef ENABLE_STACKTRACE - if (status._err_msg && !status._err_msg->_stack.empty()) { + if (status._err_msg && !status._err_msg->_stack.empty() && config::enable_stacktrace) { ostr << '\n' << status._err_msg->_stack; } -#endif return ostr; } diff --git a/be/src/util/stack_util.cpp b/be/src/util/stack_util.cpp index 5dfde1bd454dc4..20daea588732f2 100644 --- a/be/src/util/stack_util.cpp +++ b/be/src/util/stack_util.cpp @@ -36,7 +36,9 @@ void DumpStackTraceToString(std::string* stacktrace); namespace doris { std::string get_stack_trace(int start_pointers_index, std::string dwarf_location_info_mode) { -#ifdef ENABLE_STACKTRACE + if (!config::enable_stacktrace) { + return "no enable stacktrace"; + } if (dwarf_location_info_mode.empty()) { dwarf_location_info_mode = config::dwarf_location_info_mode; } @@ -55,8 +57,6 @@ std::string get_stack_trace(int start_pointers_index, std::string dwarf_location } else { return "no stack"; } -#endif - return "no enable stack"; } std::string get_stack_trace_by_glog() { diff --git a/be/src/vec/common/allocator.cpp b/be/src/vec/common/allocator.cpp index 9eb65f33fc4343..2b1c05533cd504 100644 --- a/be/src/vec/common/allocator.cpp +++ b/be/src/vec/common/allocator.cpp @@ -64,9 +64,9 @@ void Allocator::sys_memory_check(size_t [[maybe_unused]] auto stack_trace_st = doris::Status::Error( injection_err_msg); -#ifndef ENABLE_STACKTRACE - LOG(INFO) << stack_trace_st.to_string(); -#endif + if (!doris::config::enable_stacktrace) { + LOG(INFO) << stack_trace_st.to_string(); + } if (!doris::enable_thread_catch_bad_alloc) { doris::thread_context()->thread_mem_tracker_mgr->cancel_query(injection_err_msg); } else { diff --git a/be/test/testutil/run_all_tests.cpp b/be/test/testutil/run_all_tests.cpp index 1cf749d0f7ff7c..d40ce9c5e8a3b4 100644 --- a/be/test/testutil/run_all_tests.cpp +++ b/be/test/testutil/run_all_tests.cpp @@ -23,6 +23,7 @@ #include "common/config.h" #include "common/logging.h" +#include "common/status.h" #include "gtest/gtest.h" #include "gtest/gtest_pred_impl.h" #include "http/ev_http_server.h" @@ -60,6 +61,10 @@ int main(int argc, char** argv) { doris::TabletSchemaCache::create_global_schema_cache( doris::config::tablet_schema_cache_capacity)); LOG(INFO) << "init config " << st; + doris::Status s = doris::config::set_config("enable_stacktrace", "false"); + if (!s.ok()) { + LOG(WARNING) << "set enable_stacktrace=false failed"; + } doris::init_glog("be-test"); ::testing::InitGoogleTest(&argc, argv); diff --git a/build.sh b/build.sh index c7752acc3acbf0..14b1244ead7c8f 100755 --- a/build.sh +++ b/build.sh @@ -381,9 +381,6 @@ fi if [[ -z "${USE_BTHREAD_SCANNER}" ]]; then USE_BTHREAD_SCANNER='OFF' fi -if [[ -z "${ENABLE_STACKTRACE}" ]]; then - ENABLE_STACKTRACE='ON' -fi if [[ -z "${USE_DWARF}" ]]; then USE_DWARF='OFF' @@ -484,7 +481,6 @@ echo "Get params: USE_MEM_TRACKER -- ${USE_MEM_TRACKER} USE_JEMALLOC -- ${USE_JEMALLOC} USE_BTHREAD_SCANNER -- ${USE_BTHREAD_SCANNER} - ENABLE_STACKTRACE -- ${ENABLE_STACKTRACE} ENABLE_INJECTION_POINT -- ${ENABLE_INJECTION_POINT} DENABLE_CLANG_COVERAGE -- ${DENABLE_CLANG_COVERAGE} DISPLAY_BUILD_TIME -- ${DISPLAY_BUILD_TIME} @@ -586,7 +582,6 @@ if [[ "${BUILD_BE}" -eq 1 ]]; then -DENABLE_PCH="${ENABLE_PCH}" \ -DUSE_MEM_TRACKER="${USE_MEM_TRACKER}" \ -DUSE_JEMALLOC="${USE_JEMALLOC}" \ - -DENABLE_STACKTRACE="${ENABLE_STACKTRACE}" \ -DUSE_AVX2="${USE_AVX2}" \ -DGLIBC_COMPATIBILITY="${GLIBC_COMPATIBILITY}" \ -DEXTRA_CXX_FLAGS="${EXTRA_CXX_FLAGS}" \