diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5199fa2c2..e2c906869 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -34,6 +34,7 @@ option(USE_DEBUG_OUTPUT "Dump internal training results like gradients and predi
Should only be used for debugging." OFF)
option(FORCE_COLORED_OUTPUT "Force colored output from compilers, useful when ninja is used instead of make." OFF)
option(ENABLE_ALL_WARNINGS "Enable all compiler warnings. Only effective for GCC/Clang" OFF)
+option(LOG_CAPI_INVOCATION "Log all C API invocations for debugging" OFF)
option(GOOGLE_TEST "Build google tests" OFF)
option(USE_DMLC_GTEST "Use google tests bundled with dmlc-core submodule" OFF)
option(USE_NVTX "Build with cuda profiling annotations. Developers only." OFF)
diff --git a/jvm-packages/create_jni.py b/jvm-packages/create_jni.py
index 29169c97b..811e4155e 100755
--- a/jvm-packages/create_jni.py
+++ b/jvm-packages/create_jni.py
@@ -21,7 +21,8 @@ CONFIG = {
"USE_CUDA": "OFF",
"USE_NCCL": "OFF",
- "JVM_BINDINGS": "ON"
+ "JVM_BINDINGS": "ON",
+ "LOG_CAPI_INVOCATION": "OFF"
}
@@ -70,6 +71,7 @@ def normpath(path):
if __name__ == "__main__":
parser = argparse.ArgumentParser()
+ parser.add_argument('--log-capi-invocation', type=str, choices=['ON', 'OFF'], default='OFF')
parser.add_argument('--use-cuda', type=str, choices=['ON', 'OFF'], default='OFF')
cli_args = parser.parse_args()
@@ -93,6 +95,9 @@ if __name__ == "__main__":
else:
maybe_parallel_build = ""
+ if cli_args.log_capi_invocation == 'ON':
+ CONFIG['LOG_CAPI_INVOCATION'] = 'ON'
+
if cli_args.use_cuda == 'ON':
CONFIG['USE_CUDA'] = 'ON'
CONFIG['USE_NCCL'] = 'ON'
diff --git a/jvm-packages/pom.xml b/jvm-packages/pom.xml
index 04a11bc2b..fdca78ba4 100644
--- a/jvm-packages/pom.xml
+++ b/jvm-packages/pom.xml
@@ -38,6 +38,7 @@
2.12.8
2.12
2.7.3
+ OFF
OFF
diff --git a/jvm-packages/xgboost4j/pom.xml b/jvm-packages/xgboost4j/pom.xml
index 62a96c41e..927e6d42e 100644
--- a/jvm-packages/xgboost4j/pom.xml
+++ b/jvm-packages/xgboost4j/pom.xml
@@ -84,6 +84,8 @@
python
create_jni.py
+ --log-capi-invocation
+ ${log.capi.invocation}
--use-cuda
${use.cuda}
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index aae08d5f0..52813b83e 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -76,6 +76,9 @@ if (ENABLE_ALL_WARNINGS)
target_compile_options(objxgboost PUBLIC
$,-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
diff --git a/src/c_api/c_api_error.h b/src/c_api/c_api_error.h
index ef8fbe96a..612c89cbf 100644
--- a/src/c_api/c_api_error.h
+++ b/src/c_api/c_api_error.h
@@ -10,7 +10,12 @@
#include
/*! \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(*)