35#define G4Profiler_hh 1
39# include "G4GlobalConfig.hh"
43#include "G4Profiler.icc"
45#if defined(GEANT4_USE_TIMEMORY)
46# include <timemory/utility/argparse.hpp>
95 using array_type = std::array<bool, G4ProfileType::TypeEnd>;
97#if defined(GEANT4_USE_TIMEMORY)
106 static void Configure(
const std::vector<std::string>& args);
107 static void Configure(
int argc,
char** argv);
108 static void Configure(ArgumentParser&,
const std::vector<std::string>& args);
109 static void Configure(ArgumentParser&,
int argc,
char** argv);
120 static bool& GetPerEventImpl()
122 static bool _value =
false;
130template <
size_t Category>
136template <
size_t Category>
166 using type =
const std::string&;
171template <
size_t Category>
187template <
size_t Category>
192template <
size_t Category,
typename RetT,
typename CommonT = G4CommonTypeList<>>
195 using type = G4Impl::Functors_t<RetT, CommonT, G4ProfilerArgs_t<Category>>;
198template <
size_t Category,
typename RetT,
typename... CommonT>
201 G4CommonTypeList<CommonT...>>::type;
205#ifdef GEANT4_USE_TIMEMORY
212 template <
size_t,
typename Tag>
216 template <
typename... Types>
219 template <
typename Tag,
typename... Types>
226 using tim::component::user_bundle;
228 struct G4api :
public tim::concepts::api
231 using ProfilerArgparser = argparse::argument_parser;
241template <
typename... Types>
252 template <
typename... Types>
255 template <
typename... Args>
265 template <
typename... Args>
268 template <
typename... Args>
275 template <
typename... Args>
278 template <
typename... Args>
287 template <
size_t Idx,
typename Tp>
290 template <
typename... Args>
294 template <
typename... Types,
typename... Args>
309template <
typename... Types>
323template <
size_t Category>
331 G4TypeListSize<G4ProfilerArgs_t<Category>>::value;
342 template <
typename Arg,
typename... Args>
357 template <
typename... Args>
361 operator bool()
const {
return (m_bundle !=
nullptr); }
364 type* m_bundle =
nullptr;
386 template <
typename... Args>
387 static bool Query(Args... _args);
390 template <
typename... Args>
391 static std::string
Label(Args... _args);
394 template <
typename... Args>
395 static type*
Tool(
const std::string&);
411 template <
bool B,
typename Lhs,
typename Rhs>
412 using conditional_t =
typename std::conditional<B, Lhs, Rhs>::type;
416 struct PersistentSettings
419 using functor_type = conditional_t<
421 conditional_t<Idx == G4ProfileOp::Label, LabelFunc_t, ToolFunc_t>>;
423 PersistentSettings() =
default;
424 ~PersistentSettings() =
default;
426 functor_type m_functor;
430 static PersistentSettings<Idx>& GetPersistentFallback();
433 static PersistentSettings<Idx>& GetPersistent();
439template <
size_t Category>
445template <
typename Arg,
typename... Args>
448 this->operator()(_arg, _args...);
454template <
typename... Args>
459 m_bundle = Tool(Label(_args...));
461 m_bundle->start(_args...);
462 return (m_bundle !=
nullptr);
471template <
typename... Args>
474 return QueryHandler_t{ GetPersistent<G4ProfileOp::Query>().m_functor }(
482template <
typename... Args>
485 return LabelHandler_t{ GetPersistent<G4ProfileOp::Label>().m_functor }(
493template <
typename... Args>
495 const std::string& _args)
497 return ToolHandler_t{ GetPersistent<G4ProfileOp::Tool>().m_functor }(_args);
522#ifndef GEANT4_USE_TIMEMORY
529#if defined(GEANT4_USE_TIMEMORY)
531# define G4USER_PROFILER_VAR_JOIN(X, Y) X##Y
532# define G4USER_PROFILER_VAR(Y) G4USER_PROFILER_VAR_JOIN(g4user_profiler_, Y)
535# define G4USER_SCOPED_PROFILE(...) \
536 G4ProfilerConfig<G4ProfileType::User> G4USER_PROFILER_VAR(__LINE__)( \
537 TIMEMORY_JOIN("", __VA_ARGS__))
540# define G4USER_SCOPED_PROFILE_FUNC(...) \
541 G4ProfilerConfig<G4ProfileType::User> G4USER_PROFILER_VAR(__LINE__)( \
542 TIMEMORY_JOIN("", __FUNCTION__, "/", __VA_ARGS__))
545# define G4USER_SCOPED_PROFILE_FUNC_FILE(...) \
546 G4ProfilerConfig<G4ProfileType::User> G4USER_PROFILER_VAR(__LINE__)( \
547 TIMEMORY_JOIN("", __FUNCTION__, '@', __FILE__, '/', __VA_ARGS__))
550# define G4USER_SCOPED_PROFILE_FUNC_FILE_LINE(...) \
551 G4ProfilerConfig<G4ProfileType::User> G4USER_PROFILER_VAR(__LINE__)( \
552 TIMEMORY_JOIN("", __FUNCTION__, '@', __FILE__, ':', __LINE__, '/', \
555# define G4USER_SCOPED_PROFILE(...)
556# define G4USER_SCOPED_PROFILE_FUNC(...)
557# define G4USER_SCOPED_PROFILE_FUNC_FILE(...)
558# define G4USER_SCOPED_PROFILE_FUNC_FILE_LINE(...)
typename G4ProfilerConfig< Category >::type G4ProfilerConfig_t
typename G4ProfilerObject< Category >::type G4ProfilerObject_t
typename G4ProfilerArgs< Category >::type G4ProfilerArgs_t
typename G4ProfilerFunctors< Category, RetT, G4CommonTypeList< CommonT... > >::type G4ProfilerFunctors_t
FuncHandler< this_type, LabelFunc_t, std::string > LabelHandler_t
static QueryHandler_t GetFallbackQueryFunctor()
FuncHandler< this_type, ToolFunc_t, type * > ToolHandler_t
static ToolHandler_t GetToolFunctor()
static ToolHandler_t GetFallbackToolFunctor()
G4ProfilerConfig(const G4ProfilerConfig &)=delete
static constexpr size_t arg_sets
G4ProfilerConfig & operator=(const G4ProfilerConfig &)=delete
static QueryHandler_t GetQueryFunctor()
G4ProfilerFunctors_t< Category, std::string > LabelFunc_t
static type * Tool(const std::string &)
static bool Query(Args... _args)
G4ProfilerBundle< g4tim::user_bundle< Category, G4ProfileType > > type
static LabelHandler_t GetLabelFunctor()
G4ProfilerConfig(G4ProfilerConfig &&)=default
static LabelHandler_t GetFallbackLabelFunctor()
G4ProfilerConfig()=default
FuncHandler< this_type, QueryFunc_t, bool > QueryHandler_t
std::tuple< std::function< type *(const std::string &)> > ToolFunc_t
G4ProfilerFunctors_t< Category, bool > QueryFunc_t
static std::string Label(Args... _args)
G4ProfilerConfig & operator=(G4ProfilerConfig &&)=default
static void Configure(const std::vector< std::string > &args)
static void SetEnabled(size_t v, bool val)
static void SetPerEvent(bool val)
std::array< bool, G4ProfileType::TypeEnd > array_type
static bool GetPerEvent()
static bool GetEnabled(size_t v)
G4TypeList< G4PROFILER_ARG_SET(value_type)> type
G4ProfilerObject_t< Category > value_type
G4Impl::Functors_t< RetT, CommonT, G4ProfilerArgs_t< Category > > type
ArgumentParser(std::string)
this provides a dummy wrapper for the profiling
void mark_begin(Args &&...)
void report_at_exit(bool)
handler(handler &&)=default
handler & operator=(const handler &)=default
friend std::ostream & operator<<(std::ostream &os, const handler &)
handler(const handler &)=default
handler & operator=(handler &&)=default
void mark_end(Args &&...)
static void configure(Args &&...)