Add CMake flag to log C API invocations, to aid debugging (#5925)

* Add CMake flag to log C API invocations, to aid debugging

* Remove unnecessary parentheses
This commit is contained in:
Philip Hyunsu Cho
2020-07-30 19:24:28 -07:00
committed by GitHub
parent 3b88bc948f
commit 3fcfaad577
6 changed files with 18 additions and 1 deletions

View File

@@ -76,6 +76,9 @@ if (ENABLE_ALL_WARNINGS)
target_compile_options(objxgboost PUBLIC
$<IF:$<COMPILE_LANGUAGE:CUDA>,-Xcompiler=-Wall -Xcompiler=-Wextra,-Wall -Wextra>)
endif (ENABLE_ALL_WARNINGS)
if (LOG_CAPI_INVOCATION)
target_compile_definitions(objxgboost PUBLIC -DLOG_CAPI_INVOCATION=1)
endif (LOG_CAPI_INVOCATION)
set_target_properties(objxgboost PROPERTIES
POSITION_INDEPENDENT_CODE ON

View File

@@ -10,7 +10,12 @@
#include <dmlc/logging.h>
/*! \brief macro to guard beginning and end section of all functions */
#ifdef LOG_CAPI_INVOCATION
#define API_BEGIN() \
LOG(CONSOLE) << "[XGBoost C API invocation] " << __PRETTY_FUNCTION__; try {
#else // LOG_CAPI_INVOCATION
#define API_BEGIN() try {
#endif // LOG_CAPI_INVOCATION
/*! \brief every function starts with API_BEGIN();
and finishes with API_END() or API_END_HANDLE_ERROR */
#define API_END() } catch(dmlc::Error &_except_) { return XGBAPIHandleException(_except_); } return 0; // NOLINT(*)