1#ifndef KOKKOS_UTILS_CALLBACKS_RECORDERLISTENER_HPP
2#define KOKKOS_UTILS_CALLBACKS_RECORDERLISTENER_HPP
25template <
typename MatcherType,
Event... EventTypes>
requires (
sizeof...(EventTypes) > 0 &&
MatcherFor<MatcherType, EventTypes...>)
35 template <
typename T>
requires std::same_as<std::remove_cvref_t<T>, MatcherType>
37 :
matcher(std::forward<T>(matcher_)) {}
54 out <<
"Number of events recorded: " <<
recorded_events.size() << std::endl;
56 std::visit([&out] (
const auto& arg) { out <<
"- " << arg << std::endl; }, recorded_event);
61 template <
typename Callable>
62 static auto record(Callable&& callable)
64 const auto recorder_listener = std::make_shared<RecorderListener>();
68 std::invoke(std::forward<Callable>(callable));
72 return std::move(recorder_listener->recorded_events);
86template <
typename MatcherType, Event... EventTypes>
91template <
Event... EventTypes>
94template <
Event... EventTypes>
static void unregister_listener(const Callable *const callable)
Unregister a callable object as a listener.
static listener_list_const_iter_t register_listener(std::shared_ptr< Callable > callable)
Register a callable object, passed as a shared pointer, as a listener.
static auto record(Callable &&callable)
Returns the events of the types EventTypes... that occur during the execution of callable.
RecorderListener(T &&matcher_)
RecorderListener()=default
void operator()(const EventType &event)
std::deque< std::variant< EventTypes... > > recorded_events
void report(std::ostream &out) const
Report the recorded events.
Kokkos::Impl::type_list< EventTypes... > event_type_list_t
Concept to constrain any event type that is one of the given event types.
Check that Callable is a matcher for each event in EventTypes.