diff --git a/src/vt/runnable/invoke.h b/src/vt/runnable/invoke.h index b461b7517d..506985e13d 100644 --- a/src/vt/runnable/invoke.h +++ b/src/vt/runnable/invoke.h @@ -45,16 +45,22 @@ #define INCLUDED_VT_RUNNABLE_INVOKE_H #include "vt/config.h" + +#if vt_check_enabled(trace_enabled) #include "vt/utils/demangle/demangle.h" #include "vt/utils/static_checks/function_ret_check.h" #include "vt/trace/trace_registry.h" #include #include +#endif + #include namespace vt { namespace runnable { +#if vt_check_enabled(trace_enabled) + template static std::string CreateEventTypeCStyleFunc() { using TE = vt::util::demangle::TemplateExtract; @@ -114,69 +120,41 @@ struct CallableWrapper { } }; -#if vt_check_enabled(trace_enabled) -template -static trace::TraceProcessingTag BeginProcessingInvokeEvent() { - const auto trace_id = CallableWrapper::GetTraceID(); - const auto trace_event = theTrace()->messageCreation(trace_id, 0); - const auto from_node = theContext()->getNode(); - - return theTrace()->beginProcessing(trace_id, 0, trace_event, from_node, timing::getCurrentTime()); -} - -template -static void EndProcessingInvokeEvent(trace::TraceProcessingTag processing_tag) { - theTrace()->endProcessing(processing_tag, timing::getCurrentTime()); +template +struct ScopedInvokeEvent { + ScopedInvokeEvent() { + const auto trace_id = CallableWrapper::GetTraceID(); + const auto trace_event = theTrace()->messageCreation(trace_id, 0); + const auto from_node = theContext()->getNode(); - const auto trace_id = CallableWrapper::GetTraceID(); - theTrace()->messageCreation(trace_id, 0); -} -#endif - -template -util::Copyable invoke(Args&&... args) { -#if vt_check_enabled(trace_enabled) - const auto processing_tag = - BeginProcessingInvokeEvent(); -#endif - - const auto& returnVal = std::invoke(std::forward(f), std::forward(args)...); - -#if vt_check_enabled(trace_enabled) - EndProcessingInvokeEvent(processing_tag); -#endif + tag_ = theTrace()->beginProcessing( + trace_id, 0, trace_event, from_node, timing::getCurrentTime() + ); + } - return returnVal; -} + ~ScopedInvokeEvent() { + theTrace()->endProcessing(tag_, timing::getCurrentTime()); + theTrace()->messageCreation(CallableWrapper::GetTraceID(), 0); + } -template -util::NotCopyable invoke(Args&&... args) { -#if vt_check_enabled(trace_enabled) - const auto processing_tag = - BeginProcessingInvokeEvent(); -#endif +private: + trace::TraceProcessingTag tag_ = {}; +}; - auto&& returnVal = std::invoke(std::forward(f), std::forward(args)...); +#endif // vt_check_enabled(trace_enabled) +template +auto invoke(Args&&... args){ #if vt_check_enabled(trace_enabled) - EndProcessingInvokeEvent(processing_tag); + ScopedInvokeEvent e; #endif - return std::move(returnVal); + return std::invoke(std::forward(f), std::forward(args)...); } template -util::IsVoidReturn invoke(Args&&... args) { -#if vt_check_enabled(trace_enabled) - const auto processing_tag = - BeginProcessingInvokeEvent(); -#endif - - std::invoke(std::forward(f), std::forward(args)...); - -#if vt_check_enabled(trace_enabled) - EndProcessingInvokeEvent(processing_tag); -#endif +auto invoke(Args&&... args) { + return invoke(std::forward(args)...); } }} // namespace vt::runnable