From d9f621a5c612cfa361d6e4a22f15916a0fbc3b91 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Fri, 22 Jul 2022 18:36:49 +0200 Subject: [PATCH 01/17] Add Tracy as submodule --- .gitmodules | 3 +++ extensions/src/ACRE2Profiling/tracy | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 extensions/src/ACRE2Profiling/tracy diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..387a07f77 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "extensions/src/ACRE2Profiling/tracy"] + path = extensions/src/ACRE2Profiling/tracy + url = https://github.com/wolfpld/tracy.git diff --git a/extensions/src/ACRE2Profiling/tracy b/extensions/src/ACRE2Profiling/tracy new file mode 160000 index 000000000..f493d4aa8 --- /dev/null +++ b/extensions/src/ACRE2Profiling/tracy @@ -0,0 +1 @@ +Subproject commit f493d4aa8ba8141d9680473fad007d8a6348628e From 5df200cb3f975dfc174c00dfca2486a8b4e36c21 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Fri, 22 Jul 2022 20:18:59 +0200 Subject: [PATCH 02/17] Started integrating Tracy --- extensions/CMakeLists.txt | 2 + extensions/src/ACRE2Mumble/CMakeLists.txt | 2 +- .../MumbleCallbacks_channelEvents.cpp | 4 ++ .../src/ACRE2Mumble/MumbleCallbacks_init.cpp | 22 ++++++++++ .../MumbleCallbacks_pluginEvents.cpp | 6 +++ .../src/ACRE2Mumble/MumbleCallbacks_sound.cpp | 6 +++ .../ACRE2Mumble/MumbleCallbacks_speaking.cpp | 5 +++ extensions/src/ACRE2Mumble/MumbleClient.cpp | 42 ++++++++++++++++++ .../src/ACRE2Mumble/MumbleEventLoop.cpp | 44 +++++++++++++------ extensions/src/ACRE2Mumble/MumbleEventLoop.h | 1 + extensions/src/ACRE2Profiling/CMakeLists.txt | 23 ++++++++++ extensions/src/ACRE2TS/CMakeLists.txt | 2 +- 12 files changed, 143 insertions(+), 16 deletions(-) create mode 100644 extensions/src/ACRE2Profiling/CMakeLists.txt diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index 03d9dc0f2..fa219e86c 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -68,6 +68,8 @@ add_subdirectory(src/ACRE2Core) add_subdirectory(src/ACRE2Arma) add_subdirectory(src/ACRE2Steam) +add_subdirectory(src/ACRE2Profiling) + add_subdirectory(src/ACRE2TS) add_subdirectory(src/ACRE2Mumble) diff --git a/extensions/src/ACRE2Mumble/CMakeLists.txt b/extensions/src/ACRE2Mumble/CMakeLists.txt index 26a5ab283..0c3a80c1b 100644 --- a/extensions/src/ACRE2Mumble/CMakeLists.txt +++ b/extensions/src/ACRE2Mumble/CMakeLists.txt @@ -11,7 +11,7 @@ file(GLOB_RECURSE SOURCES *.h *.hpp *.c *.cpp *.asm mumble_includes/*) include_directories(mumble_includes) add_library( ${ACRE_NAME} MODULE ${SOURCES} ${GLOBAL_SOURCES}) -target_link_libraries(${ACRE_NAME} ACRE2Core ACRE2Shared x3daudio) +target_link_libraries(${ACRE_NAME} ACRE2Core ACRE2Shared ACRE2Profiling x3daudio) set_target_properties(${ACRE_NAME} PROPERTIES FOLDER ACRE2 LINK_FLAGS -SAFESEH:NO) target_compile_features(${ACRE_NAME} PRIVATE cxx_std_17) diff --git a/extensions/src/ACRE2Mumble/MumbleCallbacks_channelEvents.cpp b/extensions/src/ACRE2Mumble/MumbleCallbacks_channelEvents.cpp index 46e2d2721..64489a93d 100644 --- a/extensions/src/ACRE2Mumble/MumbleCallbacks_channelEvents.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCallbacks_channelEvents.cpp @@ -5,11 +5,15 @@ #include "Types.h" #include "compat.h" +#include + extern MumbleAPI_v_1_0_x mumAPI; extern mumble_connection_t activeConnection; extern mumble_plugin_id_t pluginID; void mumble_onChannelRenamed(mumble_connection_t connection, mumble_channelid_t channelID) { + ZoneScoped; + (void) connection; (void) channelID; CEngine::getInstance()->getClient()->updateShouldSwitchChannel(true); diff --git a/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp b/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp index 80ea6abf2..7f5b17ece 100644 --- a/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp @@ -7,9 +7,13 @@ #include "compat.h" #include "helpers.h" +#include + #define FROM_PIPENAME "\\\\.\\pipe\\acre_comm_pipe_fromTS" #define TO_PIPENAME "\\\\.\\pipe\\acre_comm_pipe_toTS" +const char *mumbleThreadName = "Mumble main thread"; + extern MumbleAPI_v_1_0_x mumAPI; mumble_connection_t activeConnection = -1; mumble_plugin_id_t pluginID = -1; @@ -23,6 +27,10 @@ void mumble_registerAPIFunctions(void *apiStruct) { } mumble_error_t mumble_init(mumble_plugin_id_t id) { + ZoneScoped; + + tracy::SetThreadName(mumbleThreadName); + pluginID = id; acre::MumbleEventLoop::getInstance().start(); @@ -49,7 +57,13 @@ mumble_error_t mumble_init(mumble_plugin_id_t id) { } void mumble_onServerSynchronized(mumble_connection_t connection) { + ZoneScoped; + + tracy::SetThreadName(mumbleThreadName); + acre::MumbleEventLoop::getInstance().queue([connection]() { + ZoneScoped; + activeConnection = connection; // set ID on every new connection @@ -66,7 +80,11 @@ void mumble_onServerSynchronized(mumble_connection_t connection) { } void mumble_onServerDisconnected(mumble_connection_t connection) { + ZoneScoped; + acre::MumbleEventLoop::getInstance().queue([connection]() { + ZoneScoped; + activeConnection = -1; if ((CEngine::getInstance()->getClient()->getState() != acre::State::stopped) && @@ -77,7 +95,11 @@ void mumble_onServerDisconnected(mumble_connection_t connection) { } void mumble_shutdown() { + ZoneScoped; + acre::MumbleEventLoop::getInstance().queue([]() { + ZoneScoped; + if ((CEngine::getInstance()->getClient()->getState() != acre::State::stopped) && (CEngine::getInstance()->getClient()->getState() != acre::State::stopping)) { CEngine::getInstance()->getClient()->stop(); diff --git a/extensions/src/ACRE2Mumble/MumbleCallbacks_pluginEvents.cpp b/extensions/src/ACRE2Mumble/MumbleCallbacks_pluginEvents.cpp index 035c16b87..9244c12aa 100644 --- a/extensions/src/ACRE2Mumble/MumbleCallbacks_pluginEvents.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCallbacks_pluginEvents.cpp @@ -4,14 +4,20 @@ #include "MumbleEventLoop.h" #include "compat.h" +#include + // // Handle a command event // bool mumble_onReceiveData(mumble_connection_t connection, mumble_userid_t sender, const uint8_t *data, size_t dataLength, const char *dataID) { + ZoneScoped; + if ((dataLength > 0U) && CEngine::getInstance()->getExternalServer()) { // Copy data to make sure it stays available in the async processing std::string dataString(reinterpret_cast(data), dataLength); acre::MumbleEventLoop::getInstance().queue([dataString]() { + ZoneScoped; + CEngine::getInstance()->getExternalServer()->handleMessage((unsigned char *)dataString.data(), dataString.size()); }); return true; diff --git a/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp b/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp index 6022f882e..d1e9d3b07 100644 --- a/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp @@ -6,6 +6,8 @@ #include "Wave.h" #include "compat.h" +#include + #include #define _USE_MATH_DEFINES @@ -17,6 +19,8 @@ using LIMITER = std::numeric_limits; bool mumble_onAudioSourceFetched(float *outputPCM, uint32_t sampleCount, uint16_t channelCount, uint32_t sampleRate, bool isSpeech, mumble_userid_t userID) { + ZoneScoped; + (void) sampleRate; if (CEngine::getInstance()->getSoundSystemOverride()) { @@ -104,6 +108,8 @@ bool mumble_onAudioSourceFetched(float *outputPCM, uint32_t sampleCount, uint16_ } bool mumble_onAudioOutputAboutToPlay(float *outputPCM, uint32_t sampleCount, uint16_t channelCount, uint32_t sampleRate) { + ZoneScoped; + (void) sampleRate; if (CEngine::getInstance()->getSoundSystemOverride()) { diff --git a/extensions/src/ACRE2Mumble/MumbleCallbacks_speaking.cpp b/extensions/src/ACRE2Mumble/MumbleCallbacks_speaking.cpp index 2fe03c5b2..22fc57ab4 100644 --- a/extensions/src/ACRE2Mumble/MumbleCallbacks_speaking.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCallbacks_speaking.cpp @@ -6,11 +6,16 @@ #include "Types.h" #include "compat.h" +#include // // Mumble Speaking callbacks // void mumble_onUserTalkingStateChanged(mumble_connection_t connection, mumble_userid_t userID, mumble_talking_state_t status) { + ZoneScoped; + acre::MumbleEventLoop::getInstance().queue([connection, userID, status]() { + ZoneScoped; + TRACE("mumble_onUserTalkingStateChanged ENTER: %d", status); if (static_cast(userID) != CEngine::getInstance()->getSelf()->getId()) { return; diff --git a/extensions/src/ACRE2Mumble/MumbleClient.cpp b/extensions/src/ACRE2Mumble/MumbleClient.cpp index d883b6076..5a719bf14 100644 --- a/extensions/src/ACRE2Mumble/MumbleClient.cpp +++ b/extensions/src/ACRE2Mumble/MumbleClient.cpp @@ -8,6 +8,8 @@ #include "compat.h" #include "shlobj.h" +#include + #pragma comment(lib, "Shlwapi.lib") static constexpr std::int32_t invalid_mumble_channel = -1; @@ -18,28 +20,38 @@ extern mumble_connection_t activeConnection; extern mumble_plugin_id_t pluginID; acre::Result CMumbleClient::initialize() { + ZoneScoped; + setPreviousChannel(invalid_mumble_channel); return acre::Result::ok; } acre::Result CMumbleClient::setMuted(const acre::id_t id_, const bool muted_) { + ZoneScoped; + (void) id_; (void) muted_; return acre::Result::ok; } acre::Result CMumbleClient::setMuted(std::list idList_, bool muted_) { + ZoneScoped; + (void) idList_; (void) muted_; return acre::Result::ok; } acre::Result CMumbleClient::getMuted(acre::id_t id_) { + ZoneScoped; + (void) id_; return acre::Result::ok; } acre::Result CMumbleClient::stop() { + ZoneScoped; + if (CEngine::getInstance() != nullptr) { CEngine::getInstance()->stop(); this->setState(acre::State::stopping); @@ -55,6 +67,8 @@ acre::Result CMumbleClient::stop() { } acre::Result CMumbleClient::start(const acre::id_t id_) { + ZoneScoped; + CEngine::getInstance()->start(id_); this->setInputActive(false); this->setDirectFirst(false); @@ -75,6 +89,8 @@ acre::Result CMumbleClient::start(const acre::id_t id_) { } bool CMumbleClient::getVAD() { + ZoneScoped; + mumble_transmission_mode_t transmitMode; const mumble_error_t err = mumAPI.getLocalUserTransmissionMode(pluginID, &transmitMode); if (err != MUMBLE_STATUS_OK) { @@ -85,11 +101,15 @@ bool CMumbleClient::getVAD() { } acre::Result CMumbleClient::localStartSpeaking(const acre::Speaking speakingType_) { + ZoneScoped; + this->localStartSpeaking(speakingType_, ""); return acre::Result::ok; } acre::Result CMumbleClient::localStartSpeaking(const acre::Speaking speakingType_, std::string radioId_) { + ZoneScoped; + bool stopDirectSpeaking = false; const bool VADactive = this->getVAD(); @@ -133,6 +153,8 @@ acre::Result CMumbleClient::localStartSpeaking(const acre::Speaking speakingType } acre::Result CMumbleClient::localStopSpeaking(const acre::Speaking speakingType_) { + ZoneScoped; + bool resendDirectSpeaking = false; const bool VADactive = this->getVAD(); @@ -205,11 +227,15 @@ acre::Result CMumbleClient::localStopSpeaking(const acre::Speaking speakingType_ } acre::Result CMumbleClient::enableMicrophone(const bool status_) { + ZoneScoped; + (void) status_; return acre::Result::ok; } acre::Result CMumbleClient::playSound(std::string path_, acre::vec3_fp32_t position_, const float32_t volume_, const int32_t looping_) { + ZoneScoped; + return acre::Result::ok; } @@ -239,6 +265,8 @@ std::string CMumbleClient::getTempFilePath(void) { } acre::Result CMumbleClient::microphoneOpen(bool status_) { + ZoneScoped; + const mumble_error_t res = mumAPI.requestMicrophoneActivationOvewrite(pluginID, status_); if (res != MUMBLE_STATUS_OK) { if (status_) { @@ -255,10 +283,14 @@ acre::Result CMumbleClient::microphoneOpen(bool status_) { } acre::Result CMumbleClient::unMuteAll(void) { + ZoneScoped; + return acre::Result::ok; } acre::Result CMumbleClient::moveToServerChannel() { + ZoneScoped; + TRACE("moveToServerChannel ENTER"); if (!CAcreSettings::getInstance()->getDisableChannelSwitch()) { mumble_userid_t clientId; @@ -289,6 +321,8 @@ acre::Result CMumbleClient::moveToServerChannel() { } acre::Result CMumbleClient::moveToPreviousChannel() { + ZoneScoped; + TRACE("moveToPreviousChannel ENTER"); if (!CAcreSettings::getInstance()->getDisableChannelSwitch()) { mumble_userid_t clientId = -1; @@ -310,6 +344,8 @@ acre::Result CMumbleClient::moveToPreviousChannel() { } uint64_t CMumbleClient::findChannelByNames(std::vector details_) { + ZoneScoped; + TRACE("findChannelByNames ENTER"); mumble_channelid_t *channelList = nullptr; std::size_t channelCount = 0U; @@ -383,6 +419,8 @@ uint64_t CMumbleClient::findChannelByNames(std::vector details_) { } acre::Result CMumbleClient::updateChannelDetails(std::vector details_) { + ZoneScoped; + setChannelDetails(details_); if (!details_.empty()) { updateShouldSwitchChannel(true); @@ -391,10 +429,14 @@ acre::Result CMumbleClient::updateChannelDetails(std::vector detail } acre::Result CMumbleClient::updateShouldSwitchChannel(const bool state_) { + ZoneScoped; + setShouldSwitchChannel(state_); return acre::Result::ok; } bool CMumbleClient::shouldSwitchChannel() { + ZoneScoped; + return getShouldSwitchChannel(); } diff --git a/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp b/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp index ae49effba..215a5b35f 100644 --- a/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp +++ b/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp @@ -1,5 +1,7 @@ #include "MumbleEventLoop.h" +#include + namespace acre { MumbleEventLoop& MumbleEventLoop::getInstance() { @@ -25,9 +27,12 @@ namespace acre { } void MumbleEventLoop::stop() { + ZoneScoped; + { std::lock_guard guard(m_lock); m_keepRunning = false; + m_drain = true; m_waiter.notify_all(); } @@ -39,6 +44,8 @@ namespace acre { } void MumbleEventLoop::queue(const std::function& callable) { + ZoneScoped; + std::lock_guard guard(m_lock); m_queuedFunctions.push_back(callable); @@ -47,6 +54,8 @@ namespace acre { } void MumbleEventLoop::queue(std::function&& callable) { + ZoneScoped; + std::unique_lock guard(m_lock); m_queuedFunctions.push_back(std::move(callable)); @@ -55,22 +64,29 @@ namespace acre { } void MumbleEventLoop::run() { + tracy::SetThreadName("ACRE2-Mumble-EventLoop"); + std::unique_lock guard(m_lock); - while (m_keepRunning) { - // Process all pending events - while (!m_queuedFunctions.empty()) { - std::function currentFunc = std::move(m_queuedFunctions.front()); - m_queuedFunctions.pop_front(); - - // Execute the current funtion. However, during the time this function is executing, there is no need to - // keep holding m_lock. By releasing it for that time, we allow further functions to be queued by other threads. - // This gets especially important if the called function will call a Mumble API function. This function will require - // to run in Mumble's main thread but if that thread is in turn waiting until a new event is queued (in one of the - // plugin callbacks in this plugin), we end up with a deadlock. - guard.unlock(); - currentFunc(); - guard.lock(); + while (m_keepRunning || m_drain) { + { + ZoneScopedN("MumbleEventLoop::run - process pending events"); + m_drain = false; + + // Process all pending events + while (!m_queuedFunctions.empty()) { + std::function currentFunc = std::move(m_queuedFunctions.front()); + m_queuedFunctions.pop_front(); + + // Execute the current funtion. However, during the time this function is executing, there is no need to + // keep holding m_lock. By releasing it for that time, we allow further functions to be queued by other threads. + // This gets especially important if the called function will call a Mumble API function. This function will require + // to run in Mumble's main thread but if that thread is in turn waiting until a new event is queued (in one of the + // plugin callbacks in this plugin), we end up with a deadlock. + guard.unlock(); + currentFunc(); + guard.lock(); + } } if (!m_keepRunning) { diff --git a/extensions/src/ACRE2Mumble/MumbleEventLoop.h b/extensions/src/ACRE2Mumble/MumbleEventLoop.h index f46656bf0..6a3b14ada 100644 --- a/extensions/src/ACRE2Mumble/MumbleEventLoop.h +++ b/extensions/src/ACRE2Mumble/MumbleEventLoop.h @@ -42,6 +42,7 @@ namespace acre { std::mutex m_lock; std::condition_variable m_waiter; bool m_keepRunning = true; + bool m_drain = false; std::deque> m_queuedFunctions; std::thread m_thread; diff --git a/extensions/src/ACRE2Profiling/CMakeLists.txt b/extensions/src/ACRE2Profiling/CMakeLists.txt new file mode 100644 index 000000000..1cbce28e5 --- /dev/null +++ b/extensions/src/ACRE2Profiling/CMakeLists.txt @@ -0,0 +1,23 @@ +cmake_minimum_required (VERSION 3.0) + +option(USE_TRACY "USE_TRACY" OFF) + +set(ACRE_NAME "ACRE2Profiling") + +acre_set_linker_options() + +file(GLOB SOURCES *.h *.hpp *.c *.cpp) + +add_library( ${ACRE_NAME} STATIC ${SOURCES} ${GLOBAL_SOURCES} ${DSP_SOURCES}) +target_link_libraries( ${ACRE_NAME} ) +set_target_properties(${ACRE_NAME} PROPERTIES FOLDER ACRE2) + +if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tracy/CMakeLists.txt") + message(FATAL_ERROR "Unable to locate tracy submodule - did you forget to run git submodule update --init?") +endif() + +set(TRACY_ENABLE ${USE_TRACY} CACHE BOOL "" FORCE) +set(TRACY_ON_DEMAND ON CACHE BOOL "" FORCE) +add_subdirectory("tracy") + +target_link_libraries( ${ACRE_NAME} Tracy::TracyClient) \ No newline at end of file diff --git a/extensions/src/ACRE2TS/CMakeLists.txt b/extensions/src/ACRE2TS/CMakeLists.txt index bfbb0e4c0..bf1ceb84d 100644 --- a/extensions/src/ACRE2TS/CMakeLists.txt +++ b/extensions/src/ACRE2TS/CMakeLists.txt @@ -11,7 +11,7 @@ file(GLOB_RECURSE SOURCES *.h *.hpp *.c *.cpp *.asm inc/*) include_directories(inc) add_library( ${ACRE_NAME} MODULE ${SOURCES} ${GLOBAL_SOURCES}) -target_link_libraries(${ACRE_NAME} ACRE2Core ACRE2Shared x3daudio) +target_link_libraries(${ACRE_NAME} ACRE2Core ACRE2Shared ACRE2Profiling x3daudio) set_target_properties(${ACRE_NAME} PROPERTIES FOLDER ACRE2 LINK_FLAGS -SAFESEH:NO) target_compile_features(${ACRE_NAME} PRIVATE cxx_std_17) From d15a3c9961c1765528e59e108bc5a073d661ff80 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Fri, 22 Jul 2022 20:53:13 +0200 Subject: [PATCH 03/17] Extended Tracy integration --- extensions/src/ACRE2Core/CMakeLists.txt | 2 +- extensions/src/ACRE2Core/Engine.cpp | 18 ++++++++++++++++++ extensions/src/ACRE2Core/NamedPipeServer.cpp | 5 +++++ extensions/src/ACRE2Core/RpcEngine.cpp | 16 ++++++++++++++++ .../src/ACRE2Mumble/MumbleCommandServer.cpp | 6 ++++++ 5 files changed, 46 insertions(+), 1 deletion(-) diff --git a/extensions/src/ACRE2Core/CMakeLists.txt b/extensions/src/ACRE2Core/CMakeLists.txt index 3f7489a8e..48cb77b0b 100644 --- a/extensions/src/ACRE2Core/CMakeLists.txt +++ b/extensions/src/ACRE2Core/CMakeLists.txt @@ -8,5 +8,5 @@ file(GLOB SOURCES *.h *.hpp *.c *.cpp) file(GLOB DSP_SOURCES DspFilters/*.h DspFilters/*.hpp DspFilters/*.c DspFilters/*.cpp) add_library( ${ACRE_NAME} STATIC ${SOURCES} ${GLOBAL_SOURCES} ${DSP_SOURCES}) -target_link_libraries( ${ACRE_NAME} ACRE2Shared) +target_link_libraries( ${ACRE_NAME} ACRE2Shared ACRE2Profiling) set_target_properties(${ACRE_NAME} PROPERTIES FOLDER ACRE2) diff --git a/extensions/src/ACRE2Core/Engine.cpp b/extensions/src/ACRE2Core/Engine.cpp index d8f329c75..0a0b5a6e2 100644 --- a/extensions/src/ACRE2Core/Engine.cpp +++ b/extensions/src/ACRE2Core/Engine.cpp @@ -31,7 +31,10 @@ #include "setChannelDetails.h" #include +#include + acre::Result CEngine::initialize(IClient *client, IServer *externalServer, std::string fromPipeName, std::string toPipeName) { + ZoneScoped; if (!g_Log) { std::string acrePluginLog{"acre2_plugin.log"}; @@ -92,6 +95,7 @@ acre::Result CEngine::initialize(IClient *client, IServer *externalServer, std:: } acre::Result CEngine::initialize(IClient *client, IServer *externalServer, std::string fromPipeName, std::string toPipeName, std::string loggingPath) { + ZoneScoped; g_Log = (Log *)new Log(const_cast(loggingPath.c_str())); LOG("* Logging engine initialized."); @@ -100,6 +104,8 @@ acre::Result CEngine::initialize(IClient *client, IServer *externalServer, std:: } acre::Result CEngine::start(const acre::id_t id) { + ZoneScoped; + if (this->getExternalServer()) { this->getExternalServer()->initialize(); } else { @@ -124,6 +130,8 @@ acre::Result CEngine::start(const acre::id_t id) { } acre::Result CEngine::stop() { + ZoneScoped; + LOG("Engine Shutting Down"); this->setState(acre::State::stopping); @@ -152,11 +160,15 @@ acre::Result CEngine::stop() { } acre::Result CEngine::localStartSpeaking(const acre::Speaking speakingType) { + ZoneScoped; + this->localStartSpeaking(speakingType, ""); return acre::Result::ok; } acre::Result CEngine::localStartSpeaking(const acre::Speaking speakingType, const std::string radioId) { + ZoneScoped; + // send a start speaking event to everyone TRACE("Local START speaking: %d, %s", speakingType, radioId.c_str()); this->getSelf()->lock(); @@ -192,6 +204,8 @@ acre::Result CEngine::localStartSpeaking(const acre::Speaking speakingType, cons } acre::Result CEngine::localStopSpeaking( void ) { + ZoneScoped; + this->getSelf()->setSpeaking(false); CEngine::getInstance()->getExternalServer()->sendMessage( CTextMessage::formatNewMessage("ext_remoteStopSpeaking", @@ -213,6 +227,8 @@ acre::Result CEngine::localStopSpeaking( void ) { } acre::Result CEngine::remoteStartSpeaking(const acre::id_t remoteId, const int32_t languageId, const std::string netId, const acre::Speaking speakingType, const std::string radioId, const acre::volume_t curveScale) { + ZoneScoped; + TRACE("Remote Start Speaking Enter: %d, %d", remoteId, speakingType); auto it = this->speakingList.find(remoteId); if (it != this->speakingList.end()) { @@ -241,6 +257,8 @@ acre::Result CEngine::remoteStartSpeaking(const acre::id_t remoteId, const int32 } acre::Result CEngine::remoteStopSpeaking(const acre::id_t remoteId) { + ZoneScoped; + TRACE("Remote STOP Speaking Enter: %d", remoteId); auto it = this->speakingList.find(remoteId); if (it != this->speakingList.end()) { diff --git a/extensions/src/ACRE2Core/NamedPipeServer.cpp b/extensions/src/ACRE2Core/NamedPipeServer.cpp index 2da726fc6..619d2faa8 100644 --- a/extensions/src/ACRE2Core/NamedPipeServer.cpp +++ b/extensions/src/ACRE2Core/NamedPipeServer.cpp @@ -4,6 +4,7 @@ #include "Log.h" #include "Engine.h" +#include @@ -24,6 +25,8 @@ CNamedPipeServer::~CNamedPipeServer( void ) { } acre::Result CNamedPipeServer::initialize() { + ZoneScoped; + HANDLE writeHandle, readHandle; SECURITY_DESCRIPTOR sd; @@ -105,6 +108,8 @@ acre::Result CNamedPipeServer::initialize() { } acre::Result CNamedPipeServer::shutdown(void) { + ZoneScoped; + HANDLE hPipe; this->setShuttingDown(true); diff --git a/extensions/src/ACRE2Core/RpcEngine.cpp b/extensions/src/ACRE2Core/RpcEngine.cpp index 1c79b9bee..e6d21e94d 100644 --- a/extensions/src/ACRE2Core/RpcEngine.cpp +++ b/extensions/src/ACRE2Core/RpcEngine.cpp @@ -12,10 +12,14 @@ #include "Log.h" #include +#include + // // Entrant worker, weee // acre::Result CRpcEngine::exProcessItem(ACRE_RPCDATA *data) { + ZoneScoped; + if (data->function != nullptr) { data->function->call(data->server, data->message); } @@ -29,6 +33,8 @@ acre::Result CRpcEngine::exProcessItem(ACRE_RPCDATA *data) { // Proc functions // acre::Result CRpcEngine::addProcedure(IRpcFunction *const cmd) { + ZoneScoped; + LOCK(this); this->m_FunctionList.insert(std::pair(std::string(cmd->getName()), cmd)); UNLOCK(this); @@ -36,6 +42,8 @@ acre::Result CRpcEngine::addProcedure(IRpcFunction *const cmd) { return acre::Result::ok; } acre::Result CRpcEngine::removeProcedure(IRpcFunction *const cmd) { + ZoneScoped; + LOCK(this); this->m_FunctionList.erase(cmd->getName()); UNLOCK(this); @@ -43,6 +51,8 @@ acre::Result CRpcEngine::removeProcedure(IRpcFunction *const cmd) { return acre::Result::ok; } acre::Result CRpcEngine::removeProcedure(char *const cmd) { + ZoneScoped; + LOCK(this); this->m_FunctionList.erase(cmd); UNLOCK(this); @@ -50,6 +60,8 @@ acre::Result CRpcEngine::removeProcedure(char *const cmd) { return acre::Result::ok; } IRpcFunction *CRpcEngine::findProcedure(char *const cmd) { + ZoneScoped; + if (this->getShuttingDown()) { return nullptr; @@ -62,11 +74,15 @@ IRpcFunction *CRpcEngine::findProcedure(char *const cmd) { return nullptr; } + acre::Result CRpcEngine::runProcedure(IServer *const serverInstance, IMessage *msg) { + ZoneScoped; + return this->runProcedure(serverInstance, msg, TRUE); } acre::Result CRpcEngine::runProcedure(IServer *const serverInstance, IMessage *msg, const bool entrant) { + ZoneScoped; if (msg == nullptr) { return acre::Result::error; diff --git a/extensions/src/ACRE2Mumble/MumbleCommandServer.cpp b/extensions/src/ACRE2Mumble/MumbleCommandServer.cpp index 2729f6d16..e8e974cd2 100644 --- a/extensions/src/ACRE2Mumble/MumbleCommandServer.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCommandServer.cpp @@ -4,6 +4,8 @@ #include "MumbleFunctions.h" #include "TextMessage.h" +#include + #include extern MumbleAPI_v_1_0_x mumAPI; @@ -23,6 +25,8 @@ acre::Result CMumbleCommandServer::shutdown() { } acre::Result CMumbleCommandServer::sendMessage(IMessage *msg) { + ZoneScoped; + std::lock_guard guard(*this); mumble_userid_t *channelUsers = nullptr; @@ -62,6 +66,8 @@ acre::Result CMumbleCommandServer::handleMessage(unsigned char *data) { } acre::Result CMumbleCommandServer::handleMessage(unsigned char *data, size_t length) { + ZoneScoped; + CTextMessage *msg = nullptr; // TRACE("recv: [%s]", data); msg = new (std::nothrow) CTextMessage((char *) data, length); From 056b66ffbffd685a3b580adef9e12b3f8239f4aa Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 23 Jul 2022 09:16:18 +0200 Subject: [PATCH 04/17] Fix inaccessible config path in Mumble plugin --- extensions/src/ACRE2Mumble/MumbleClient.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/extensions/src/ACRE2Mumble/MumbleClient.cpp b/extensions/src/ACRE2Mumble/MumbleClient.cpp index 5a719bf14..bc1661798 100644 --- a/extensions/src/ACRE2Mumble/MumbleClient.cpp +++ b/extensions/src/ACRE2Mumble/MumbleClient.cpp @@ -244,7 +244,13 @@ std::string CMumbleClient::getUniqueId() { } std::string CMumbleClient::getConfigFilePath(void) { - std::string tempFolder = ".\\acre"; + // For the time being Mumble doesn't expose a config file path via its API, so we just fall back + // to using a sub-directory in Arma 3's AppData directory + std::string tempFolder = "acre"; + std::array appDataPath{""}; + if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_LOCAL_APPDATA, NULL, 0, appDataPath.data()))) { + tempFolder = std::string(appDataPath.data()) + "\\Arma 3\\" + tempFolder; + } if (!PathFileExistsA(tempFolder.c_str()) && !CreateDirectoryA(tempFolder.c_str(), nullptr)) { LOG("ERROR: UNABLE TO CREATE TEMP DIR"); } From 8234508bf0ac9225504e409dc9b91972f34dec62 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 23 Jul 2022 09:52:45 +0200 Subject: [PATCH 05/17] Yet more Tracy integration --- extensions/src/ACRE2Core/NamedPipeServer.cpp | 115 ++++++++++-------- .../src/ACRE2Core/ext_handleGetClientID.h | 4 + .../src/ACRE2Core/ext_remoteStartSpeaking.h | 3 + .../src/ACRE2Core/ext_remoteStopSpeaking.h | 3 + extensions/src/ACRE2Core/ext_reset.h | 4 + extensions/src/ACRE2Core/getClientID.h | 3 + extensions/src/ACRE2Core/getPluginVersion.h | 3 + extensions/src/ACRE2Core/loadSound.h | 4 + extensions/src/ACRE2Core/localMute.h | 3 + extensions/src/ACRE2Core/ping.h | 4 + extensions/src/ACRE2Core/playSound.h | 3 + extensions/src/ACRE2Core/setChannelDetails.h | 4 + extensions/src/ACRE2Core/setMuted.h | 3 + extensions/src/ACRE2Core/setPTTKeys.h | 4 + .../src/ACRE2Core/setSelectableVoiceCurve.h | 4 + extensions/src/ACRE2Core/setSetting.h | 4 + .../ACRE2Core/setSoundSystemMasterOverride.h | 3 + extensions/src/ACRE2Core/setVoiceCurveModel.h | 4 + .../src/ACRE2Core/startGodModeSpeaking.h | 3 + .../src/ACRE2Core/startIntercomSpeaking.h | 3 + extensions/src/ACRE2Core/startRadioSpeaking.h | 3 + extensions/src/ACRE2Core/startZeusSpeaking.h | 3 + .../src/ACRE2Core/stopGodModeSpeaking.h | 3 + .../src/ACRE2Core/stopIntercomSpeaking.h | 3 + extensions/src/ACRE2Core/stopRadioSpeaking.h | 3 + extensions/src/ACRE2Core/stopZeusSpeaking.h | 3 + extensions/src/ACRE2Core/updateSelf.h | 3 + extensions/src/ACRE2Core/updateSpeakingData.h | 3 + extensions/src/ACRE2Profiling/CMakeLists.txt | 4 +- extensions/src/ACRE2Shared/CMakeLists.txt | 2 +- extensions/src/ACRE2Shared/EntrantWorker.h | 10 ++ 31 files changed, 170 insertions(+), 51 deletions(-) diff --git a/extensions/src/ACRE2Core/NamedPipeServer.cpp b/extensions/src/ACRE2Core/NamedPipeServer.cpp index 619d2faa8..e6d368b46 100644 --- a/extensions/src/ACRE2Core/NamedPipeServer.cpp +++ b/extensions/src/ACRE2Core/NamedPipeServer.cpp @@ -147,20 +147,26 @@ acre::Result CNamedPipeServer::shutdown(void) { } acre::Result CNamedPipeServer::sendLoop() { + ZoneScoped; + tracy::SetThreadName("NamedPipeServer::sendLoop"); + while (!this->getShuttingDown()) { - - do { - ConnectNamedPipe(this->m_PipeHandleWrite, NULL); - if (GetLastError() == ERROR_PIPE_CONNECTED) { - LOG("Client write connected"); - CEngine::getInstance()->getSoundEngine()->onClientGameConnected(); - this->setConnectedWrite(true); - break; - } else { - this->setConnectedWrite(false); - Sleep(1); - } - } while (!this->getConnectedWrite() && !this->getShuttingDown()); + { + ZoneScopedN("CNamedPipeServer::sendLoop - connecting write pipe"); + + do { + ConnectNamedPipe(this->m_PipeHandleWrite, NULL); + if (GetLastError() == ERROR_PIPE_CONNECTED) { + LOG("Client write connected"); + CEngine::getInstance()->getSoundEngine()->onClientGameConnected(); + this->setConnectedWrite(true); + break; + } else { + this->setConnectedWrite(false); + Sleep(1); + } + } while (!this->getConnectedWrite() && !this->getShuttingDown()); + } clock_t lastTick = clock() / CLOCKS_PER_SEC; while (this->getConnectedWrite()) { @@ -177,6 +183,8 @@ acre::Result CNamedPipeServer::sendLoop() { IMessage *msg = nullptr; if (this->m_sendQueue.try_pop(msg)) { if (msg != nullptr) { + ZoneScopedN("CNamedPipeServer::sendLoop - sending message"); + lastTick = clock() / CLOCKS_PER_SEC; const DWORD size = (DWORD)strlen((char *)msg->getData()) + 1; if (size > 3) { @@ -215,6 +223,9 @@ acre::Result CNamedPipeServer::sendLoop() { } acre::Result CNamedPipeServer::readLoop() { + ZoneScoped; + tracy::SetThreadName("NamedPipeServer::readLoop"); + DWORD cbRead; char *mBuffer = (char *)LocalAlloc(LMEM_FIXED, BUFSIZE); @@ -225,20 +236,25 @@ acre::Result CNamedPipeServer::readLoop() { this->validTSServers.insert(std::string("enter a ts3 server id here")); */ while (!this->getShuttingDown()) { - //this->checkServer(); - bool ret = ConnectNamedPipe(this->m_PipeHandleRead, NULL); - if (GetLastError() == ERROR_PIPE_CONNECTED) { - LOG("Client read connected"); - CEngine::getInstance()->getClient()->updateShouldSwitchChannel(false); - CEngine::getInstance()->getClient()->unMuteAll(); - CEngine::getInstance()->getSoundEngine()->onClientGameConnected(); - this->setConnectedRead(true); - } else { - this->setConnectedRead(false); - Sleep(1); + bool ret = false; + { + ZoneScopedN("CNamedPipeServer::readLoop - connecting read pipe"); + // this->checkServer(); + ret = ConnectNamedPipe(this->m_PipeHandleRead, NULL); + if (GetLastError() == ERROR_PIPE_CONNECTED) { + LOG("Client read connected"); + CEngine::getInstance()->getClient()->updateShouldSwitchChannel(false); + CEngine::getInstance()->getClient()->unMuteAll(); + CEngine::getInstance()->getSoundEngine()->onClientGameConnected(); + this->setConnectedRead(true); + } else { + this->setConnectedRead(false); + Sleep(1); - continue; + continue; + } } + clock_t lastTick = clock() / CLOCKS_PER_SEC; while (this->getConnectedRead()) { //this->checkServer(); @@ -261,29 +277,32 @@ acre::Result CNamedPipeServer::readLoop() { } ret = false; - do { - ret = ReadFile(this->m_PipeHandleRead, mBuffer, BUFSIZE - 1, &cbRead, NULL); // -1 for null-byte below - if (!ret && GetLastError() != ERROR_MORE_DATA) { - break; - } else if (!ret && GetLastError() == ERROR_BROKEN_PIPE) { - this->setConnectedRead(false); - break; - } - // handle the packet and run it - mBuffer[cbRead] = 0x00; - //LOG("READ: %s", (char *)mBuffer); - IMessage *const msg = new CTextMessage((char *)mBuffer, cbRead); - //TRACE("got and parsed message [%s]", msg->getData()); - if (msg != nullptr && msg->getProcedureName()) { - - // Do not free msg, this is deleted inside runProcedure() - CEngine::getInstance()->getRpcEngine()->runProcedure(this, msg); - - lastTick = clock() / CLOCKS_PER_SEC; - //TRACE("tick [%d], [%s]",lastTick, msg->getData()); - } - // wait 1ms for new msg so we dont hog cpu cycles - } while (!ret); + { + ZoneScopedN("CNamedPipeServer::readLoop - receiving messages"); + + do { + ret = ReadFile(this->m_PipeHandleRead, mBuffer, BUFSIZE - 1, &cbRead, NULL); // -1 for null-byte below + if (!ret && GetLastError() != ERROR_MORE_DATA) { + break; + } else if (!ret && GetLastError() == ERROR_BROKEN_PIPE) { + this->setConnectedRead(false); + break; + } + // handle the packet and run it + mBuffer[cbRead] = 0x00; + // LOG("READ: %s", (char *)mBuffer); + IMessage *const msg = new CTextMessage((char *) mBuffer, cbRead); + // TRACE("got and parsed message [%s]", msg->getData()); + if (msg != nullptr && msg->getProcedureName()) { + // Do not free msg, this is deleted inside runProcedure() + CEngine::getInstance()->getRpcEngine()->runProcedure(this, msg); + + lastTick = clock() / CLOCKS_PER_SEC; + // TRACE("tick [%d], [%s]",lastTick, msg->getData()); + } + // wait 1ms for new msg so we dont hog cpu cycles + } while (!ret); + } //ret = ConnectNamedPipe(this->getPipeHandle(), NULL); Sleep(1); } diff --git a/extensions/src/ACRE2Core/ext_handleGetClientID.h b/extensions/src/ACRE2Core/ext_handleGetClientID.h index 4b4da1ee2..4bcf811c0 100644 --- a/extensions/src/ACRE2Core/ext_handleGetClientID.h +++ b/extensions/src/ACRE2Core/ext_handleGetClientID.h @@ -11,7 +11,11 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(ext_handleGetClientID) { + ZoneScoped; + CEngine::getInstance()->getGameServer()->sendMessage( CTextMessage::formatNewMessage("handleGetClientID", "%d,%s,", diff --git a/extensions/src/ACRE2Core/ext_remoteStartSpeaking.h b/extensions/src/ACRE2Core/ext_remoteStartSpeaking.h index 6fe02c0ae..c80411f7d 100644 --- a/extensions/src/ACRE2Core/ext_remoteStartSpeaking.h +++ b/extensions/src/ACRE2Core/ext_remoteStartSpeaking.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(ext_remoteStartSpeaking) { + ZoneScoped; /*CTextMessage::formatNewMessage("ext_remoteStartSpeaking", "%d,%d,%s,%f,", diff --git a/extensions/src/ACRE2Core/ext_remoteStopSpeaking.h b/extensions/src/ACRE2Core/ext_remoteStopSpeaking.h index ccb4f6856..95db883ec 100644 --- a/extensions/src/ACRE2Core/ext_remoteStopSpeaking.h +++ b/extensions/src/ACRE2Core/ext_remoteStopSpeaking.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(ext_remoteStopSpeaking) { + ZoneScoped; /*CTextMessage::formatNewMessage("ext_remoteStartSpeaking", "%d,%d,%s,%f,", diff --git a/extensions/src/ACRE2Core/ext_reset.h b/extensions/src/ACRE2Core/ext_reset.h index 42781bc98..52c08e2ad 100644 --- a/extensions/src/ACRE2Core/ext_reset.h +++ b/extensions/src/ACRE2Core/ext_reset.h @@ -5,7 +5,11 @@ #include "Types.h" #include "Engine.h" +#include + RPC_FUNCTION(ext_reset) { + ZoneScoped; + const acre::id_t id = vMessage->getParameterAsInt(0); // diff --git a/extensions/src/ACRE2Core/getClientID.h b/extensions/src/ACRE2Core/getClientID.h index b1f678c5a..9aaf0fce2 100644 --- a/extensions/src/ACRE2Core/getClientID.h +++ b/extensions/src/ACRE2Core/getClientID.h @@ -12,7 +12,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(getClientID) { + ZoneScoped; TRACE("enter"); diff --git a/extensions/src/ACRE2Core/getPluginVersion.h b/extensions/src/ACRE2Core/getPluginVersion.h index 9b1e151a4..2203147df 100644 --- a/extensions/src/ACRE2Core/getPluginVersion.h +++ b/extensions/src/ACRE2Core/getPluginVersion.h @@ -3,7 +3,10 @@ #include "IServer.h" #include "TextMessage.h" +#include + RPC_FUNCTION(getPluginVersion) { + ZoneScoped; vServer->sendMessage(CTextMessage::formatNewMessage("handleGetPluginVersion", "%s", ACRE_VERSION)); diff --git a/extensions/src/ACRE2Core/loadSound.h b/extensions/src/ACRE2Core/loadSound.h index 879ca1e0c..37d788e66 100644 --- a/extensions/src/ACRE2Core/loadSound.h +++ b/extensions/src/ACRE2Core/loadSound.h @@ -11,7 +11,11 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(loadSound) { + ZoneScoped; + const std::string id = std::string((char *)vMessage->getParameter(0)); const int32_t currentCount = vMessage->getParameterAsInt(1); const int32_t totalCount = vMessage->getParameterAsInt(2); diff --git a/extensions/src/ACRE2Core/localMute.h b/extensions/src/ACRE2Core/localMute.h index 24d11df4d..21d0a66b2 100644 --- a/extensions/src/ACRE2Core/localMute.h +++ b/extensions/src/ACRE2Core/localMute.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(localMute) { + ZoneScoped; const bool status = vMessage->getParameterAsInt(0) == 1; diff --git a/extensions/src/ACRE2Core/ping.h b/extensions/src/ACRE2Core/ping.h index ab53984a6..d1179973c 100644 --- a/extensions/src/ACRE2Core/ping.h +++ b/extensions/src/ACRE2Core/ping.h @@ -7,9 +7,13 @@ #include "Engine.h" #include "TextMessage.h" +#include + volatile DWORD g_pingTime; RPC_FUNCTION(ping) { + ZoneScoped; + g_pingTime = clock() / CLOCKS_PER_SEC; vServer->sendMessage(CTextMessage::formatNewMessage("pong", "%f,", g_pingTime)); return acre::Result::ok; diff --git a/extensions/src/ACRE2Core/playSound.h b/extensions/src/ACRE2Core/playSound.h index 98d9d5720..ad88daf4f 100644 --- a/extensions/src/ACRE2Core/playSound.h +++ b/extensions/src/ACRE2Core/playSound.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(playLoadedSound) { + ZoneScoped; const std::string id = std::string((char *)vMessage->getParameter(0)); const acre::vec3_fp32_t position(vMessage->getParameterAsFloat(1), vMessage->getParameterAsFloat(3), vMessage->getParameterAsFloat(2)); diff --git a/extensions/src/ACRE2Core/setChannelDetails.h b/extensions/src/ACRE2Core/setChannelDetails.h index b5532472e..627da8477 100644 --- a/extensions/src/ACRE2Core/setChannelDetails.h +++ b/extensions/src/ACRE2Core/setChannelDetails.h @@ -7,7 +7,11 @@ #include +#include + RPC_FUNCTION(setChannelDetails) { + ZoneScoped; + const std::vector details = { std::string((char *)vMessage->getParameter(0)), std::string((char *)vMessage->getParameter(1)), diff --git a/extensions/src/ACRE2Core/setMuted.h b/extensions/src/ACRE2Core/setMuted.h index 266a5f0c0..803f91700 100644 --- a/extensions/src/ACRE2Core/setMuted.h +++ b/extensions/src/ACRE2Core/setMuted.h @@ -8,9 +8,12 @@ #include "Engine.h" #include "TextMessage.h" +#include RPC_FUNCTION(setMuted) { + ZoneScoped; + for (DWORD index = 0; index < vMessage->getParameterCount(); -1) { if (vMessage->getParameter(index) == nullptr) { break; diff --git a/extensions/src/ACRE2Core/setPTTKeys.h b/extensions/src/ACRE2Core/setPTTKeys.h index db79a1a23..130434ffe 100644 --- a/extensions/src/ACRE2Core/setPTTKeys.h +++ b/extensions/src/ACRE2Core/setPTTKeys.h @@ -4,7 +4,11 @@ #include "TextMessage.h" #include "Log.h" +#include + RPC_FUNCTION(setPTTKeys) { + ZoneScoped; + /* CEngine::getInstance()->getKeyHandlerEngine()->setKeyBind( std::string((char *)vMessage->getParameter(0)), diff --git a/extensions/src/ACRE2Core/setSelectableVoiceCurve.h b/extensions/src/ACRE2Core/setSelectableVoiceCurve.h index cc8bd7dd4..3be2e7f3d 100644 --- a/extensions/src/ACRE2Core/setSelectableVoiceCurve.h +++ b/extensions/src/ACRE2Core/setSelectableVoiceCurve.h @@ -4,7 +4,11 @@ #include "TextMessage.h" #include "Log.h" +#include + RPC_FUNCTION(setSelectableVoiceCurve) { + ZoneScoped; + const float32_t voiceCurveScale = vMessage->getParameterAsFloat(0); //LOG("VOICE MODEL: %d VOICE CURVE: %f", voiceModel, voiceCurveScale); if (!CEngine::getInstance()->getGameServer()->getConnected()) { diff --git a/extensions/src/ACRE2Core/setSetting.h b/extensions/src/ACRE2Core/setSetting.h index 998ae9ad0..a84f493ff 100644 --- a/extensions/src/ACRE2Core/setSetting.h +++ b/extensions/src/ACRE2Core/setSetting.h @@ -4,7 +4,11 @@ #include "Log.h" #include "AcreSettings.h" +#include + RPC_FUNCTION(setSetting) { + ZoneScoped; + const std::string name = std::string((char *)vMessage->getParameter(0)); float32_t value = vMessage->getParameterAsFloat(1); value = round(value * 100.0f) / 100.0f; diff --git a/extensions/src/ACRE2Core/setSoundSystemMasterOverride.h b/extensions/src/ACRE2Core/setSoundSystemMasterOverride.h index f8e94fd18..79f21ad08 100644 --- a/extensions/src/ACRE2Core/setSoundSystemMasterOverride.h +++ b/extensions/src/ACRE2Core/setSoundSystemMasterOverride.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(setSoundSystemMasterOverride) { + ZoneScoped; const bool status = vMessage->getParameterAsInt(0) == 1; diff --git a/extensions/src/ACRE2Core/setVoiceCurveModel.h b/extensions/src/ACRE2Core/setVoiceCurveModel.h index f3fa7f4e2..69cf7acb4 100644 --- a/extensions/src/ACRE2Core/setVoiceCurveModel.h +++ b/extensions/src/ACRE2Core/setVoiceCurveModel.h @@ -4,7 +4,11 @@ #include "TextMessage.h" #include "Log.h" +#include + RPC_FUNCTION(setVoiceCurveModel) { + ZoneScoped; + const acre::CurveModel voiceModel = static_cast(vMessage->getParameterAsInt(0)); const float32_t voiceCurveScale = vMessage->getParameterAsFloat(1); diff --git a/extensions/src/ACRE2Core/startGodModeSpeaking.h b/extensions/src/ACRE2Core/startGodModeSpeaking.h index 829412002..afe1438b9 100644 --- a/extensions/src/ACRE2Core/startGodModeSpeaking.h +++ b/extensions/src/ACRE2Core/startGodModeSpeaking.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(startGodModeSpeaking) { + ZoneScoped; CEngine::getInstance()->getClient()->localStartSpeaking(acre::Speaking::god); diff --git a/extensions/src/ACRE2Core/startIntercomSpeaking.h b/extensions/src/ACRE2Core/startIntercomSpeaking.h index eefa7780e..30310b622 100644 --- a/extensions/src/ACRE2Core/startIntercomSpeaking.h +++ b/extensions/src/ACRE2Core/startIntercomSpeaking.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(startIntercomSpeaking) { + ZoneScoped; CEngine::getInstance()->getClient()->localStartSpeaking(acre::Speaking::intercom); diff --git a/extensions/src/ACRE2Core/startRadioSpeaking.h b/extensions/src/ACRE2Core/startRadioSpeaking.h index 8875fdfd5..3b46cb799 100644 --- a/extensions/src/ACRE2Core/startRadioSpeaking.h +++ b/extensions/src/ACRE2Core/startRadioSpeaking.h @@ -13,7 +13,10 @@ #include +#include + RPC_FUNCTION(startRadioSpeaking) { + ZoneScoped; const std::string radioId = std::string((char *)vMessage->getParameter(0)); diff --git a/extensions/src/ACRE2Core/startZeusSpeaking.h b/extensions/src/ACRE2Core/startZeusSpeaking.h index 4dcac1435..1dec7d175 100644 --- a/extensions/src/ACRE2Core/startZeusSpeaking.h +++ b/extensions/src/ACRE2Core/startZeusSpeaking.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(startZeusSpeaking) { + ZoneScoped; CEngine::getInstance()->getClient()->localStartSpeaking(acre::Speaking::zeus); diff --git a/extensions/src/ACRE2Core/stopGodModeSpeaking.h b/extensions/src/ACRE2Core/stopGodModeSpeaking.h index 5486c9003..8d5ba3ff7 100644 --- a/extensions/src/ACRE2Core/stopGodModeSpeaking.h +++ b/extensions/src/ACRE2Core/stopGodModeSpeaking.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(stopGodModeSpeaking) { + ZoneScoped; CEngine::getInstance()->getClient()->localStopSpeaking(acre::Speaking::god); diff --git a/extensions/src/ACRE2Core/stopIntercomSpeaking.h b/extensions/src/ACRE2Core/stopIntercomSpeaking.h index eca43e7e2..26da1626f 100644 --- a/extensions/src/ACRE2Core/stopIntercomSpeaking.h +++ b/extensions/src/ACRE2Core/stopIntercomSpeaking.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(stopIntercomSpeaking) { + ZoneScoped; CEngine::getInstance()->getClient()->localStopSpeaking(acre::Speaking::intercom); diff --git a/extensions/src/ACRE2Core/stopRadioSpeaking.h b/extensions/src/ACRE2Core/stopRadioSpeaking.h index 0b1ad6540..a881cef35 100644 --- a/extensions/src/ACRE2Core/stopRadioSpeaking.h +++ b/extensions/src/ACRE2Core/stopRadioSpeaking.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(stopRadioSpeaking) { + ZoneScoped; CEngine::getInstance()->getClient()->localStopSpeaking(acre::Speaking::radio); diff --git a/extensions/src/ACRE2Core/stopZeusSpeaking.h b/extensions/src/ACRE2Core/stopZeusSpeaking.h index b99cebe6e..6b3928a1b 100644 --- a/extensions/src/ACRE2Core/stopZeusSpeaking.h +++ b/extensions/src/ACRE2Core/stopZeusSpeaking.h @@ -11,7 +11,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(stopZeusSpeaking) { + ZoneScoped; CEngine::getInstance()->getClient()->localStopSpeaking(acre::Speaking::zeus); diff --git a/extensions/src/ACRE2Core/updateSelf.h b/extensions/src/ACRE2Core/updateSelf.h index 2977f73ff..5925d0533 100644 --- a/extensions/src/ACRE2Core/updateSelf.h +++ b/extensions/src/ACRE2Core/updateSelf.h @@ -12,7 +12,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(updateSelf) { + ZoneScoped; LOCK(CEngine::getInstance()->getSelf()); diff --git a/extensions/src/ACRE2Core/updateSpeakingData.h b/extensions/src/ACRE2Core/updateSpeakingData.h index 6eedd0d16..3858c6815 100644 --- a/extensions/src/ACRE2Core/updateSpeakingData.h +++ b/extensions/src/ACRE2Core/updateSpeakingData.h @@ -12,7 +12,10 @@ #include "TextMessage.h" +#include + RPC_FUNCTION(updateSpeakingData) { + ZoneScoped; CPlayer *speaker = nullptr; diff --git a/extensions/src/ACRE2Profiling/CMakeLists.txt b/extensions/src/ACRE2Profiling/CMakeLists.txt index 1cbce28e5..c8bbb1efb 100644 --- a/extensions/src/ACRE2Profiling/CMakeLists.txt +++ b/extensions/src/ACRE2Profiling/CMakeLists.txt @@ -17,7 +17,7 @@ if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tracy/CMakeLists.txt") endif() set(TRACY_ENABLE ${USE_TRACY} CACHE BOOL "" FORCE) -set(TRACY_ON_DEMAND ON CACHE BOOL "" FORCE) +set(TRACY_ON_DEMAND OFF CACHE BOOL "" FORCE) add_subdirectory("tracy") -target_link_libraries( ${ACRE_NAME} Tracy::TracyClient) \ No newline at end of file +target_link_libraries( ${ACRE_NAME} Tracy::TracyClient) diff --git a/extensions/src/ACRE2Shared/CMakeLists.txt b/extensions/src/ACRE2Shared/CMakeLists.txt index 79007c67d..5291f3ddc 100644 --- a/extensions/src/ACRE2Shared/CMakeLists.txt +++ b/extensions/src/ACRE2Shared/CMakeLists.txt @@ -7,5 +7,5 @@ acre_set_linker_options() file(GLOB SOURCES *.h *.hpp *.c *.cpp) add_library( ${ACRE_NAME} STATIC ${SOURCES} ${GLOBAL_SOURCES}) -target_link_libraries( ${ACRE_NAME}) +target_link_libraries( ${ACRE_NAME} ACRE2Profiling) set_target_properties(${ACRE_NAME} PROPERTIES FOLDER ACRE2) diff --git a/extensions/src/ACRE2Shared/EntrantWorker.h b/extensions/src/ACRE2Shared/EntrantWorker.h index b38432bda..2d5c9e4f2 100644 --- a/extensions/src/ACRE2Shared/EntrantWorker.h +++ b/extensions/src/ACRE2Shared/EntrantWorker.h @@ -7,6 +7,8 @@ #include #include +#include + template class TEntrantWorker : public CLockable { public: TEntrantWorker() { @@ -17,6 +19,8 @@ template class TEntrantWorker : public CLockable { } acre::Result startWorker(void) { + ZoneScoped; + LOCK(this); setShuttingDown(false); std::queue().swap(m_processQueue); // Clear the queue @@ -27,6 +31,8 @@ template class TEntrantWorker : public CLockable { } acre::Result stopWorker(void) { + ZoneScoped; + setShuttingDown(true); setRunning(false); if (m_workerThread.joinable()) { @@ -41,9 +47,13 @@ template class TEntrantWorker : public CLockable { } acre::Result exWorkerThread() { + ZoneScoped; + while (!getShuttingDown()) { LOCK(this); if (!m_processQueue.empty()) { + ZoneScopedN("exWorkerThread - processing queue item"); + const T item = m_processQueue.front(); m_processQueue.pop(); exProcessItem(item); From a2813c6b8eb4d4558791ca401adf887c3399bee0 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 23 Jul 2022 10:12:39 +0200 Subject: [PATCH 06/17] Add Tracy zone to overall Mumble event loop --- extensions/src/ACRE2Mumble/MumbleEventLoop.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp b/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp index 215a5b35f..8e78180e8 100644 --- a/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp +++ b/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp @@ -64,6 +64,7 @@ namespace acre { } void MumbleEventLoop::run() { + ZoneScoped; tracy::SetThreadName("ACRE2-Mumble-EventLoop"); std::unique_lock guard(m_lock); From 03aa162fa757c23baab93c5eb189886b22fda524 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 23 Jul 2022 10:13:05 +0200 Subject: [PATCH 07/17] Fix plugin not unloading when Tracy enabled --- extensions/src/ACRE2Profiling/CMakeLists.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/extensions/src/ACRE2Profiling/CMakeLists.txt b/extensions/src/ACRE2Profiling/CMakeLists.txt index c8bbb1efb..2fd5c302a 100644 --- a/extensions/src/ACRE2Profiling/CMakeLists.txt +++ b/extensions/src/ACRE2Profiling/CMakeLists.txt @@ -18,6 +18,8 @@ endif() set(TRACY_ENABLE ${USE_TRACY} CACHE BOOL "" FORCE) set(TRACY_ON_DEMAND OFF CACHE BOOL "" FORCE) +# We require the delayed init mode to prevent freezes on unloading/shutdown of the (Mumble) plugin +set(TRACY_DELAYED_INIT ON CACHE BOOL "" FORCE) add_subdirectory("tracy") target_link_libraries( ${ACRE_NAME} Tracy::TracyClient) From bbe4312cc9a41ab3a9a5dd0468c6af2bb46fb117 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 23 Jul 2022 13:25:46 +0200 Subject: [PATCH 08/17] Only profile sound callbacks if they actually do something --- extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp b/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp index d1e9d3b07..fa8b80580 100644 --- a/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp @@ -19,8 +19,6 @@ using LIMITER = std::numeric_limits; bool mumble_onAudioSourceFetched(float *outputPCM, uint32_t sampleCount, uint16_t channelCount, uint32_t sampleRate, bool isSpeech, mumble_userid_t userID) { - ZoneScoped; - (void) sampleRate; if (CEngine::getInstance()->getSoundSystemOverride()) { @@ -35,6 +33,8 @@ bool mumble_onAudioSourceFetched(float *outputPCM, uint32_t sampleCount, uint16_ return false; } + ZoneScoped; + // Make this faster const std::uint32_t mixdownSampleLength = sampleCount; int16_t *mixdownSamples = new (std::nothrow) int16_t[mixdownSampleLength]; @@ -108,8 +108,6 @@ bool mumble_onAudioSourceFetched(float *outputPCM, uint32_t sampleCount, uint16_ } bool mumble_onAudioOutputAboutToPlay(float *outputPCM, uint32_t sampleCount, uint16_t channelCount, uint32_t sampleRate) { - ZoneScoped; - (void) sampleRate; if (CEngine::getInstance()->getSoundSystemOverride()) { @@ -124,6 +122,8 @@ bool mumble_onAudioOutputAboutToPlay(float *outputPCM, uint32_t sampleCount, uin return false; } + ZoneScoped; + uint32_t speakerMask = SPEAKER_STEREO; // Make this faster From 453006bd11a7b31a985575cb12f06a73014e2ea6 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 23 Jul 2022 13:26:26 +0200 Subject: [PATCH 09/17] Also profile locks --- extensions/src/ACRE2Mumble/MumbleEventLoop.cpp | 10 +++++----- extensions/src/ACRE2Mumble/MumbleEventLoop.h | 6 ++++-- extensions/src/ACRE2Shared/Lockable.h | 4 +++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp b/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp index 8e78180e8..e47b30c38 100644 --- a/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp +++ b/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp @@ -19,7 +19,7 @@ namespace acre { } { - std::lock_guard guard(m_lock); + std::lock_guard guard(m_lock); m_keepRunning = true; } @@ -30,7 +30,7 @@ namespace acre { ZoneScoped; { - std::lock_guard guard(m_lock); + std::lock_guard guard(m_lock); m_keepRunning = false; m_drain = true; @@ -46,7 +46,7 @@ namespace acre { void MumbleEventLoop::queue(const std::function& callable) { ZoneScoped; - std::lock_guard guard(m_lock); + std::lock_guard guard(m_lock); m_queuedFunctions.push_back(callable); @@ -56,7 +56,7 @@ namespace acre { void MumbleEventLoop::queue(std::function&& callable) { ZoneScoped; - std::unique_lock guard(m_lock); + std::unique_lock guard(m_lock); m_queuedFunctions.push_back(std::move(callable)); @@ -67,7 +67,7 @@ namespace acre { ZoneScoped; tracy::SetThreadName("ACRE2-Mumble-EventLoop"); - std::unique_lock guard(m_lock); + std::unique_lock guard(m_lock); while (m_keepRunning || m_drain) { { diff --git a/extensions/src/ACRE2Mumble/MumbleEventLoop.h b/extensions/src/ACRE2Mumble/MumbleEventLoop.h index 6a3b14ada..5100440f3 100644 --- a/extensions/src/ACRE2Mumble/MumbleEventLoop.h +++ b/extensions/src/ACRE2Mumble/MumbleEventLoop.h @@ -6,6 +6,8 @@ #include #include +#include + namespace acre { /** @@ -39,8 +41,8 @@ namespace acre { void queue(std::function&& callable); protected: - std::mutex m_lock; - std::condition_variable m_waiter; + TracyLockable(std::mutex, m_lock); + std::condition_variable_any m_waiter; bool m_keepRunning = true; bool m_drain = false; std::deque> m_queuedFunctions; diff --git a/extensions/src/ACRE2Shared/Lockable.h b/extensions/src/ACRE2Shared/Lockable.h index dfe9d205c..2788e90e0 100644 --- a/extensions/src/ACRE2Shared/Lockable.h +++ b/extensions/src/ACRE2Shared/Lockable.h @@ -3,9 +3,11 @@ #include +#include + class CLockable { private: - std::recursive_mutex m_lockable_mutex; + TracyLockable(std::recursive_mutex, m_lockable_mutex); public: void lock() { m_lockable_mutex.lock(); From 24051c9720055096d4298363082eb52160d20615 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 23 Jul 2022 13:49:17 +0200 Subject: [PATCH 10/17] Name a few more threads --- extensions/src/ACRE2Core/RpcEngine.cpp | 1 + extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp | 2 ++ 2 files changed, 3 insertions(+) diff --git a/extensions/src/ACRE2Core/RpcEngine.cpp b/extensions/src/ACRE2Core/RpcEngine.cpp index e6d21e94d..6d33f6ae2 100644 --- a/extensions/src/ACRE2Core/RpcEngine.cpp +++ b/extensions/src/ACRE2Core/RpcEngine.cpp @@ -19,6 +19,7 @@ // acre::Result CRpcEngine::exProcessItem(ACRE_RPCDATA *data) { ZoneScoped; + tracy::SetThreadName("RPCEngine"); if (data->function != nullptr) { data->function->call(data->server, data->message); diff --git a/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp b/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp index fa8b80580..625e2f3e3 100644 --- a/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCallbacks_sound.cpp @@ -108,6 +108,8 @@ bool mumble_onAudioSourceFetched(float *outputPCM, uint32_t sampleCount, uint16_ } bool mumble_onAudioOutputAboutToPlay(float *outputPCM, uint32_t sampleCount, uint16_t channelCount, uint32_t sampleRate) { + tracy::SetThreadName("Mumble audio output thread"); + (void) sampleRate; if (CEngine::getInstance()->getSoundSystemOverride()) { From 2df067cb7df41e2d3b5fa1abe5ee36ca9f1d9a0b Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sat, 23 Jul 2022 14:28:46 +0200 Subject: [PATCH 11/17] Profile Mumble API functions --- .../src/ACRE2Mumble/MumbleCallbacks_init.cpp | 4 +-- extensions/src/ACRE2Mumble/MumbleClient.cpp | 30 +++++++++---------- .../src/ACRE2Mumble/MumbleCommandServer.cpp | 8 ++--- extensions/src/ACRE2Mumble/MumbleFunctions.h | 13 ++++++++ 4 files changed, 34 insertions(+), 21 deletions(-) diff --git a/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp b/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp index 7f5b17ece..68c41af32 100644 --- a/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp @@ -35,7 +35,7 @@ mumble_error_t mumble_init(mumble_plugin_id_t id) { acre::MumbleEventLoop::getInstance().start(); - if (mumAPI.getActiveServerConnection(pluginID, &activeConnection) != MUMBLE_STATUS_OK) { + if (API_CALL(getActiveServerConnection, pluginID, &activeConnection) != MUMBLE_STATUS_OK) { activeConnection = -1; } @@ -68,7 +68,7 @@ void mumble_onServerSynchronized(mumble_connection_t connection) { // set ID on every new connection acre::id_t clientId = 0; - mumAPI.getLocalUserID(pluginID, activeConnection, (mumble_userid_t*)&clientId); + API_CALL(getLocalUserID, pluginID, activeConnection, (mumble_userid_t*)&clientId); CEngine::getInstance()->getSelf()->setId(clientId); CEngine::getInstance()->getExternalServer()->setId(clientId); diff --git a/extensions/src/ACRE2Mumble/MumbleClient.cpp b/extensions/src/ACRE2Mumble/MumbleClient.cpp index bc1661798..de25c56c9 100644 --- a/extensions/src/ACRE2Mumble/MumbleClient.cpp +++ b/extensions/src/ACRE2Mumble/MumbleClient.cpp @@ -60,7 +60,7 @@ acre::Result CMumbleClient::stop() { } this->setState(acre::State::stopped); - mumAPI.log(pluginID, "stopped"); + API_CALL(log, pluginID, "stopped"); } return acre::Result::ok; @@ -82,8 +82,8 @@ acre::Result CMumbleClient::start(const acre::id_t id_) { this->setState(acre::State::running); this->setIsX3DInitialized(false); - mumAPI.log(pluginID, "Started"); - mumAPI.log(pluginID, ACRE_VERSION_METADATA); + API_CALL(log, pluginID, "Started"); + API_CALL(log, pluginID, ACRE_VERSION_METADATA); return acre::Result::ok; } @@ -92,7 +92,7 @@ bool CMumbleClient::getVAD() { ZoneScoped; mumble_transmission_mode_t transmitMode; - const mumble_error_t err = mumAPI.getLocalUserTransmissionMode(pluginID, &transmitMode); + const mumble_error_t err = API_CALL(getLocalUserTransmissionMode, pluginID, &transmitMode); if (err != MUMBLE_STATUS_OK) { return false; } @@ -273,7 +273,7 @@ std::string CMumbleClient::getTempFilePath(void) { acre::Result CMumbleClient::microphoneOpen(bool status_) { ZoneScoped; - const mumble_error_t res = mumAPI.requestMicrophoneActivationOvewrite(pluginID, status_); + const mumble_error_t res = API_CALL(requestMicrophoneActivationOvewrite, pluginID, status_); if (res != MUMBLE_STATUS_OK) { if (status_) { LOG("Error toggling PTT Open: %s (%d)\n", mumble_errorMessage(res), res); @@ -302,10 +302,10 @@ acre::Result CMumbleClient::moveToServerChannel() { mumble_userid_t clientId; std::vector details = getChannelDetails(); - if (mumAPI.getLocalUserID(pluginID, activeConnection, &clientId) == MUMBLE_STATUS_OK) { + if (API_CALL(getLocalUserID, pluginID, activeConnection, &clientId) == MUMBLE_STATUS_OK) { mumble_channelid_t currentChannelId = invalid_mumble_channel; - if ((mumAPI.getChannelOfUser(pluginID, activeConnection, clientId, ¤tChannelId) == MUMBLE_STATUS_OK) && + if ((API_CALL(getChannelOfUser, pluginID, activeConnection, clientId, ¤tChannelId) == MUMBLE_STATUS_OK) && (getPreviousChannel() == invalid_mumble_channel)) { setPreviousChannel(currentChannelId); } @@ -317,7 +317,7 @@ acre::Result CMumbleClient::moveToServerChannel() { password = details.at(1); } - mumAPI.requestUserMove(pluginID, activeConnection, clientId, channelId, password.c_str()); + API_CALL(requestUserMove, pluginID, activeConnection, clientId, channelId, password.c_str()); } } } @@ -333,13 +333,13 @@ acre::Result CMumbleClient::moveToPreviousChannel() { if (!CAcreSettings::getInstance()->getDisableChannelSwitch()) { mumble_userid_t clientId = -1; - if (mumAPI.getLocalUserID(pluginID, activeConnection, &clientId) == MUMBLE_STATUS_OK) { + if (API_CALL(getLocalUserID, pluginID, activeConnection, &clientId) == MUMBLE_STATUS_OK) { mumble_channelid_t currentChannelId = invalid_mumble_channel; - if (mumAPI.getChannelOfUser(pluginID, activeConnection, clientId, ¤tChannelId) == MUMBLE_STATUS_OK) { + if (API_CALL(getChannelOfUser, pluginID, activeConnection, clientId, ¤tChannelId) == MUMBLE_STATUS_OK) { const mumble_channelid_t channelId = static_cast(getPreviousChannel()); if (channelId != invalid_mumble_channel && channelId != currentChannelId) { - mumAPI.requestUserMove(pluginID, activeConnection, clientId, channelId, ""); + API_CALL(requestUserMove, pluginID, activeConnection, clientId, channelId, ""); } } } @@ -356,7 +356,7 @@ uint64_t CMumbleClient::findChannelByNames(std::vector details_) { mumble_channelid_t *channelList = nullptr; std::size_t channelCount = 0U; - if (mumAPI.getAllChannels(pluginID, activeConnection, &channelList, &channelCount) == MUMBLE_STATUS_OK) { + if (API_CALL(getAllChannels, pluginID, activeConnection, &channelList, &channelCount) == MUMBLE_STATUS_OK) { mumble_channelid_t channelId = invalid_mumble_channel; mumble_channelid_t defaultChannelId = invalid_mumble_channel; std::map channelMap; @@ -369,10 +369,10 @@ uint64_t CMumbleClient::findChannelByNames(std::vector details_) { channelId = *channelList + idx; const char *channelName = nullptr; - if (mumAPI.getChannelName(pluginID, activeConnection, channelId, &channelName) == MUMBLE_STATUS_OK) { + if (API_CALL(getChannelName, pluginID, activeConnection, channelId, &channelName) == MUMBLE_STATUS_OK) { // Copy the channel name into a std::string and then get rid of the Mumble resource again std::string channelNameString(channelName); - mumAPI.freeMemory(pluginID, (void *) channelName); + API_CALL(freeMemory, pluginID, (void *) channelName); if (channelNameString.find(default_mumble_channel) != -1 || (!details_.at(0).empty() && channelNameString == name)) { if (channelNameString == default_mumble_channel) { @@ -383,7 +383,7 @@ uint64_t CMumbleClient::findChannelByNames(std::vector details_) { } } - mumAPI.freeMemory(pluginID, channelList); + API_CALL(freeMemory, pluginID, channelList); mumble_channelid_t bestChannelId = invalid_mumble_channel; int32_t bestMatches = 0; diff --git a/extensions/src/ACRE2Mumble/MumbleCommandServer.cpp b/extensions/src/ACRE2Mumble/MumbleCommandServer.cpp index e8e974cd2..1bff925c4 100644 --- a/extensions/src/ACRE2Mumble/MumbleCommandServer.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCommandServer.cpp @@ -33,24 +33,24 @@ acre::Result CMumbleCommandServer::sendMessage(IMessage *msg) { size_t userCount = 0U; mumble_channelid_t currentChannel = 0; - mumble_error_t err = mumAPI.getChannelOfUser(pluginID, activeConnection, this->getId(), ¤tChannel); + mumble_error_t err = API_CALL(getChannelOfUser, pluginID, activeConnection, this->getId(), ¤tChannel); if (err != MUMBLE_STATUS_OK) { LOG("ERROR, UNABLE TO GET CHANNEL OF USER: %s (%d)", mumble_errorMessage(err), err); return acre::Result::error; } - err = mumAPI.getUsersInChannel(pluginID, activeConnection, currentChannel, &channelUsers, &userCount); + err = API_CALL(getUsersInChannel, pluginID, activeConnection, currentChannel, &channelUsers, &userCount); if (err != MUMBLE_STATUS_OK) { LOG("ERROR, UNABLE TO GET USERS IN CHANNEL: %s (%d)", mumble_errorMessage(err), err); return acre::Result::error; } - err = mumAPI.sendData(pluginID, activeConnection, channelUsers, userCount, (const uint8_t *) msg->getData(), msg->getLength(), "ACRE2"); + err = API_CALL(sendData, pluginID, activeConnection, channelUsers, userCount, (const uint8_t *) msg->getData(), msg->getLength(), "ACRE2"); if (err != MUMBLE_STATUS_OK) { LOG("ERROR, UNABLE TO SEND MESSAGE DATA: %s (%d)", mumble_errorMessage(err), err); return acre::Result::error; } - err = mumAPI.freeMemory(pluginID, (void *) channelUsers); + err = API_CALL(freeMemory, pluginID, (void *) channelUsers); if (err != MUMBLE_STATUS_OK) { LOG("ERROR, UNABLE TO FREE CHANNEL USER LIST: %s (%d)", mumble_errorMessage(err), err); return acre::Result::error; diff --git a/extensions/src/ACRE2Mumble/MumbleFunctions.h b/extensions/src/ACRE2Mumble/MumbleFunctions.h index c5860ab87..0b8676874 100644 --- a/extensions/src/ACRE2Mumble/MumbleFunctions.h +++ b/extensions/src/ACRE2Mumble/MumbleFunctions.h @@ -3,3 +3,16 @@ #include "MumbleAPI_v_1_0_x.h" #define MUMBLE_PLUGIN_NO_DEFAULT_FUNCTION_DEFINITIONS #include "MumblePlugin_v_1_1_x.h" + + +#include + +#ifndef TRACY_ENABLE +#define API_CALL(function, ...) mumAPI.function(__VA_ARGS__) +#else +#define API_CALL(function, ...) \ + [=]() mutable { \ + ZoneScopedN("Mumble API function \"" #function "\""); \ + return mumAPI.function(__VA_ARGS__); \ + }() +#endif From 94d294a331c70761f6dfc89953e1debcb663021a Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sun, 24 Jul 2022 16:15:26 +0200 Subject: [PATCH 12/17] Clean-up profiling lib cmake code --- extensions/CMakeLists.txt | 5 +++-- extensions/src/ACRE2Profiling/CMakeLists.txt | 6 ++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index fa219e86c..adc9d20b3 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -58,6 +58,9 @@ if(MSVC) set(GLOBAL_SOURCES ${GLOBAL_RC}) endif() + +add_subdirectory(src/ACRE2Profiling) + include_directories(src/ACRE2Shared) include_directories(src/ACRE2Core) @@ -68,8 +71,6 @@ add_subdirectory(src/ACRE2Core) add_subdirectory(src/ACRE2Arma) add_subdirectory(src/ACRE2Steam) -add_subdirectory(src/ACRE2Profiling) - add_subdirectory(src/ACRE2TS) add_subdirectory(src/ACRE2Mumble) diff --git a/extensions/src/ACRE2Profiling/CMakeLists.txt b/extensions/src/ACRE2Profiling/CMakeLists.txt index 2fd5c302a..320c8822a 100644 --- a/extensions/src/ACRE2Profiling/CMakeLists.txt +++ b/extensions/src/ACRE2Profiling/CMakeLists.txt @@ -8,9 +8,7 @@ acre_set_linker_options() file(GLOB SOURCES *.h *.hpp *.c *.cpp) -add_library( ${ACRE_NAME} STATIC ${SOURCES} ${GLOBAL_SOURCES} ${DSP_SOURCES}) -target_link_libraries( ${ACRE_NAME} ) -set_target_properties(${ACRE_NAME} PROPERTIES FOLDER ACRE2) +add_library( ${ACRE_NAME} INTERFACE) if(NOT EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/tracy/CMakeLists.txt") message(FATAL_ERROR "Unable to locate tracy submodule - did you forget to run git submodule update --init?") @@ -22,4 +20,4 @@ set(TRACY_ON_DEMAND OFF CACHE BOOL "" FORCE) set(TRACY_DELAYED_INIT ON CACHE BOOL "" FORCE) add_subdirectory("tracy") -target_link_libraries( ${ACRE_NAME} Tracy::TracyClient) +target_link_libraries( ${ACRE_NAME} INTERFACE Tracy::TracyClient) From 683e3f40eaa855a517742380bd1de5dca3b2d547 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sun, 24 Jul 2022 16:27:52 +0200 Subject: [PATCH 13/17] Expose CMake option to enable tracing --- extensions/CMakeLists.txt | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/extensions/CMakeLists.txt b/extensions/CMakeLists.txt index adc9d20b3..059bdc1ed 100644 --- a/extensions/CMakeLists.txt +++ b/extensions/CMakeLists.txt @@ -6,6 +6,7 @@ include(${PROJECT_SOURCE_DIR}/CMakeModules/cxx_compiler_functions.cmake) option(USE_64BIT_BUILD "USE_64BIT_BUILD" OFF) option(USE_STATIC_LINKING "USE_STATIC_LINKING" ON) +option(ENABLE_TRACING "ENABLE_TRACING" OFF) set(CMAKE_BUILD_TYPE "RelWithDebInfo") @@ -58,6 +59,10 @@ if(MSVC) set(GLOBAL_SOURCES ${GLOBAL_RC}) endif() +if(ENABLE_TRACING) + message(STATUS "Enabling tracing (beware of excessively verbose log output)") + add_compile_definitions(_TRACE=1) +endif() add_subdirectory(src/ACRE2Profiling) From ee770e6fc4b9a6e266574fcbb74632095c7824bd Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sun, 24 Jul 2022 18:51:11 +0200 Subject: [PATCH 14/17] Fix lambda capturing fpr API calls when using Tracy --- extensions/src/ACRE2Mumble/MumbleFunctions.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/extensions/src/ACRE2Mumble/MumbleFunctions.h b/extensions/src/ACRE2Mumble/MumbleFunctions.h index 0b8676874..8db8d31ef 100644 --- a/extensions/src/ACRE2Mumble/MumbleFunctions.h +++ b/extensions/src/ACRE2Mumble/MumbleFunctions.h @@ -11,7 +11,7 @@ #define API_CALL(function, ...) mumAPI.function(__VA_ARGS__) #else #define API_CALL(function, ...) \ - [=]() mutable { \ + [&]() mutable { \ ZoneScopedN("Mumble API function \"" #function "\""); \ return mumAPI.function(__VA_ARGS__); \ }() From 63d55708a6760228c5c662152d8be76eb52926a2 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sun, 24 Jul 2022 18:51:45 +0200 Subject: [PATCH 15/17] Add error handling to API call --- extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp b/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp index 68c41af32..56f386f3d 100644 --- a/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp +++ b/extensions/src/ACRE2Mumble/MumbleCallbacks_init.cpp @@ -67,8 +67,12 @@ void mumble_onServerSynchronized(mumble_connection_t connection) { activeConnection = connection; // set ID on every new connection - acre::id_t clientId = 0; - API_CALL(getLocalUserID, pluginID, activeConnection, (mumble_userid_t*)&clientId); + acre::id_t clientId = 5; + mumble_error_t retCode = API_CALL(getLocalUserID, pluginID, activeConnection, (mumble_userid_t*)&clientId); + if (retCode != MUMBLE_STATUS_OK) { + LOG("ERROR, FAILED TO FETCH LOCAL USER'S ID: %s (%d)", mumble_errorMessage(retCode), retCode); + } + TRACE("Local user's ID is %d", clientId); CEngine::getInstance()->getSelf()->setId(clientId); CEngine::getInstance()->getExternalServer()->setId(clientId); From 882462010ba84db1d61800862d76535ab3da6f87 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sun, 24 Jul 2022 19:05:00 +0200 Subject: [PATCH 16/17] Add more debug output --- extensions/src/ACRE2Mumble/MumbleClient.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extensions/src/ACRE2Mumble/MumbleClient.cpp b/extensions/src/ACRE2Mumble/MumbleClient.cpp index de25c56c9..82fe13668 100644 --- a/extensions/src/ACRE2Mumble/MumbleClient.cpp +++ b/extensions/src/ACRE2Mumble/MumbleClient.cpp @@ -307,6 +307,7 @@ acre::Result CMumbleClient::moveToServerChannel() { if ((API_CALL(getChannelOfUser, pluginID, activeConnection, clientId, ¤tChannelId) == MUMBLE_STATUS_OK) && (getPreviousChannel() == invalid_mumble_channel)) { + TRACE("Setting previous channel ID to %d", currentChannelId); setPreviousChannel(currentChannelId); } @@ -317,8 +318,11 @@ acre::Result CMumbleClient::moveToServerChannel() { password = details.at(1); } + TRACE("Requesting local user to be moved to channel %d", channelId); API_CALL(requestUserMove, pluginID, activeConnection, clientId, channelId, password.c_str()); } + } else { + LOG("ERROR, FAILED TO OBTAIN LOCAL USER'S ID"); } } setShouldSwitchChannel(false); @@ -365,6 +369,8 @@ uint64_t CMumbleClient::findChannelByNames(std::vector details_) { name = details_.at(0); } + TRACE("Searching for channel \"%s\"", name.c_str()); + for (std::int32_t idx = 0U; idx < channelCount; idx++) { channelId = *channelList + idx; const char *channelName = nullptr; @@ -419,6 +425,8 @@ uint64_t CMumbleClient::findChannelByNames(std::vector details_) { } } return bestChannelId; + } else { + LOG("ERROR, FAILED TO GET CHANNEL LIST"); } return 0; From ebdff38830b312930eccf4a60172639fd698a075 Mon Sep 17 00:00:00 2001 From: Robert Adam Date: Sun, 24 Jul 2022 20:19:13 +0200 Subject: [PATCH 17/17] Improved readability of Tracy capturings --- extensions/src/ACRE2Core/NamedPipeServer.cpp | 107 ++++++++++-------- extensions/src/ACRE2Core/RpcEngine.cpp | 7 +- .../src/ACRE2Core/ext_handleGetClientID.h | 2 +- .../src/ACRE2Core/ext_remoteStartSpeaking.h | 2 +- .../src/ACRE2Core/ext_remoteStopSpeaking.h | 2 +- extensions/src/ACRE2Core/ext_reset.h | 2 +- extensions/src/ACRE2Core/getClientID.h | 2 +- extensions/src/ACRE2Core/getPluginVersion.h | 2 +- extensions/src/ACRE2Core/loadSound.h | 2 +- extensions/src/ACRE2Core/localMute.h | 2 +- extensions/src/ACRE2Core/ping.h | 2 +- extensions/src/ACRE2Core/playSound.h | 2 +- extensions/src/ACRE2Core/setChannelDetails.h | 2 +- extensions/src/ACRE2Core/setMuted.h | 2 +- extensions/src/ACRE2Core/setPTTKeys.h | 2 +- .../src/ACRE2Core/setSelectableVoiceCurve.h | 2 +- extensions/src/ACRE2Core/setSetting.h | 2 +- .../ACRE2Core/setSoundSystemMasterOverride.h | 2 +- extensions/src/ACRE2Core/setVoiceCurveModel.h | 2 +- .../src/ACRE2Core/startGodModeSpeaking.h | 2 +- .../src/ACRE2Core/startIntercomSpeaking.h | 2 +- extensions/src/ACRE2Core/startRadioSpeaking.h | 2 +- extensions/src/ACRE2Core/startZeusSpeaking.h | 2 +- .../src/ACRE2Core/stopGodModeSpeaking.h | 2 +- .../src/ACRE2Core/stopIntercomSpeaking.h | 2 +- extensions/src/ACRE2Core/stopRadioSpeaking.h | 2 +- extensions/src/ACRE2Core/stopZeusSpeaking.h | 2 +- extensions/src/ACRE2Core/updateSelf.h | 2 +- extensions/src/ACRE2Core/updateSpeakingData.h | 2 +- extensions/src/ACRE2Mumble/MumbleClient.cpp | 6 - .../src/ACRE2Mumble/MumbleEventLoop.cpp | 39 +++---- extensions/src/ACRE2Shared/EntrantWorker.h | 4 - 32 files changed, 111 insertions(+), 106 deletions(-) diff --git a/extensions/src/ACRE2Core/NamedPipeServer.cpp b/extensions/src/ACRE2Core/NamedPipeServer.cpp index e6d368b46..beb634222 100644 --- a/extensions/src/ACRE2Core/NamedPipeServer.cpp +++ b/extensions/src/ACRE2Core/NamedPipeServer.cpp @@ -146,30 +146,29 @@ acre::Result CNamedPipeServer::shutdown(void) { return acre::Result::ok; } +const char *sendFrameName = "NamedPipeServer - sending"; + acre::Result CNamedPipeServer::sendLoop() { - ZoneScoped; tracy::SetThreadName("NamedPipeServer::sendLoop"); while (!this->getShuttingDown()) { - { - ZoneScopedN("CNamedPipeServer::sendLoop - connecting write pipe"); - - do { - ConnectNamedPipe(this->m_PipeHandleWrite, NULL); - if (GetLastError() == ERROR_PIPE_CONNECTED) { - LOG("Client write connected"); - CEngine::getInstance()->getSoundEngine()->onClientGameConnected(); - this->setConnectedWrite(true); - break; - } else { - this->setConnectedWrite(false); - Sleep(1); - } - } while (!this->getConnectedWrite() && !this->getShuttingDown()); - } + do { + ConnectNamedPipe(this->m_PipeHandleWrite, NULL); + if (GetLastError() == ERROR_PIPE_CONNECTED) { + LOG("Client write connected"); + CEngine::getInstance()->getSoundEngine()->onClientGameConnected(); + this->setConnectedWrite(true); + break; + } else { + this->setConnectedWrite(false); + Sleep(1); + } + } while (!this->getConnectedWrite() && !this->getShuttingDown()); clock_t lastTick = clock() / CLOCKS_PER_SEC; while (this->getConnectedWrite()) { + FrameMarkStart(sendFrameName); + if (this->getShuttingDown()) break; @@ -183,7 +182,7 @@ acre::Result CNamedPipeServer::sendLoop() { IMessage *msg = nullptr; if (this->m_sendQueue.try_pop(msg)) { if (msg != nullptr) { - ZoneScopedN("CNamedPipeServer::sendLoop - sending message"); + ZoneScoped; lastTick = clock() / CLOCKS_PER_SEC; const DWORD size = (DWORD)strlen((char *)msg->getData()) + 1; @@ -209,21 +208,27 @@ acre::Result CNamedPipeServer::sendLoop() { } delete msg; } + + FrameMarkEnd(sendFrameName); } + Sleep(1); } + LOG("Write loop disconnected"); FlushFileBuffers(this->m_PipeHandleWrite); const bool ret = DisconnectNamedPipe(this->m_PipeHandleWrite); Sleep(1); } + TRACE("Sending thread terminating"); return acre::Result::ok; } +const char *receiveFrameName = "NamedPipeServer - receiving"; + acre::Result CNamedPipeServer::readLoop() { - ZoneScoped; tracy::SetThreadName("NamedPipeServer::readLoop"); DWORD cbRead; @@ -238,7 +243,7 @@ acre::Result CNamedPipeServer::readLoop() { while (!this->getShuttingDown()) { bool ret = false; { - ZoneScopedN("CNamedPipeServer::readLoop - connecting read pipe"); + // ZoneScopedN("CNamedPipeServer::readLoop - connecting read pipe"); // this->checkServer(); ret = ConnectNamedPipe(this->m_PipeHandleRead, NULL); if (GetLastError() == ERROR_PIPE_CONNECTED) { @@ -257,6 +262,8 @@ acre::Result CNamedPipeServer::readLoop() { clock_t lastTick = clock() / CLOCKS_PER_SEC; while (this->getConnectedRead()) { + FrameMarkStart(receiveFrameName); + //this->checkServer(); if (this->getShuttingDown()) { break; @@ -277,35 +284,38 @@ acre::Result CNamedPipeServer::readLoop() { } ret = false; - { - ZoneScopedN("CNamedPipeServer::readLoop - receiving messages"); - - do { - ret = ReadFile(this->m_PipeHandleRead, mBuffer, BUFSIZE - 1, &cbRead, NULL); // -1 for null-byte below - if (!ret && GetLastError() != ERROR_MORE_DATA) { - break; - } else if (!ret && GetLastError() == ERROR_BROKEN_PIPE) { - this->setConnectedRead(false); - break; - } - // handle the packet and run it - mBuffer[cbRead] = 0x00; - // LOG("READ: %s", (char *)mBuffer); - IMessage *const msg = new CTextMessage((char *) mBuffer, cbRead); - // TRACE("got and parsed message [%s]", msg->getData()); - if (msg != nullptr && msg->getProcedureName()) { - // Do not free msg, this is deleted inside runProcedure() - CEngine::getInstance()->getRpcEngine()->runProcedure(this, msg); - - lastTick = clock() / CLOCKS_PER_SEC; - // TRACE("tick [%d], [%s]",lastTick, msg->getData()); - } - // wait 1ms for new msg so we dont hog cpu cycles - } while (!ret); - } - //ret = ConnectNamedPipe(this->getPipeHandle(), NULL); + do { + ret = ReadFile(this->m_PipeHandleRead, mBuffer, BUFSIZE - 1, &cbRead, NULL); // -1 for null-byte below + if (!ret && GetLastError() != ERROR_MORE_DATA) { + break; + } else if (!ret && GetLastError() == ERROR_BROKEN_PIPE) { + this->setConnectedRead(false); + break; + } + + ZoneScoped; + + // handle the packet and run it + mBuffer[cbRead] = 0x00; + // LOG("READ: %s", (char *)mBuffer); + IMessage *const msg = new CTextMessage((char *) mBuffer, cbRead); + // TRACE("got and parsed message [%s]", msg->getData()); + if (msg != nullptr && msg->getProcedureName()) { + // Do not free msg, this is deleted inside runProcedure() + CEngine::getInstance()->getRpcEngine()->runProcedure(this, msg); + + lastTick = clock() / CLOCKS_PER_SEC; + // TRACE("tick [%d], [%s]",lastTick, msg->getData()); + } + // wait 1ms for new msg so we dont hog cpu cycles + } while (!ret); + //ret = ConnectNamedPipe(this->getPipeHandle(), NULL); + + FrameMarkEnd(receiveFrameName); + Sleep(1); } + // Kill the write pipe along with ourselves, because we master shutdown/startup this->setConnectedWrite(false); this->setConnectedRead(false); @@ -329,7 +339,8 @@ acre::Result CNamedPipeServer::readLoop() { CEngine::getInstance()->getSelf()->getId() ) ); - } + } + Sleep(1); } diff --git a/extensions/src/ACRE2Core/RpcEngine.cpp b/extensions/src/ACRE2Core/RpcEngine.cpp index 6d33f6ae2..1a0e6e174 100644 --- a/extensions/src/ACRE2Core/RpcEngine.cpp +++ b/extensions/src/ACRE2Core/RpcEngine.cpp @@ -14,12 +14,13 @@ #include -// +const char *frameName = "RPCEngine"; + // // Entrant worker, weee // acre::Result CRpcEngine::exProcessItem(ACRE_RPCDATA *data) { - ZoneScoped; tracy::SetThreadName("RPCEngine"); + FrameMarkStart(frameName); if (data->function != nullptr) { data->function->call(data->server, data->message); @@ -27,6 +28,8 @@ acre::Result CRpcEngine::exProcessItem(ACRE_RPCDATA *data) { delete data->message; free(data); + FrameMarkEnd(frameName); + return acre::Result::ok; } diff --git a/extensions/src/ACRE2Core/ext_handleGetClientID.h b/extensions/src/ACRE2Core/ext_handleGetClientID.h index 4bcf811c0..2bb4b7f67 100644 --- a/extensions/src/ACRE2Core/ext_handleGetClientID.h +++ b/extensions/src/ACRE2Core/ext_handleGetClientID.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(ext_handleGetClientID) { - ZoneScoped; + ZoneScopedN("RPC - ext_handleGetClientID"); CEngine::getInstance()->getGameServer()->sendMessage( CTextMessage::formatNewMessage("handleGetClientID", diff --git a/extensions/src/ACRE2Core/ext_remoteStartSpeaking.h b/extensions/src/ACRE2Core/ext_remoteStartSpeaking.h index c80411f7d..22d0e0c7b 100644 --- a/extensions/src/ACRE2Core/ext_remoteStartSpeaking.h +++ b/extensions/src/ACRE2Core/ext_remoteStartSpeaking.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(ext_remoteStartSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - ext_remoteStartSpeaking"); /*CTextMessage::formatNewMessage("ext_remoteStartSpeaking", "%d,%d,%s,%f,", diff --git a/extensions/src/ACRE2Core/ext_remoteStopSpeaking.h b/extensions/src/ACRE2Core/ext_remoteStopSpeaking.h index 95db883ec..a18e0238a 100644 --- a/extensions/src/ACRE2Core/ext_remoteStopSpeaking.h +++ b/extensions/src/ACRE2Core/ext_remoteStopSpeaking.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(ext_remoteStopSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - ext_remoteStopSpeaking"); /*CTextMessage::formatNewMessage("ext_remoteStartSpeaking", "%d,%d,%s,%f,", diff --git a/extensions/src/ACRE2Core/ext_reset.h b/extensions/src/ACRE2Core/ext_reset.h index 52c08e2ad..c51ce5754 100644 --- a/extensions/src/ACRE2Core/ext_reset.h +++ b/extensions/src/ACRE2Core/ext_reset.h @@ -8,7 +8,7 @@ #include RPC_FUNCTION(ext_reset) { - ZoneScoped; + ZoneScopedN("RPC - ext_reset"); const acre::id_t id = vMessage->getParameterAsInt(0); diff --git a/extensions/src/ACRE2Core/getClientID.h b/extensions/src/ACRE2Core/getClientID.h index 9aaf0fce2..7a1994f0d 100644 --- a/extensions/src/ACRE2Core/getClientID.h +++ b/extensions/src/ACRE2Core/getClientID.h @@ -15,7 +15,7 @@ #include RPC_FUNCTION(getClientID) { - ZoneScoped; + ZoneScopedN("RPC - getClientID"); TRACE("enter"); diff --git a/extensions/src/ACRE2Core/getPluginVersion.h b/extensions/src/ACRE2Core/getPluginVersion.h index 2203147df..baf28f541 100644 --- a/extensions/src/ACRE2Core/getPluginVersion.h +++ b/extensions/src/ACRE2Core/getPluginVersion.h @@ -6,7 +6,7 @@ #include RPC_FUNCTION(getPluginVersion) { - ZoneScoped; + ZoneScopedN("RPC - getPluginVersion"); vServer->sendMessage(CTextMessage::formatNewMessage("handleGetPluginVersion", "%s", ACRE_VERSION)); diff --git a/extensions/src/ACRE2Core/loadSound.h b/extensions/src/ACRE2Core/loadSound.h index 37d788e66..ffd21e798 100644 --- a/extensions/src/ACRE2Core/loadSound.h +++ b/extensions/src/ACRE2Core/loadSound.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(loadSound) { - ZoneScoped; + ZoneScopedN("RPC - loadSound"); const std::string id = std::string((char *)vMessage->getParameter(0)); const int32_t currentCount = vMessage->getParameterAsInt(1); diff --git a/extensions/src/ACRE2Core/localMute.h b/extensions/src/ACRE2Core/localMute.h index 21d0a66b2..d12411ed7 100644 --- a/extensions/src/ACRE2Core/localMute.h +++ b/extensions/src/ACRE2Core/localMute.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(localMute) { - ZoneScoped; + ZoneScopedN("RPC - localMute"); const bool status = vMessage->getParameterAsInt(0) == 1; diff --git a/extensions/src/ACRE2Core/ping.h b/extensions/src/ACRE2Core/ping.h index d1179973c..061a92f9a 100644 --- a/extensions/src/ACRE2Core/ping.h +++ b/extensions/src/ACRE2Core/ping.h @@ -12,7 +12,7 @@ volatile DWORD g_pingTime; RPC_FUNCTION(ping) { - ZoneScoped; + ZoneScopedN("RPC - ping"); g_pingTime = clock() / CLOCKS_PER_SEC; vServer->sendMessage(CTextMessage::formatNewMessage("pong", "%f,", g_pingTime)); diff --git a/extensions/src/ACRE2Core/playSound.h b/extensions/src/ACRE2Core/playSound.h index ad88daf4f..000a6c472 100644 --- a/extensions/src/ACRE2Core/playSound.h +++ b/extensions/src/ACRE2Core/playSound.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(playLoadedSound) { - ZoneScoped; + ZoneScopedN("RPC - playLoadedSound"); const std::string id = std::string((char *)vMessage->getParameter(0)); const acre::vec3_fp32_t position(vMessage->getParameterAsFloat(1), vMessage->getParameterAsFloat(3), vMessage->getParameterAsFloat(2)); diff --git a/extensions/src/ACRE2Core/setChannelDetails.h b/extensions/src/ACRE2Core/setChannelDetails.h index 627da8477..87a8574fa 100644 --- a/extensions/src/ACRE2Core/setChannelDetails.h +++ b/extensions/src/ACRE2Core/setChannelDetails.h @@ -10,7 +10,7 @@ #include RPC_FUNCTION(setChannelDetails) { - ZoneScoped; + ZoneScopedN("RPC - setChannelDetails"); const std::vector details = { std::string((char *)vMessage->getParameter(0)), diff --git a/extensions/src/ACRE2Core/setMuted.h b/extensions/src/ACRE2Core/setMuted.h index 803f91700..5d62c38cd 100644 --- a/extensions/src/ACRE2Core/setMuted.h +++ b/extensions/src/ACRE2Core/setMuted.h @@ -12,7 +12,7 @@ RPC_FUNCTION(setMuted) { - ZoneScoped; + ZoneScopedN("RPC - setMuted"); for (DWORD index = 0; index < vMessage->getParameterCount(); -1) { if (vMessage->getParameter(index) == nullptr) { diff --git a/extensions/src/ACRE2Core/setPTTKeys.h b/extensions/src/ACRE2Core/setPTTKeys.h index 130434ffe..0e7768da4 100644 --- a/extensions/src/ACRE2Core/setPTTKeys.h +++ b/extensions/src/ACRE2Core/setPTTKeys.h @@ -7,7 +7,7 @@ #include RPC_FUNCTION(setPTTKeys) { - ZoneScoped; + ZoneScopedN("RPC - setPTTKeys"); /* CEngine::getInstance()->getKeyHandlerEngine()->setKeyBind( diff --git a/extensions/src/ACRE2Core/setSelectableVoiceCurve.h b/extensions/src/ACRE2Core/setSelectableVoiceCurve.h index 3be2e7f3d..684aa6cf6 100644 --- a/extensions/src/ACRE2Core/setSelectableVoiceCurve.h +++ b/extensions/src/ACRE2Core/setSelectableVoiceCurve.h @@ -7,7 +7,7 @@ #include RPC_FUNCTION(setSelectableVoiceCurve) { - ZoneScoped; + ZoneScopedN("RPC - setSelectableVoiceCurve"); const float32_t voiceCurveScale = vMessage->getParameterAsFloat(0); //LOG("VOICE MODEL: %d VOICE CURVE: %f", voiceModel, voiceCurveScale); diff --git a/extensions/src/ACRE2Core/setSetting.h b/extensions/src/ACRE2Core/setSetting.h index a84f493ff..74f32bfd3 100644 --- a/extensions/src/ACRE2Core/setSetting.h +++ b/extensions/src/ACRE2Core/setSetting.h @@ -7,7 +7,7 @@ #include RPC_FUNCTION(setSetting) { - ZoneScoped; + ZoneScopedN("RPC - setSetting"); const std::string name = std::string((char *)vMessage->getParameter(0)); float32_t value = vMessage->getParameterAsFloat(1); diff --git a/extensions/src/ACRE2Core/setSoundSystemMasterOverride.h b/extensions/src/ACRE2Core/setSoundSystemMasterOverride.h index 79f21ad08..dc4a7d02e 100644 --- a/extensions/src/ACRE2Core/setSoundSystemMasterOverride.h +++ b/extensions/src/ACRE2Core/setSoundSystemMasterOverride.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(setSoundSystemMasterOverride) { - ZoneScoped; + ZoneScopedN("RPC - setSoundSystemMasterOverride"); const bool status = vMessage->getParameterAsInt(0) == 1; diff --git a/extensions/src/ACRE2Core/setVoiceCurveModel.h b/extensions/src/ACRE2Core/setVoiceCurveModel.h index 69cf7acb4..0c8d7ee1c 100644 --- a/extensions/src/ACRE2Core/setVoiceCurveModel.h +++ b/extensions/src/ACRE2Core/setVoiceCurveModel.h @@ -7,7 +7,7 @@ #include RPC_FUNCTION(setVoiceCurveModel) { - ZoneScoped; + ZoneScopedN("RPC - setVoiceCurveModel"); const acre::CurveModel voiceModel = static_cast(vMessage->getParameterAsInt(0)); const float32_t voiceCurveScale = vMessage->getParameterAsFloat(1); diff --git a/extensions/src/ACRE2Core/startGodModeSpeaking.h b/extensions/src/ACRE2Core/startGodModeSpeaking.h index afe1438b9..5cf281589 100644 --- a/extensions/src/ACRE2Core/startGodModeSpeaking.h +++ b/extensions/src/ACRE2Core/startGodModeSpeaking.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(startGodModeSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - startGodModeSpeaking"); CEngine::getInstance()->getClient()->localStartSpeaking(acre::Speaking::god); diff --git a/extensions/src/ACRE2Core/startIntercomSpeaking.h b/extensions/src/ACRE2Core/startIntercomSpeaking.h index 30310b622..c66225733 100644 --- a/extensions/src/ACRE2Core/startIntercomSpeaking.h +++ b/extensions/src/ACRE2Core/startIntercomSpeaking.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(startIntercomSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - startIntercomSpeaking"); CEngine::getInstance()->getClient()->localStartSpeaking(acre::Speaking::intercom); diff --git a/extensions/src/ACRE2Core/startRadioSpeaking.h b/extensions/src/ACRE2Core/startRadioSpeaking.h index 3b46cb799..71c4c13ce 100644 --- a/extensions/src/ACRE2Core/startRadioSpeaking.h +++ b/extensions/src/ACRE2Core/startRadioSpeaking.h @@ -16,7 +16,7 @@ #include RPC_FUNCTION(startRadioSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - startRadioSpeaking"); const std::string radioId = std::string((char *)vMessage->getParameter(0)); diff --git a/extensions/src/ACRE2Core/startZeusSpeaking.h b/extensions/src/ACRE2Core/startZeusSpeaking.h index 1dec7d175..a4576e495 100644 --- a/extensions/src/ACRE2Core/startZeusSpeaking.h +++ b/extensions/src/ACRE2Core/startZeusSpeaking.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(startZeusSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - startZeusSpeaking"); CEngine::getInstance()->getClient()->localStartSpeaking(acre::Speaking::zeus); diff --git a/extensions/src/ACRE2Core/stopGodModeSpeaking.h b/extensions/src/ACRE2Core/stopGodModeSpeaking.h index 8d5ba3ff7..46b3456d4 100644 --- a/extensions/src/ACRE2Core/stopGodModeSpeaking.h +++ b/extensions/src/ACRE2Core/stopGodModeSpeaking.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(stopGodModeSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - stopGodModeSpeaking"); CEngine::getInstance()->getClient()->localStopSpeaking(acre::Speaking::god); diff --git a/extensions/src/ACRE2Core/stopIntercomSpeaking.h b/extensions/src/ACRE2Core/stopIntercomSpeaking.h index 26da1626f..6819865e9 100644 --- a/extensions/src/ACRE2Core/stopIntercomSpeaking.h +++ b/extensions/src/ACRE2Core/stopIntercomSpeaking.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(stopIntercomSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - stopIntercomSpeaking"); CEngine::getInstance()->getClient()->localStopSpeaking(acre::Speaking::intercom); diff --git a/extensions/src/ACRE2Core/stopRadioSpeaking.h b/extensions/src/ACRE2Core/stopRadioSpeaking.h index a881cef35..d1728f703 100644 --- a/extensions/src/ACRE2Core/stopRadioSpeaking.h +++ b/extensions/src/ACRE2Core/stopRadioSpeaking.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(stopRadioSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - stopRadioSpeaking"); CEngine::getInstance()->getClient()->localStopSpeaking(acre::Speaking::radio); diff --git a/extensions/src/ACRE2Core/stopZeusSpeaking.h b/extensions/src/ACRE2Core/stopZeusSpeaking.h index 6b3928a1b..0a50dd677 100644 --- a/extensions/src/ACRE2Core/stopZeusSpeaking.h +++ b/extensions/src/ACRE2Core/stopZeusSpeaking.h @@ -14,7 +14,7 @@ #include RPC_FUNCTION(stopZeusSpeaking) { - ZoneScoped; + ZoneScopedN("RPC - stopZeuSpeaking"); CEngine::getInstance()->getClient()->localStopSpeaking(acre::Speaking::zeus); diff --git a/extensions/src/ACRE2Core/updateSelf.h b/extensions/src/ACRE2Core/updateSelf.h index 5925d0533..b2d3f9148 100644 --- a/extensions/src/ACRE2Core/updateSelf.h +++ b/extensions/src/ACRE2Core/updateSelf.h @@ -15,7 +15,7 @@ #include RPC_FUNCTION(updateSelf) { - ZoneScoped; + ZoneScopedN("RPC - updateSelf"); LOCK(CEngine::getInstance()->getSelf()); diff --git a/extensions/src/ACRE2Core/updateSpeakingData.h b/extensions/src/ACRE2Core/updateSpeakingData.h index 3858c6815..48d07fe7e 100644 --- a/extensions/src/ACRE2Core/updateSpeakingData.h +++ b/extensions/src/ACRE2Core/updateSpeakingData.h @@ -15,7 +15,7 @@ #include RPC_FUNCTION(updateSpeakingData) { - ZoneScoped; + ZoneScopedN("RPC - updateSpeakingData"); CPlayer *speaker = nullptr; diff --git a/extensions/src/ACRE2Mumble/MumbleClient.cpp b/extensions/src/ACRE2Mumble/MumbleClient.cpp index 82fe13668..ddea7c6e6 100644 --- a/extensions/src/ACRE2Mumble/MumbleClient.cpp +++ b/extensions/src/ACRE2Mumble/MumbleClient.cpp @@ -433,8 +433,6 @@ uint64_t CMumbleClient::findChannelByNames(std::vector details_) { } acre::Result CMumbleClient::updateChannelDetails(std::vector details_) { - ZoneScoped; - setChannelDetails(details_); if (!details_.empty()) { updateShouldSwitchChannel(true); @@ -443,14 +441,10 @@ acre::Result CMumbleClient::updateChannelDetails(std::vector detail } acre::Result CMumbleClient::updateShouldSwitchChannel(const bool state_) { - ZoneScoped; - setShouldSwitchChannel(state_); return acre::Result::ok; } bool CMumbleClient::shouldSwitchChannel() { - ZoneScoped; - return getShouldSwitchChannel(); } diff --git a/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp b/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp index e47b30c38..7437447ff 100644 --- a/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp +++ b/extensions/src/ACRE2Mumble/MumbleEventLoop.cpp @@ -64,32 +64,33 @@ namespace acre { } void MumbleEventLoop::run() { - ZoneScoped; tracy::SetThreadName("ACRE2-Mumble-EventLoop"); std::unique_lock guard(m_lock); + const char *frameName = "ACRE2 MumbleEventLoop"; while (m_keepRunning || m_drain) { - { - ZoneScopedN("MumbleEventLoop::run - process pending events"); - m_drain = false; - - // Process all pending events - while (!m_queuedFunctions.empty()) { - std::function currentFunc = std::move(m_queuedFunctions.front()); - m_queuedFunctions.pop_front(); - - // Execute the current funtion. However, during the time this function is executing, there is no need to - // keep holding m_lock. By releasing it for that time, we allow further functions to be queued by other threads. - // This gets especially important if the called function will call a Mumble API function. This function will require - // to run in Mumble's main thread but if that thread is in turn waiting until a new event is queued (in one of the - // plugin callbacks in this plugin), we end up with a deadlock. - guard.unlock(); - currentFunc(); - guard.lock(); - } + FrameMarkStart(frameName); + + m_drain = false; + + // Process all pending events + while (!m_queuedFunctions.empty()) { + std::function currentFunc = std::move(m_queuedFunctions.front()); + m_queuedFunctions.pop_front(); + + // Execute the current funtion. However, during the time this function is executing, there is no need to + // keep holding m_lock. By releasing it for that time, we allow further functions to be queued by other threads. + // This gets especially important if the called function will call a Mumble API function. This function will require + // to run in Mumble's main thread but if that thread is in turn waiting until a new event is queued (in one of the + // plugin callbacks in this plugin), we end up with a deadlock. + guard.unlock(); + currentFunc(); + guard.lock(); } + FrameMarkEnd(frameName); + if (!m_keepRunning) { break; } diff --git a/extensions/src/ACRE2Shared/EntrantWorker.h b/extensions/src/ACRE2Shared/EntrantWorker.h index 2d5c9e4f2..599aef4e7 100644 --- a/extensions/src/ACRE2Shared/EntrantWorker.h +++ b/extensions/src/ACRE2Shared/EntrantWorker.h @@ -47,13 +47,9 @@ template class TEntrantWorker : public CLockable { } acre::Result exWorkerThread() { - ZoneScoped; - while (!getShuttingDown()) { LOCK(this); if (!m_processQueue.empty()) { - ZoneScopedN("exWorkerThread - processing queue item"); - const T item = m_processQueue.front(); m_processQueue.pop(); exProcessItem(item);