1 #ifndef MHO_Profiler_HH__
2 #define MHO_Profiler_HH__
35 namespace sn = selfname;
50 #define PROFILE_INFO_LEN 128
93 void Enable() { fDisabled =
false; };
115 void Lock() { fMutex.lock(); };
131 void AddEntry(
int flag, uint64_t thread_id, std::string filename,
int line_num, std::string func_name);
138 void GetEvents(std::vector< MHO_ProfileEvent >& events) { events = fEvents; }
149 fEvents.reserve(1000);
153 virtual ~MHO_Profiler(){};
156 std::size_t fNThreads;
161 std::vector< MHO_ProfileEvent > fEvents;
166 #ifdef HOPS_USE_PROFILER
169 #define profiler_start() \
172 MHO_Profiler::GetInstance().Lock(); \
173 MHO_Profiler::GetInstance().AddEntry(pStart, std::hash< std::thread::id >{}(std::this_thread::get_id()), \
174 std::string(sn::file_basename(__FILE__)), __LINE__, \
175 std::string(__PRETTY_FUNCTION__)); \
176 MHO_Profiler::GetInstance().Unlock(); \
180 #define profiler_stop() \
183 MHO_Profiler::GetInstance().Lock(); \
184 MHO_Profiler::GetInstance().AddEntry(pStop, std::hash< std::thread::id >{}(std::this_thread::get_id()), \
185 std::string(sn::file_basename(__FILE__)), __LINE__, \
186 std::string(__PRETTY_FUNCTION__)); \
187 MHO_Profiler::GetInstance().Unlock(); \
194 struct MHO_ProfilerGuard
196 MHO_ProfilerGuard(uint64_t thread_id, std::string filename,
int line_num, std::string funcname)
197 : fThreadID(thread_id), fFilename(std::move(filename)), fFuncname(std::move(funcname))
212 MHO_ProfilerGuard(
const MHO_ProfilerGuard&) =
delete;
213 MHO_ProfilerGuard& operator=(
const MHO_ProfilerGuard&) =
delete;
217 std::string fFilename;
218 std::string fFuncname;
222 #define PROFILER_CONCAT_(a, b) a##b
223 #define PROFILER_CONCAT(a, b) PROFILER_CONCAT_(a, b)
227 #define profiler_scope() \
228 hops::MHO_ProfilerGuard PROFILER_CONCAT(_pg_, __LINE__)(std::hash< std::thread::id >{}(std::this_thread::get_id()), \
229 std::string(sn::file_basename(__FILE__)), __LINE__, \
230 std::string(__PRETTY_FUNCTION__))
235 #define profiler_start()
236 #define profiler_stop()
237 #define profiler_scope()
#define PROFILE_INFO_LEN
Definition: MHO_Profiler.hh:50
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:105
void Unlock()
Releases control of the mutex.
Definition: MHO_Profiler.hh:120
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:93
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:6
void GetEvents(std::vector< MHO_ProfileEvent > &events)
Getter for events - at end of program, retrieve and utilize the profiler events.
Definition: MHO_Profiler.hh:138
MHO_Profiler(MHO_Profiler &&)=delete
void Disable()
Sets HOPS_COLOR_MSG to disabled state.
Definition: MHO_Profiler.hh:98
MHO_Profiler & operator=(MHO_Profiler const &)=delete
void DumpEvents()
Prints all stored events along with their details.
Definition: MHO_Profiler.cc:25
void Lock()
Acquires a lock using fMutex for thread synchronization. TODO we need to eliminate the need for locks...
Definition: MHO_Profiler.hh:115
MHO_Profiler & operator=(MHO_Profiler &&)=delete
void Start()
Definition: Message/src/MHO_Timer.cc:37
Definition: MHO_AdhocFlagging.hh:18
int fLineNumber
Definition: MHO_Profiler.hh:58
double fTime
Definition: MHO_Profiler.hh:60
char fFuncname[PROFILE_INFO_LEN]
Definition: MHO_Profiler.hh:62
MHO_ProfilerFlag
Definition: MHO_Profiler.hh:38
@ pStartFlag
Definition: MHO_Profiler.hh:39
@ pStopFlag
Definition: MHO_Profiler.hh:40
int fFlag
Definition: MHO_Profiler.hh:57
char fFilename[PROFILE_INFO_LEN]
Definition: MHO_Profiler.hh:61
uint64_t fThreadID
Definition: MHO_Profiler.hh:59
Class MHO_ProfileEvent.
Definition: MHO_Profiler.hh:56