diff --git a/include/easy/profiler.h b/include/easy/profiler.h index fc4a68f..ba7defa 100644 --- a/include/easy/profiler.h +++ b/include/easy/profiler.h @@ -556,8 +556,8 @@ namespace profiler { */ PROFILER_API const char* getContextSwitchLogFilename(); - PROFILER_API void startListenSignalToCapture(); - PROFILER_API void stopListenSignalToCapture(); + PROFILER_API void startListen(uint16_t _port = profiler::DEFAULT_PORT); + PROFILER_API void stopListen(); /** Returns current major version. @@ -604,8 +604,8 @@ namespace profiler { inline void setLowPriorityEventTracing(bool) { } inline void setContextSwitchLogFilename(const char*) { } inline const char* getContextSwitchLogFilename() { return ""; } - inline void startListenSignalToCapture() { } - inline void stopListenSignalToCapture() { } + inline void startListen(uint16_t _port = profiler::DEFAULT_PORT) { } + inline void stopListen() { } inline uint8_t versionMajor() { return 0; } inline uint8_t versionMinor() { return 0; } inline uint16_t versionPatch() { return 0; } diff --git a/sample/main.cpp b/sample/main.cpp index d9bd21d..8fa03b9 100644 --- a/sample/main.cpp +++ b/sample/main.cpp @@ -207,7 +207,7 @@ int main(int argc, char* argv[]) #endif EASY_MAIN_THREAD; - profiler::startListenSignalToCapture(); + profiler::startListen(); std::vector threads; for (int i=0; i < 3; i++) { diff --git a/scripts/context_switch_logger.stp b/scripts/context_switch_logger.stp index b9f8c7a..1ced532 100644 --- a/scripts/context_switch_logger.stp +++ b/scripts/context_switch_logger.stp @@ -14,7 +14,8 @@ probe scheduler.ctxswitch { next //printf("Switch from %d(%s) to %d(%s) at %d\n",prev_tid, prev_task_name,next_tid,next_task_name, gettimeofday_ns()) - printf("%d %d %d\n",gettimeofday_ns(),prev_tid, next_tid ) + printf("%d %d %d %s\n",gettimeofday_ns(),prev_tid, next_tid, next_task_name ) + //printf("%d %d %d\n",gettimeofday_ns(),prev_tid, next_tid ) } probe begin diff --git a/src/profile_manager.cpp b/src/profile_manager.cpp index b786521..458a044 100644 --- a/src/profile_manager.cpp +++ b/src/profile_manager.cpp @@ -173,12 +173,12 @@ extern "C" { return MANAGER.getContextSwitchLogFilename(); } - PROFILER_API void startListenSignalToCapture() + PROFILER_API void startListen(uint16_t _port) { - return MANAGER.startListenSignalToCapture(); + return MANAGER.startListenSignalToCapture(_port); } - PROFILER_API void stopListenSignalToCapture() + PROFILER_API void stopListen() { return MANAGER.stopListenSignalToCapture(); } @@ -727,8 +727,9 @@ uint32_t ProfileManager::dumpBlocksToStream(profiler::OStream& _outputStream) std::ifstream infile(m_csInfoFilename.c_str()); if(infile.is_open()) { - while (infile >> timestamp >> thread_from >> thread_to) { - beginContextSwitch(thread_from, timestamp, thread_to, "", false); + std::string next_task_name; + while (infile >> timestamp >> thread_from >> thread_to >> next_task_name) { + beginContextSwitch(thread_from, timestamp, thread_to, next_task_name.c_str(), false); endContextSwitch(thread_to, timestamp, false); } } @@ -908,12 +909,12 @@ void ProfileManager::setBlockStatus(block_id_t _id, EasyBlockStatus _status) } } -void ProfileManager::startListenSignalToCapture() +void ProfileManager::startListenSignalToCapture(uint16_t _port) { if (!m_isAlreadyListened) { m_stopListen.store(false, std::memory_order_release); - m_listenThread = std::move(std::thread(&ProfileManager::listen, this)); + m_listenThread = std::move(std::thread(&ProfileManager::listen, this, _port)); m_isAlreadyListened = true; } } @@ -930,14 +931,14 @@ void ProfileManager::stopListenSignalToCapture() //#define EASY_DEBUG_NET_PRINT -void ProfileManager::listen() +void ProfileManager::listen(uint16_t _port) { EASY_THREAD_SCOPE("EasyProfiler.Listen"); EasySocket socket; profiler::net::Message replyMessage(profiler::net::MESSAGE_TYPE_REPLY_START_CAPTURING); - socket.bind(profiler::DEFAULT_PORT); + socket.bind(_port); int bytes = 0; while (!m_stopListen.load(std::memory_order_acquire)) { diff --git a/src/profile_manager.h b/src/profile_manager.h index 114a68c..50285ae 100644 --- a/src/profile_manager.h +++ b/src/profile_manager.h @@ -368,7 +368,7 @@ class ProfileManager std::thread m_listenThread; bool m_isAlreadyListened = false; - void listen(); + void listen(uint16_t _port); int m_socket = 0;//TODO crossplatform @@ -409,7 +409,7 @@ 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(); + void startListenSignalToCapture(uint16_t _port); void stopListenSignalToCapture(); private: