Static libstdcxx and python (#139)

Support python + static libstdc++

[ROCm/rocprofiler-systems commit: a1dcd1bc4b]
Este commit está contenido en:
Jonathan R. Madsen
2022-08-28 03:56:13 -05:00
cometido por GitHub
padre 7ceb1e0bee
commit f642813ad1
Se han modificado 11 ficheros con 127 adiciones y 57 borrados
@@ -5,8 +5,8 @@
# ########################################################################################
if(OMNITRACE_BUILD_STATIC_LIBSTDCXX)
omnitrace_message(FATAL_ERROR
"static libstdc++ is not compatible with python bindings")
# omnitrace_message(FATAL_ERROR "static libstdc++ is not compatible with python
# bindings")
endif()
# if set, will screw up loading library
@@ -76,18 +76,16 @@ set(pybind_libs pybind11::module)
add_library(libpyomnitrace-interface INTERFACE)
target_link_libraries(
libpyomnitrace-interface
INTERFACE
pybind11::module
timemory::timemory-headers
omnitrace::omnitrace-headers
omnitrace::omnitrace-compile-options
omnitrace::omnitrace-lto
omnitrace::omnitrace-dl-library
omnitrace::omnitrace-user-library
omnitrace::omnitrace-python
omnitrace::omnitrace-python-compile-options
$<BUILD_INTERFACE:$<IF:$<BOOL:${OMNITRACE_BUILD_STATIC_LIBGCC}>,omnitrace::omnitrace-static-libgcc,>>
)
INTERFACE pybind11::module
timemory::timemory-headers
omnitrace::omnitrace-headers
omnitrace::omnitrace-compile-options
omnitrace::omnitrace-static-libgcc-optional
omnitrace::omnitrace-lto
omnitrace::omnitrace-dl-library
omnitrace::omnitrace-user-library
omnitrace::omnitrace-python
omnitrace::omnitrace-python-compile-options)
omnitrace_target_compile_definitions(libpyomnitrace-interface
INTERFACE OMNITRACE_PYBIND11_SOURCE)
@@ -77,6 +77,9 @@ PYBIND11_MODULE(libpyomnitrace, omni)
{
using namespace pyomnitrace;
py::doc("Omnitrace Python bindings for profiling, user API, and code coverage "
"post-processing");
static bool _is_initialized = false;
static bool _is_finalized = false;
static auto _get_use_mpi = []() {
@@ -162,10 +165,25 @@ PYBIND11_MODULE(libpyomnitrace, omni)
},
"Finalize omnitrace");
py::doc("omnitrace profiler for python");
pyprofile::generate(omni);
pycoverage::generate(omni);
pyuser::generate(omni);
auto _python_path = tim::get_env("OMNITRACE_PATH", std::string{}, false);
auto _libpath = std::string{ "libomnitrace-dl.so" };
if(!_python_path.empty()) _libpath = TIMEMORY_JOIN("/", _python_path, _libpath);
// permit env override if default path fails/is wrong
_libpath = tim::get_env("OMNITRACE_DL_LIBRARY", _libpath);
// this is necessary when building with -static-libstdc++
// without it, loading libomnitrace.so within libomnitrace-dl.so segfaults
if(!dlopen(_libpath.c_str(), RTLD_NOW | RTLD_GLOBAL))
{
auto _msg =
TIMEMORY_JOIN("", "dlopen(\"", _libpath, "\", RTLD_NOW | RTLD_GLOBAL)");
perror(_msg.c_str());
fprintf(stderr, "[omnitrace][dl][pid=%i] %s :: %s\n", getpid(), _msg.c_str(),
dlerror());
}
}
//======================================================================================//
@@ -35,6 +35,12 @@ This submodule imports the timemory Python function profiler
"""
try:
import os
os.environ["OMNITRACE_PATH"] = os.path.abspath(
os.path.join(os.path.dirname(__file__), "../../..")
)
from .libpyomnitrace import coverage
from . import user
from .profiler import Profiler, FakeProfiler
@@ -93,7 +93,7 @@ class Region:
_count = Region._counter
self._active = False
if _count != self._count:
raise LogicError(
raise RuntimeError(
f"{self._label} was not popped in the order it was pushed. Current stack number: {_count}, expected stack number: {self._count}"
)
_libuser.pop_region(self._label)