1#ifndef KOKKOS_UTILS_CALLBACKS_RECORDERLISTENER_HPP
2#define KOKKOS_UTILS_CALLBACKS_RECORDERLISTENER_HPP
26template <
typename MatcherType,
Event... EventTypes>
requires (
sizeof...(EventTypes) > 0 &&
MatcherFor<MatcherType, EventTypes...>)
37 template <
typename T>
requires std::same_as<std::remove_cvref_t<T>, MatcherType>
39 :
matcher(std::forward<T>(matcher_)) {}
50 const std::lock_guard lock(
mtx);
65 out <<
"Number of events recorded: " <<
recorded_events.size() << std::endl;
67 std::visit([&out] (
const auto& arg) { out <<
"- " << arg << std::endl; }, recorded_event);
72 template <
typename Callable>
73 static auto record(Callable&& callable)
75 const auto recorder_listener = std::make_shared<RecorderListener>();
79 std::invoke(std::forward<Callable>(callable));
83 return std::move(recorder_listener->recorded_events);
95 mutable std::mutex
mtx;
98template <
typename MatcherType,
Event... EventTypes>
103template <
Event... EventTypes>
106template <
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 & operator=(RecorderListener &&)=delete
std::deque< event_variant_t > recorded_events
RecorderListener & operator=(const RecorderListener &)=delete
RecorderListener(RecorderListener &&)=delete
std::variant< EventTypes... > event_variant_t
RecorderListener(const RecorderListener &)=delete
RecorderListener()=default
void operator()(const EventType &event)
Ensure atomic growth of recorded_events with mtx.
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.