LSP: Allow users to see timing data

It's often interesting to know how long it takes for a reply to a
request to come in. While that data is in principle already available
from the inspector, a dedicated logging category gives much quicker
results.

Change-Id: Idd43c6e69422140863a7adaa33a7bc17dd8e6492
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2021-10-19 12:07:54 +02:00
parent 5cdce37ea4
commit d40fa5b353
2 changed files with 15 additions and 1 deletions

View File

@@ -37,6 +37,7 @@
#include <QTextCodec> #include <QTextCodec>
namespace LanguageServerProtocol { namespace LanguageServerProtocol {
Q_LOGGING_CATEGORY(timingLog, "qtc.languageserverprotocol.timing", QtWarningMsg)
constexpr const char CancelRequest::methodName[]; constexpr const char CancelRequest::methodName[];
@@ -148,4 +149,10 @@ CancelRequest::CancelRequest(const CancelParameter &params)
: Notification(methodName, params) : Notification(methodName, params)
{ } { }
void logElapsedTime(const QString &method, const QElapsedTimer &t)
{
qCDebug(timingLog) << "received server reply to" << method
<< "after" << t.elapsed() << "ms";
}
} // namespace LanguageServerProtocol } // namespace LanguageServerProtocol

View File

@@ -34,6 +34,7 @@
#include <utils/variant.h> #include <utils/variant.h>
#include <QDebug> #include <QDebug>
#include <QElapsedTimer>
#include <QHash> #include <QHash>
#include <QJsonObject> #include <QJsonObject>
#include <QJsonValue> #include <QJsonValue>
@@ -294,6 +295,8 @@ public:
{ return JsonRpcMessage::isValid(errorMessage) && id().isValid(); } { return JsonRpcMessage::isValid(errorMessage) && id().isValid(); }
}; };
void LANGUAGESERVERPROTOCOL_EXPORT logElapsedTime(const QString &method, const QElapsedTimer &t);
template <typename Result, typename ErrorDataType, typename Params> template <typename Result, typename ErrorDataType, typename Params>
class Request : public Notification<Params> class Request : public Notification<Params>
{ {
@@ -316,9 +319,13 @@ public:
Utils::optional<ResponseHandler> responseHandler() const final Utils::optional<ResponseHandler> responseHandler() const final
{ {
auto callback = [callback = m_callBack](const QByteArray &content, QTextCodec *codec) { QElapsedTimer timer;
timer.start();
auto callback = [callback = m_callBack, method = this->method(), t = std::move(timer)]
(const QByteArray &content, QTextCodec *codec) {
if (!callback) if (!callback)
return; return;
logElapsedTime(method, t);
QString parseError; QString parseError;
const QJsonObject &object = JsonRpcMessageHandler::toJsonObject(content, const QJsonObject &object = JsonRpcMessageHandler::toJsonObject(content,
codec, codec,