diff --git a/include/hook.h b/include/hook.h index 91212d4..54eb8a5 100644 --- a/include/hook.h +++ b/include/hook.h @@ -74,6 +74,8 @@ struct MemberDetector(self)->curSymName(), std::get<0>(sym)); }); + // TODO: if std::get<2>(*iter) is a pointer and it's point to + // std::get<1>(*iter) then there will return nullptr *std::get<2>(*iter) = info.oldFuncPtr; return std::get<1>(*iter); } diff --git a/lib/backtrace.cpp b/lib/backtrace.cpp index d94a288..c96184a 100644 --- a/lib/backtrace.cpp +++ b/lib/backtrace.cpp @@ -46,6 +46,11 @@ bool CallFrames::CollectNative() { } bool CallFrames::CollectPython() { + // https://stackoverflow.com/questions/33637423/pygilstate-ensure-after-py-finalize + if (!Py_IsInitialized()) { + LOG(WARN) << "python process finished!"; + return false; + } python_frames_.reserve(kMaxStackDeep); // Acquire the Global Interpreter Lock (GIL) before calling Python C API // functions from non-Python threads. diff --git a/lib/xpu_mock.cpp b/lib/xpu_mock.cpp index 655f50c..6c9ad53 100644 --- a/lib/xpu_mock.cpp +++ b/lib/xpu_mock.cpp @@ -32,6 +32,7 @@ class XpuRuntimeWrapApi { static int xpuWait(void* devStream); static int xpuMemcpy(void* dst, const void* src, uint64_t size, int kind); static int xpuSetDevice(int devId); + static int xpuCurrentDeviceId(int* devIdPtr); private: int (*raw_xpu_malloc_)(void**, uint64_t, int){nullptr}; @@ -254,6 +255,10 @@ int XpuRuntimeWrapApi::xpuSetDevice(int devId) { return XpuRuntimeWrapApi::instance().raw_xpu_set_device_id_(devId); } +int XpuRuntimeWrapApi::xpuCurrentDeviceId(int* devIdPtr) { + return XpuRuntimeWrapApi::instance().raw_xpu_current_device_(devIdPtr); +} + struct XpuRuntimeApiHook : public hook::HookInstallerWrap { bool targetLib(const char* name) { return !strstr(name, "libxpurt.so.1") && !strstr(name, "libxpurt.so"); @@ -271,7 +276,7 @@ struct XpuRuntimeApiHook : public hook::HookInstallerWrap { // get device id {"xpu_current_device", reinterpret_cast( - XpuRuntimeWrapApi::instance().raw_xpu_current_device_), + XpuRuntimeWrapApi::instance().xpuCurrentDeviceId), reinterpret_cast( &XpuRuntimeWrapApi::instance().raw_xpu_current_device_)}, // sync device @@ -288,7 +293,7 @@ struct XpuRuntimeApiHook : public hook::HookInstallerWrap { reinterpret_cast( &XpuRuntimeWrapApi::instance().raw_xpu_set_device_id_)}}; - void onSuccess() {} + void onSuccess() { LOG(WARN) << "install " << curSymName() << " success"; } }; } // namespace @@ -298,5 +303,6 @@ extern "C" { void xpu_dh_initialize() { static auto install_wrap = std::make_shared(); install_wrap->install(); + LOG(INFO) << "xpu_dh_initialize complete!"; } } \ No newline at end of file