From da8b9b783e72e1b2b46fdc3594ec19f3563fbb04 Mon Sep 17 00:00:00 2001 From: JoergAtGithub Date: Wed, 5 Jan 2022 21:50:03 +0100 Subject: [PATCH] Created local RuntimeLoggingCategories in HidIoThread, which improved the performance of the logging statements from milliseconds to some microseconds --- src/controllers/hid/hidcontroller.cpp | 6 +----- src/controllers/hid/hidio.cpp | 27 +++++++++++++++------------ src/controllers/hid/hidio.h | 8 ++------ 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/controllers/hid/hidcontroller.cpp b/src/controllers/hid/hidcontroller.cpp index e1bc3537da94..76999b73ddd8 100644 --- a/src/controllers/hid/hidcontroller.cpp +++ b/src/controllers/hid/hidcontroller.cpp @@ -105,11 +105,7 @@ int HidController::open() { if (m_pHidIoThread != nullptr) { qWarning() << "HidIoThread already present for" << getName(); } else { - m_pHidIoThread = new HidIoThread(m_pHidDevice, - std::move(m_deviceInfo), - m_logBase, - m_logInput, - m_logOutput); + m_pHidIoThread = new HidIoThread(m_pHidDevice, std::move(m_deviceInfo)); m_pHidIoThread->setObjectName(QString("HidIoThread %1").arg(getName())); connect(m_pHidIoThread, diff --git a/src/controllers/hid/hidio.cpp b/src/controllers/hid/hidio.cpp index 3acbdda1f8cf..94bbf830669e 100644 --- a/src/controllers/hid/hidio.cpp +++ b/src/controllers/hid/hidio.cpp @@ -14,16 +14,19 @@ namespace { constexpr int kReportIdSize = 1; constexpr int kMaxHidErrorMessageSize = 512; +QString loggingCategoryPrefix(const QString& deviceName) { + return QStringLiteral("controller.") + + RuntimeLoggingCategory::removeInvalidCharsFromCategory(deviceName.toLower()); +} } // namespace HidIoReport::HidIoReport(const unsigned char& reportId, hid_device* device, - const mixxx::hid::DeviceInfo&& deviceInfo, - const RuntimeLoggingCategory& logOutput) + const mixxx::hid::DeviceInfo&& deviceInfo) : m_reportId(reportId), + m_logOutput(loggingCategoryPrefix(deviceInfo.formatName()) + QStringLiteral(".output")), m_pHidDevice(device), m_deviceInfo(std::move(deviceInfo)), - m_logOutput(logOutput), m_lastSentOutputReport() { } @@ -63,16 +66,16 @@ void HidIoReport::sendOutputReport(QByteArray data) { } } -HidIoThread::HidIoThread(hid_device* device, - const mixxx::hid::DeviceInfo&& deviceInfo, - const RuntimeLoggingCategory& logBase, - const RuntimeLoggingCategory& logInput, - const RuntimeLoggingCategory& logOutput) +HidIoThread::HidIoThread( + hid_device* device, const mixxx::hid::DeviceInfo&& deviceInfo) : QThread(), m_pollingBufferIndex(0), - m_logBase(logBase), - m_logInput(logInput), - m_logOutput(logOutput), + // Defining RuntimeLoggingCategories locally in this thread improves runtime performance significiant + m_logBase(loggingCategoryPrefix(deviceInfo.formatName())), + m_logInput(loggingCategoryPrefix(deviceInfo.formatName()) + + QStringLiteral(".input")), + m_logOutput(loggingCategoryPrefix(deviceInfo.formatName()) + + QStringLiteral(".output")), m_pHidDevice(device), m_deviceInfo(std::move(deviceInfo)), m_HidDeviceMutex(QT_RECURSIVE_MUTEX_INIT), @@ -188,7 +191,7 @@ void HidIoThread::sendOutputReport(const QByteArray& data, unsigned int reportID if (m_outputReports.find(reportID) == m_outputReports.end()) { std::unique_ptr pNewOutputReport; m_outputReports[reportID] = std::make_unique( - reportID, m_pHidDevice, std::move(m_deviceInfo), m_logOutput); + reportID, m_pHidDevice, std::move(m_deviceInfo)); } // SendOutputReports executes a hardware operation, which take several milliseconds m_outputReports[reportID]->sendOutputReport(data); diff --git a/src/controllers/hid/hidio.h b/src/controllers/hid/hidio.h index f3b8772274e1..e75f8f134eac 100644 --- a/src/controllers/hid/hidio.h +++ b/src/controllers/hid/hidio.h @@ -13,8 +13,7 @@ class HidIoReport { public: HidIoReport(const unsigned char& reportId, hid_device* device, - const mixxx::hid::DeviceInfo&& deviceInfo, - const RuntimeLoggingCategory& logOutput); + const mixxx::hid::DeviceInfo&& deviceInfo); void sendOutputReport(QByteArray data); private: @@ -30,10 +29,7 @@ class HidIoThread : public QThread { Q_OBJECT public: HidIoThread(hid_device* device, - const mixxx::hid::DeviceInfo&& deviceInfo, - const RuntimeLoggingCategory& logBase, - const RuntimeLoggingCategory& logInput, - const RuntimeLoggingCategory& logOutput); + const mixxx::hid::DeviceInfo&& deviceInfo); void stop();