Skip to content

Commit

Permalink
Perfetto / Python Updates (#236)
Browse files Browse the repository at this point in the history
* Fixes to pip install + miscellaneous changes

- Updated MANIFEST.in
- Fix build-system when installing via pip
- Fixed AppleClang issue with hash specialization of static_string
- Moved _config.cpp to config.cpp

* Perfetto / Python Updates

- python_args for perfetto
- {global,thread}_{init,finalize} static functions in python components

* Testing tweaks

* Formatting updates
  • Loading branch information
jrmadsen committed Dec 7, 2021
1 parent 0dcdfed commit 1662925
Show file tree
Hide file tree
Showing 13 changed files with 476 additions and 438 deletions.
4 changes: 4 additions & 0 deletions MANIFEST.in
Expand Up @@ -38,6 +38,7 @@ global-exclude *.pyc
global-exclude *.git*
global-exclude *__pycache__*
global-exclude *.so
global-exclude *.sql

# recursive excludes

Expand All @@ -46,7 +47,10 @@ recursive-exclude _skbuild *
recursive-exclude build *
recursive-exclude dist *
recursive-exclude external/hatchet/build *
recursive-exclude external/perfetto *

# bypass global exclude of git files

include docs/.gitinfo
include external/perfetto/sdk/perfetto.h
include external/perfetto/sdk/perfetto.cc
2 changes: 1 addition & 1 deletion VERSION
@@ -1 +1 @@
3.3.0
3.3.0rc4
2 changes: 1 addition & 1 deletion cmake/Modules/Packages.cmake
Expand Up @@ -358,7 +358,7 @@ if(TIMEMORY_USE_WINSOCK)
timemory_target_compile_definitions(timemory-headers INTERFACE TIMEMORY_USE_WINSOCK)
endif()

if(TIMEMORY_BUILD_TESTING)
if(TIMEMORY_BUILD_TESTING OR TIMEMORY_BUILD_MINIMAL_TESTING)
target_compile_definitions(timemory-headers
INTERFACE $<BUILD_INTERFACE:TIMEMORY_INTERNAL_TESTING>)
endif()
Expand Down
9 changes: 9 additions & 0 deletions pyproject.toml
@@ -1,3 +1,12 @@
[build-system]
requires = [
"setuptools >= 40.0.4",
"setuptools_scm >= 2.0.0",
"wheel >= 0.29.0",
"scikit-build >= 0.8.0",
"cython",
]
build-backend = 'setuptools.build_meta'

[tool.black]
line-length = 80
Expand Down
26 changes: 26 additions & 0 deletions source/python/libpytimemory-components.cpp
Expand Up @@ -754,12 +754,38 @@ generate(py::module& _pymod, std::array<bool, N>& _boolgen,
return T::description();
};

namespace operation = tim::operation;

auto _global_init = []() {
operation::init<T>{}(operation::mode_constant<operation::init_mode::global>{});
};

auto _thread_init = []() {
operation::init<T>{}(operation::mode_constant<operation::init_mode::thread>{});
};

auto _global_fini = []() {
operation::fini<T>{}(operation::mode_constant<operation::fini_mode::global>{});
};

auto _thread_fini = []() {
operation::fini<T>{}(operation::mode_constant<operation::fini_mode::thread>{});
};

auto _true = [](py::object) { return true; };

_pycomp.def_static("label", _label, "Get the label for the type");
_pycomp.def_static("description", _desc, "Get the description for the type");
_pycomp.def_property_readonly_static("available", _true,
"Whether the component is available");
_pycomp.def_static("global_init", _global_init,
"Execute global initialization routine");
_pycomp.def_static("thread_init", _thread_init,
"Execute thread initialization routine");
_pycomp.def_static("global_finalize", _global_fini,
"Execute global finalization routine");
_pycomp.def_static("thread_finalize", _thread_fini,
"Execute thread finalization routine");

std::set<std::string> _keys = property_t::ids();
_keys.insert(id);
Expand Down
5 changes: 4 additions & 1 deletion source/tests/CMakeLists.txt
Expand Up @@ -199,7 +199,10 @@ if(TARGET custom-record-functions)
PROPERTIES PROCESSOR_AFFINITY ON)
endif()

if(_LIBRARY_TARGET)
# tracing is only used via dynamic instrumentation so only test on linux
if(_LIBRARY_TARGET
AND UNIX
AND NOT APPLE)
list(APPEND trace_tests_env "TIMEMORY_COLLAPSE_THREADS=ON")
list(APPEND trace_tests_env "TIMEMORY_NODE_COUNT=2")
list(APPEND trace_tests_env "TIMEMORY_MPI_THREAD=ON")
Expand Down
2 changes: 2 additions & 0 deletions source/timemory/components/perfetto/perfetto.cpp
Expand Up @@ -143,6 +143,8 @@ perfetto_trace::global_finalize()
::perfetto::TrackEvent::Flush();

auto& _session = get_config().session;
if(!_session)
return;

// Stop tracing and read the trace data.
_session->StopBlocking();
Expand Down
22 changes: 22 additions & 0 deletions source/timemory/components/perfetto/types.hpp
Expand Up @@ -42,6 +42,28 @@ TIMEMORY_DEFINE_CONCRETE_TRAIT(uses_value_storage, component::perfetto_trace, fa
TIMEMORY_DEFINE_CONCRETE_TRAIT(is_available, component::perfetto_trace, false_type)
#endif

#if defined(TIMEMORY_PYBIND11_SOURCE)
//
namespace tim
{
namespace trait
{
//
template <>
struct python_args<TIMEMORY_STORE, component::perfetto_trace>
{
using type = type_list<type_list<size_t>, type_list<const char*, size_t>>;
};
//
template <>
struct python_args<TIMEMORY_START, component::perfetto_trace>
{
using type = type_list<type_list<const char*>>;
};
} // namespace trait
} // namespace tim
#endif

// perfetto header
#if defined(TIMEMORY_USE_PERFETTO)
# include <perfetto.h>
Expand Down
2 changes: 1 addition & 1 deletion source/timemory/config.hpp
Expand Up @@ -36,5 +36,5 @@
#include "timemory/config/config.hpp"
//
#if !defined(TIMEMORY_USE_CONFIG_EXTERN)
# include "timemory/config/_config.cpp"
# include "timemory/config/config.cpp"
#endif

0 comments on commit 1662925

Please sign in to comment.