Skip to content

Commit

Permalink
Created local RuntimeLoggingCategories in HidIoThread, which improved…
Browse files Browse the repository at this point in the history
… the performance of the logging statements from milliseconds to some microseconds
  • Loading branch information
JoergAtGithub committed Jan 5, 2022
1 parent 3cd3c3c commit da8b9b7
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 23 deletions.
6 changes: 1 addition & 5 deletions src/controllers/hid/hidcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
27 changes: 15 additions & 12 deletions src/controllers/hid/hidio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
}

Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -188,7 +191,7 @@ void HidIoThread::sendOutputReport(const QByteArray& data, unsigned int reportID
if (m_outputReports.find(reportID) == m_outputReports.end()) {
std::unique_ptr<HidIoReport> pNewOutputReport;
m_outputReports[reportID] = std::make_unique<HidIoReport>(
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);
Expand Down
8 changes: 2 additions & 6 deletions src/controllers/hid/hidio.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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();

Expand Down

0 comments on commit da8b9b7

Please sign in to comment.