User regions in Python (#57)

* User regions in Python

* User-region testing + common submodule

- Updated examples/python/source.py to use user-regions
- Python-level user submodule
- Python-level common submodule
- clean-up of profiler python code
- extended source.py testing to include the user-regions
This commit is contained in:
Jonathan R. Madsen
2022-07-25 20:24:34 -05:00
committed by GitHub
parent 74fe68101b
commit 4dd144a32c
9 changed files with 371 additions and 167 deletions
+34 -1
View File
@@ -24,6 +24,7 @@
#include "dl.hpp"
#include "library/coverage.hpp"
#include "library/impl/coverage.hpp"
#include "omnitrace/user.h"
#include <timemory/backends/process.hpp>
#include <timemory/backends/threading.hpp>
@@ -62,6 +63,11 @@ namespace pycoverage
py::module
generate(py::module& _pymod);
}
namespace pyuser
{
py::module
generate(py::module& _pymod);
}
} // namespace pyomnitrace
template <typename... Tp>
@@ -158,8 +164,8 @@ PYBIND11_MODULE(libpyomnitrace, omni)
py::doc("omnitrace profiler for python");
pyprofile::generate(omni);
pycoverage::generate(omni);
pyuser::generate(omni);
}
//======================================================================================//
@@ -824,6 +830,33 @@ generate(py::module& _pymod)
return _pycov;
}
} // namespace pycoverage
namespace pyuser
{
py::module
generate(py::module& _pymod)
{
py::module _pyuser = _pymod.def_submodule("user", "User instrumentation");
_pyuser.def("start_trace", &omnitrace_user_start_trace,
"Enable tracing on this thread and all subsequently created threads");
_pyuser.def("stop_trace", &omnitrace_user_stop_trace,
"Disable tracing on this thread and all subsequently created threads");
_pyuser.def(
"start_thread_trace", &omnitrace_user_start_thread_trace,
"Enable tracing on this thread. Does not apply to subsequently created threads");
_pyuser.def(
"stop_thread_trace", &omnitrace_user_stop_thread_trace,
"Enable tracing on this thread. Does not apply to subsequently created threads");
_pyuser.def("push_region", &omnitrace_user_push_region,
"Start a user-defined region");
_pyuser.def("pop_region", &omnitrace_user_pop_region, "Start a user-defined region");
_pyuser.def("error_string", &omnitrace_user_error_string,
"Return a descriptor for the provided error code");
return _pyuser;
}
} // namespace pyuser
} // namespace pyomnitrace
//
//======================================================================================//