0
0
mirror of https://github.com/yse/easy_profiler.git synced 2024-12-27 08:41:02 +08:00

startListen fixes

This commit is contained in:
Victor Zarubkin 2016-12-01 23:30:43 +03:00
parent 80ebd76116
commit e7db63e7d3
3 changed files with 15 additions and 15 deletions

View File

@ -556,7 +556,7 @@ namespace profiler {
*/
PROFILER_API const char* getContextSwitchLogFilename();
PROFILER_API void startListen(uint16_t _port = profiler::DEFAULT_PORT);
PROFILER_API void startListen(uint16_t _port = ::profiler::DEFAULT_PORT);
PROFILER_API void stopListen();
/** Returns current major version.
@ -604,7 +604,7 @@ namespace profiler {
inline void setLowPriorityEventTracing(bool) { }
inline void setContextSwitchLogFilename(const char*) { }
inline const char* getContextSwitchLogFilename() { return ""; }
inline void startListen(uint16_t _port = profiler::DEFAULT_PORT) { }
inline void startListen(uint16_t = ::profiler::DEFAULT_PORT) { }
inline void stopListen() { }
inline uint8_t versionMajor() { return 0; }
inline uint8_t versionMinor() { return 0; }

View File

@ -175,12 +175,12 @@ extern "C" {
PROFILER_API void startListen(uint16_t _port)
{
return MANAGER.startListenSignalToCapture(_port);
return MANAGER.startListen(_port);
}
PROFILER_API void stopListen()
{
return MANAGER.stopListenSignalToCapture();
return MANAGER.stopListen();
}
#else
PROFILER_API const BaseBlockDescriptor* registerDescription(EasyBlockStatus, const char*, const char*, const char*, int, block_type_t, color_t) { return reinterpret_cast<const BaseBlockDescriptor*>(0xbad); }
@ -195,8 +195,8 @@ extern "C" {
PROFILER_API void setLowPriorityEventTracing(bool) { }
PROFILER_API void setContextSwitchLogFilename(const char*) { }
PROFILER_API const char* getContextSwitchLogFilename() { return ""; }
PROFILER_API void startListenSignalToCapture() { }
PROFILER_API void stopListenSignalToCapture() { }
PROFILER_API void startListen(uint16_t) { }
PROFILER_API void stopListen() { }
#endif
PROFILER_API uint8_t versionMajor()
@ -396,13 +396,14 @@ ProfileManager::ProfileManager()
{
m_isEnabled = ATOMIC_VAR_INIT(false);
m_isEventTracingEnabled = ATOMIC_VAR_INIT(EASY_EVENT_TRACING_ENABLED);
m_isAlreadyListening = ATOMIC_VAR_INIT(false);
m_stopListen = ATOMIC_VAR_INIT(false);
}
ProfileManager::~ProfileManager()
{
#ifndef EASY_PROFILER_API_DISABLED
stopListenSignalToCapture();
stopListen();
#endif
for (auto desc : m_descriptors)
@ -909,22 +910,21 @@ void ProfileManager::setBlockStatus(block_id_t _id, EasyBlockStatus _status)
}
}
void ProfileManager::startListenSignalToCapture(uint16_t _port)
void ProfileManager::startListen(uint16_t _port)
{
if (!m_isAlreadyListened)
if (!m_isAlreadyListening.exchange(true, std::memory_order_release))
{
m_stopListen.store(false, std::memory_order_release);
m_listenThread = std::move(std::thread(&ProfileManager::listen, this, _port));
m_isAlreadyListened = true;
}
}
void ProfileManager::stopListenSignalToCapture()
void ProfileManager::stopListen()
{
m_stopListen.store(true, std::memory_order_release);
if (m_listenThread.joinable())
m_listenThread.join();
m_isAlreadyListened = false;
m_isAlreadyListening.store(false, std::memory_order_release);
}
//////////////////////////////////////////////////////////////////////////

View File

@ -360,6 +360,7 @@ class ProfileManager
profiler::spin_lock m_storedSpin;
std::atomic_bool m_isEnabled;
std::atomic_bool m_isEventTracingEnabled;
std::atomic_bool m_isAlreadyListening;
std::string m_csInfoFilename = "/tmp/cs_profiling_info.log";
@ -367,7 +368,6 @@ class ProfileManager
void setBlockStatus(profiler::block_id_t _id, profiler::EasyBlockStatus _status);
std::thread m_listenThread;
bool m_isAlreadyListened = false;
void listen(uint16_t _port);
int m_socket = 0;//TODO crossplatform
@ -409,8 +409,8 @@ public:
void beginContextSwitch(profiler::thread_id_t _thread_id, profiler::timestamp_t _time, profiler::thread_id_t _target_thread_id, const char* _target_process, bool _lockSpin = true);
void storeContextSwitch(profiler::thread_id_t _thread_id, profiler::timestamp_t _time, profiler::thread_id_t _target_thread_id, bool _lockSpin = true);
void endContextSwitch(profiler::thread_id_t _thread_id, profiler::timestamp_t _endtime, bool _lockSpin = true);
void startListenSignalToCapture(uint16_t _port);
void stopListenSignalToCapture();
void startListen(uint16_t _port);
void stopListen();
private: