From e7f5cc0748cf0c51de77f6afde4ba59707a302ef Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Wed, 1 Mar 2017 11:14:02 +0200 Subject: [PATCH] New API: * bool isEnabled() * bool isListening() * bool isEventTracingEnabled() * bool isLowPriorityEventTracing() --- easy_profiler_core/event_trace_win.h | 1 + easy_profiler_core/include/easy/profiler.h | 8 ++++ easy_profiler_core/profile_manager.cpp | 43 +++++++++++++++++++++- easy_profiler_core/profile_manager.h | 3 ++ 4 files changed, 54 insertions(+), 1 deletion(-) diff --git a/easy_profiler_core/event_trace_win.h b/easy_profiler_core/event_trace_win.h index fcce6b2..892b967 100644 --- a/easy_profiler_core/event_trace_win.h +++ b/easy_profiler_core/event_trace_win.h @@ -95,6 +95,7 @@ namespace profiler { ::profiler::EventTracingEnableStatus enable(bool _force = false); void disable(); void setLowPriority(bool _value); + bool getLowPriority(); static void setProcessPrivileges(); private: diff --git a/easy_profiler_core/include/easy/profiler.h b/easy_profiler_core/include/easy/profiler.h index 86c43d8..ebeb2af 100644 --- a/easy_profiler_core/include/easy/profiler.h +++ b/easy_profiler_core/include/easy/profiler.h @@ -547,6 +547,7 @@ namespace profiler { \ingroup profiler */ PROFILER_API void setEnabled(bool _isEnable); + PROFILER_API bool isEnabled(); /** Save all gathered blocks into file. @@ -581,6 +582,7 @@ namespace profiler { \ingroup profiler */ PROFILER_API void setEventTracingEnabled(bool _isEnable); + PROFILER_API bool isEventTracingEnabled(); /** Set event tracing thread priority (low or normal). @@ -591,6 +593,7 @@ namespace profiler { \ingroup profiler */ PROFILER_API void setLowPriorityEventTracing(bool _isLowPriority); + PROFILER_API bool isLowPriorityEventTracing(); /** Set temporary log-file path for Unix event tracing system. @@ -608,6 +611,7 @@ namespace profiler { PROFILER_API void startListen(uint16_t _port = ::profiler::DEFAULT_PORT); PROFILER_API void stopListen(); + PROFILER_API bool isListening(); /** Returns current major version. @@ -645,17 +649,21 @@ namespace profiler { { return reinterpret_cast(0xbad); } inline void endBlock() { } inline void setEnabled(bool) { } + inline bool isEnabled(bool) { return false; } inline void storeEvent(const BaseBlockDescriptor*, const char*) { } inline void beginBlock(Block&) { } inline uint32_t dumpBlocksToFile(const char*) { return 0; } inline const char* registerThreadScoped(const char*, ThreadGuard&) { return ""; } inline const char* registerThread(const char*) { return ""; } inline void setEventTracingEnabled(bool) { } + inline bool isEventTracingEnabled() { return false; } inline void setLowPriorityEventTracing(bool) { } + inline bool isLowPriorityEventTracing() { return false; } inline void setContextSwitchLogFilename(const char*) { } inline const char* getContextSwitchLogFilename() { return ""; } inline void startListen(uint16_t = ::profiler::DEFAULT_PORT) { } inline void stopListen() { } + inline bool isListening() { return false; } inline uint8_t versionMajor() { return 0; } inline uint8_t versionMinor() { return 0; } inline uint16_t versionPatch() { return 0; } diff --git a/easy_profiler_core/profile_manager.cpp b/easy_profiler_core/profile_manager.cpp index 6a460a2..9069027 100644 --- a/easy_profiler_core/profile_manager.cpp +++ b/easy_profiler_core/profile_manager.cpp @@ -201,6 +201,11 @@ extern "C" { MANAGER.setEnabled(isEnable); } + PROFILER_API bool isEnabled() + { + return MANAGER.isEnabled(); + } + PROFILER_API void storeEvent(const BaseBlockDescriptor* _desc, const char* _runtimeName) { MANAGER.storeBlock(_desc, _runtimeName); @@ -231,13 +236,24 @@ extern "C" { MANAGER.setEventTracingEnabled(_isEnable); } + PROFILER_API bool isEventTracingEnabled() + { + return MANAGER.isEventTracingEnabled(); + } + # ifdef _WIN32 PROFILER_API void setLowPriorityEventTracing(bool _isLowPriority) { EasyEventTracer::instance().setLowPriority(_isLowPriority); } + + PROFILER_API bool isLowPriorityEventTracing() + { + return EasyEventTracer::instance().isLowPriorityEventTracing(); + } # else PROFILER_API void setLowPriorityEventTracing(bool) { } + PROFILER_API bool isLowPriorityEventTracing() { return false; } # endif PROFILER_API void setContextSwitchLogFilename(const char* name) @@ -259,21 +275,30 @@ extern "C" { { return MANAGER.stopListen(); } + + PROFILER_API bool isListening() + { + return MANAGER.isListening(); + } #else PROFILER_API const BaseBlockDescriptor* registerDescription(EasyBlockStatus, const char*, const char*, const char*, int, block_type_t, color_t, bool) { return reinterpret_cast(0xbad); } PROFILER_API void endBlock() { } PROFILER_API void setEnabled(bool) { } + PROFILER_API bool isEnabled() { return false; } PROFILER_API void storeEvent(const BaseBlockDescriptor*, const char*) { } PROFILER_API void beginBlock(Block&) { } PROFILER_API uint32_t dumpBlocksToFile(const char*) { return 0; } PROFILER_API const char* registerThreadScoped(const char*, ThreadGuard&) { return ""; } PROFILER_API const char* registerThread(const char*) { return ""; } PROFILER_API void setEventTracingEnabled(bool) { } + PROFILER_API bool isEventTracingEnabled() { return false; } PROFILER_API void setLowPriorityEventTracing(bool) { } + PROFILER_API bool isLowPriorityEventTracing(bool) { return false; } PROFILER_API void setContextSwitchLogFilename(const char*) { } PROFILER_API const char* getContextSwitchLogFilename() { return ""; } PROFILER_API void startListen(uint16_t) { } PROFILER_API void stopListen() { } + PROFILER_API bool isListening() { } #endif PROFILER_API uint8_t versionMajor() @@ -823,9 +848,19 @@ void ProfileManager::setEnabled(bool isEnable) } } +bool ProfileManager::isEnabled() const +{ + return m_profilerStatus.load(std::memory_order_acquire) == EASY_PROF_ENABLED; +} + void ProfileManager::setEventTracingEnabled(bool _isEnable) { - m_isEventTracingEnabled.store(_isEnable, std::memory_order_release); + m_isEventTracingEnabled.store(_isEnable, std::memory_order_acquire); +} + +bool ProfileManager::isEventTracingEnabled() const +{ + return m_isEventTracingEnabled.load(std::memory_order_acquire); } ////////////////////////////////////////////////////////////////////////// @@ -1193,6 +1228,11 @@ void ProfileManager::stopListen() EASY_LOGMSG("Listening stopped\n"); } +bool ProfileManager::isListening() const +{ + return m_isAlreadyListening.load(std::memory_order_acquire); +} + ////////////////////////////////////////////////////////////////////////// void ProfileManager::listen(uint16_t _port) @@ -1423,5 +1463,6 @@ void ProfileManager::listen(uint16_t _port) } } + ////////////////////////////////////////////////////////////////////////// diff --git a/easy_profiler_core/profile_manager.h b/easy_profiler_core/profile_manager.h index 0c6d437..446352c 100644 --- a/easy_profiler_core/profile_manager.h +++ b/easy_profiler_core/profile_manager.h @@ -402,7 +402,9 @@ public: void beginBlock(profiler::Block& _block); void endBlock(); void setEnabled(bool isEnable); + bool isEnabled() const; void setEventTracingEnabled(bool _isEnable); + bool isEventTracingEnabled() const; uint32_t dumpBlocksToFile(const char* filename); const char* registerThread(const char* name, profiler::ThreadGuard& threadGuard); const char* registerThread(const char* name); @@ -421,6 +423,7 @@ public: void endContextSwitch(profiler::thread_id_t _thread_id, processid_t _process_id, profiler::timestamp_t _endtime, bool _lockSpin = true); void startListen(uint16_t _port); void stopListen(); + bool isListening() const; private: