From dec8967df2f3592bba2b93ea39ede673748a8901 Mon Sep 17 00:00:00 2001 From: Petr Mironychev <9195189+Palm1r@users.noreply.github.com> Date: Sat, 31 Aug 2024 23:56:54 +0200 Subject: [PATCH] Add performance benchmark --- LLMClientInterface.cpp | 27 +++++++++++++++++++++++++++ LLMClientInterface.hpp | 7 +++++++ 2 files changed, 34 insertions(+) diff --git a/LLMClientInterface.cpp b/LLMClientInterface.cpp index 9414ebb..cba2f0b 100644 --- a/LLMClientInterface.cpp +++ b/LLMClientInterface.cpp @@ -69,6 +69,8 @@ void LLMClientInterface::sendData(const QByteArray &data) } else if (method == "textDocument/didOpen") { handleTextDocumentDidOpen(request); } else if (method == "getCompletionsCycling") { + QString requestId = request["id"].toString(); + startTimeMeasurement(requestId); handleCompletion(request); } else if (method == "$/cancelRequest") { handleCancelRequest(request); @@ -316,6 +318,8 @@ void LLMClientInterface::sendCompletionToClient(const QString &completion, logMessage(QString("Full response: \n%1") .arg(QString::fromUtf8(QJsonDocument(response).toJson(QJsonDocument::Indented)))); + QString requestId = request["id"].toString(); + endTimeMeasurement(requestId); emit messageReceived(LanguageServerProtocol::JsonRpcMessage(response)); } @@ -381,6 +385,29 @@ QString LLMClientInterface::removeStopWords(const QString &completion) return filteredCompletion; } +void LLMClientInterface::startTimeMeasurement(const QString &requestId) +{ + m_requestStartTimes[requestId] = QDateTime::currentMSecsSinceEpoch(); +} + +void LLMClientInterface::endTimeMeasurement(const QString &requestId) +{ + if (m_requestStartTimes.contains(requestId)) { + qint64 startTime = m_requestStartTimes[requestId]; + qint64 endTime = QDateTime::currentMSecsSinceEpoch(); + qint64 totalTime = endTime - startTime; + logPerformance(requestId, "TotalCompletionTime", totalTime); + m_requestStartTimes.remove(requestId); + } +} + +void LLMClientInterface::logPerformance(const QString &requestId, + const QString &operation, + qint64 elapsedMs) +{ + logMessage(QString("Performance: %1 %2 took %3 ms").arg(requestId, operation).arg(elapsedMs)); +} + void LLMClientInterface::parseCurrentMessage() {} } // namespace QodeAssist diff --git a/LLMClientInterface.hpp b/LLMClientInterface.hpp index 6fef777..a648806 100644 --- a/LLMClientInterface.hpp +++ b/LLMClientInterface.hpp @@ -81,6 +81,13 @@ private: QNetworkAccessManager *m_manager; QMap m_activeRequests; QMap m_accumulatedResponses; + + QElapsedTimer m_completionTimer; + QMap m_requestStartTimes; + + void startTimeMeasurement(const QString &requestId); + void endTimeMeasurement(const QString &requestId); + void logPerformance(const QString &requestId, const QString &operation, qint64 elapsedMs); }; } // namespace QodeAssist