1 #ifndef MHO_Profiler_HH__
2 #define MHO_Profiler_HH__
15 #define HOPS_USE_PROFILER
34 namespace sn = selfname;
49 #define PROFILE_INFO_LEN 128
86 if(fInstance ==
nullptr)
96 void Enable() { fDisabled =
false; };
119 void Lock() { fMutex.lock(); };
135 void AddEntry(
int flag, uint64_t thread_id, std::string filename,
int line_num, std::string func_name);
142 void GetEvents(std::vector< MHO_ProfileEvent >& events) { events = fEvents; }
153 fEvents.reserve(1000);
157 virtual ~MHO_Profiler(){};
161 std::size_t fNThreads;
166 std::vector< MHO_ProfileEvent > fEvents;
171 #ifdef HOPS_USE_PROFILER
174 #define profiler_start() \
177 MHO_Profiler::GetInstance().Lock(); \
178 MHO_Profiler::GetInstance().AddEntry(pStart, std::hash< std::thread::id >{}(std::this_thread::get_id()), \
179 std::string(sn::file_basename(__FILE__)), __LINE__, \
180 std::string(__PRETTY_FUNCTION__)); \
181 MHO_Profiler::GetInstance().Unlock(); \
185 #define profiler_stop() \
188 MHO_Profiler::GetInstance().Lock(); \
189 MHO_Profiler::GetInstance().AddEntry(pStop, std::hash< std::thread::id >{}(std::this_thread::get_id()), \
190 std::string(sn::file_basename(__FILE__)), __LINE__, \
191 std::string(__PRETTY_FUNCTION__)); \
192 MHO_Profiler::GetInstance().Unlock(); \
199 #define profiler_start()
200 #define profiler_stop()
#define PROFILE_INFO_LEN
Definition: MHO_Profiler.hh:49
constexpr to strip path prefix from FILE macros
Class MHO_Profiler - uses the singleton pattern.
Definition: MHO_Profiler.hh:69
bool IsEnabled() const
Checks if the feature is enabled.
Definition: MHO_Profiler.hh:108
void Unlock()
Releases control of the mutex.
Definition: MHO_Profiler.hh:124
static MHO_Profiler & GetInstance()
provide public access to the only static instance
Definition: MHO_Profiler.hh:84
MHO_Profiler(MHO_Profiler const &)=delete
void Enable()
Sets the enabled state to true.
Definition: MHO_Profiler.hh:96
void AddEntry(int flag, uint64_t thread_id, std::string filename, int line_num, std::string func_name)
Adds a profiling event to the internal list if not disabled.
Definition: MHO_Profiler.cc:9
void GetEvents(std::vector< MHO_ProfileEvent > &events)
Getter for events - at end of program, retrieve and utilize the profiler events.
Definition: MHO_Profiler.hh:142
MHO_Profiler(MHO_Profiler &&)=delete
void Disable()
Sets HOPS_COLOR_MSG to disabled state.
Definition: MHO_Profiler.hh:101
MHO_Profiler & operator=(MHO_Profiler const &)=delete
void DumpEvents()
Prints all stored events along with their details.
Definition: MHO_Profiler.cc:28
void Lock()
Acquires a lock using fMutex for thread synchronization. TODO we need to eliminate the need for locks...
Definition: MHO_Profiler.hh:119
MHO_Profiler & operator=(MHO_Profiler &&)=delete
void Start()
Definition: Message/src/MHO_Timer.cc:37
Definition: MHO_ChannelLabeler.hh:17
int fLineNumber
Definition: MHO_Profiler.hh:57
double fTime
Definition: MHO_Profiler.hh:59
char fFuncname[PROFILE_INFO_LEN]
Definition: MHO_Profiler.hh:61
MHO_ProfilerFlag
Definition: MHO_Profiler.hh:37
@ pStartFlag
Definition: MHO_Profiler.hh:38
@ pStopFlag
Definition: MHO_Profiler.hh:39
int fFlag
Definition: MHO_Profiler.hh:56
char fFilename[PROFILE_INFO_LEN]
Definition: MHO_Profiler.hh:60
uint64_t fThreadID
Definition: MHO_Profiler.hh:58
Class MHO_ProfileEvent.
Definition: MHO_Profiler.hh:55