forked from qt-creator/qt-creator
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:
@@ -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 ¶ms)
|
|||||||
: 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
|
||||||
|
@@ -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,
|
||||||
|
Reference in New Issue
Block a user