33#include " remote/jsonrpcconnection.hpp"
44#include " remote/apilistener.hpp"
55#include " remote/apifunction.hpp"
6+ #include " base/benchmark.hpp"
67#include " remote/jsonrpc.hpp"
78#include " base/defer.hpp"
89#include " base/configtype.hpp"
@@ -66,11 +67,17 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
6667 return ch::duration_cast<ch::milliseconds>(d).count ();
6768 });
6869
70+ Benchmark::Clock::time_point readStarted, readFinished, processingStarted;
71+
6972 m_Stream->next_layer ().SetSeen (&m_Seen);
7073
7174 while (!m_ShuttingDown) {
7275 String jsonString;
7376
77+ if (m_Endpoint) {
78+ readStarted = Benchmark::Clock::now ();
79+ }
80+
7481 try {
7582 jsonString = JsonRpc::ReadMessage (m_Stream, yc, m_Endpoint ? -1 : 1024 * 1024 );
7683 } catch (const std::exception& ex) {
@@ -81,6 +88,10 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
8188 break ;
8289 }
8390
91+ if (m_Endpoint) {
92+ readFinished = Benchmark::Clock::now ();
93+ }
94+
8495 m_Seen = Utility::GetTime ();
8596 if (m_Endpoint) {
8697 m_Endpoint->AddMessageReceived (jsonString.GetLength ());
@@ -96,13 +107,21 @@ void JsonRpcConnection::HandleIncomingMessages(boost::asio::yield_context yc)
96107 // Cache the elapsed time to acquire a CPU semaphore used to detect extremely heavy workloads.
97108 cpuBoundDuration = ch::steady_clock::now () - start;
98109
110+ if (m_Endpoint) {
111+ processingStarted = Benchmark::Clock::now ();
112+ }
113+
99114 Dictionary::Ptr message = JsonRpc::DecodeMessage (jsonString);
100115 if (String method = message->Get (" method" ); !method.IsEmpty ()) {
101116 rpcMethod = std::move (method);
102117 }
103118
104119 MessageHandler (message);
105120
121+ if (m_Endpoint) {
122+ m_Endpoint->AddInputTimes (readFinished - readStarted, processingStarted);
123+ }
124+
106125 l_TaskStats.InsertValue (Utility::GetTime (), 1 );
107126
108127 auto total = ch::steady_clock::now () - start;
0 commit comments