@@ -94,10 +94,14 @@ class RemoteIndexServer final : public v1::SymbolIndex::Service {
94
94
}
95
95
96
96
private:
97
+ using stopwatch = std::chrono::steady_clock;
98
+
97
99
grpc::Status Lookup (grpc::ServerContext *Context,
98
100
const LookupRequest *Request,
99
101
grpc::ServerWriter<LookupReply> *Reply) override {
100
- WithContextValue (CurrentRequest, Context);
102
+ auto StartTime = stopwatch::now ();
103
+ WithContextValue WithRequestContext (CurrentRequest, Context);
104
+ logRequest (*Request);
101
105
trace::Span Tracer (" LookupRequest" );
102
106
auto Req = ProtobufMarshaller->fromProtobuf (Request);
103
107
if (!Req) {
@@ -116,21 +120,26 @@ class RemoteIndexServer final : public v1::SymbolIndex::Service {
116
120
}
117
121
LookupReply NextMessage;
118
122
*NextMessage.mutable_stream_result () = *SerializedItem;
123
+ logResponse (NextMessage);
119
124
Reply->Write (NextMessage);
120
125
++Sent;
121
126
});
122
127
LookupReply LastMessage;
123
128
LastMessage.mutable_final_result ()->set_has_more (true );
129
+ logResponse (LastMessage);
124
130
Reply->Write (LastMessage);
125
131
SPAN_ATTACH (Tracer, " Sent" , Sent);
126
132
SPAN_ATTACH (Tracer, " Failed to send" , FailedToSend);
133
+ logRequestSummary (" v1/Lookup" , Sent, StartTime);
127
134
return grpc::Status::OK;
128
135
}
129
136
130
137
grpc::Status FuzzyFind (grpc::ServerContext *Context,
131
138
const FuzzyFindRequest *Request,
132
139
grpc::ServerWriter<FuzzyFindReply> *Reply) override {
133
- WithContextValue (CurrentRequest, Context);
140
+ auto StartTime = stopwatch::now ();
141
+ WithContextValue WithRequestContext (CurrentRequest, Context);
142
+ logRequest (*Request);
134
143
trace::Span Tracer (" FuzzyFindRequest" );
135
144
auto Req = ProtobufMarshaller->fromProtobuf (Request);
136
145
if (!Req) {
@@ -150,20 +159,25 @@ class RemoteIndexServer final : public v1::SymbolIndex::Service {
150
159
}
151
160
FuzzyFindReply NextMessage;
152
161
*NextMessage.mutable_stream_result () = *SerializedItem;
162
+ logResponse (NextMessage);
153
163
Reply->Write (NextMessage);
154
164
++Sent;
155
165
});
156
166
FuzzyFindReply LastMessage;
157
167
LastMessage.mutable_final_result ()->set_has_more (HasMore);
168
+ logResponse (LastMessage);
158
169
Reply->Write (LastMessage);
159
170
SPAN_ATTACH (Tracer, " Sent" , Sent);
160
171
SPAN_ATTACH (Tracer, " Failed to send" , FailedToSend);
172
+ logRequestSummary (" v1/FuzzyFind" , Sent, StartTime);
161
173
return grpc::Status::OK;
162
174
}
163
175
164
176
grpc::Status Refs (grpc::ServerContext *Context, const RefsRequest *Request,
165
177
grpc::ServerWriter<RefsReply> *Reply) override {
166
- WithContextValue (CurrentRequest, Context);
178
+ auto StartTime = stopwatch::now ();
179
+ WithContextValue WithRequestContext (CurrentRequest, Context);
180
+ logRequest (*Request);
167
181
trace::Span Tracer (" RefsRequest" );
168
182
auto Req = ProtobufMarshaller->fromProtobuf (Request);
169
183
if (!Req) {
@@ -182,21 +196,26 @@ class RemoteIndexServer final : public v1::SymbolIndex::Service {
182
196
}
183
197
RefsReply NextMessage;
184
198
*NextMessage.mutable_stream_result () = *SerializedItem;
199
+ logResponse (NextMessage);
185
200
Reply->Write (NextMessage);
186
201
++Sent;
187
202
});
188
203
RefsReply LastMessage;
189
204
LastMessage.mutable_final_result ()->set_has_more (HasMore);
205
+ logResponse (LastMessage);
190
206
Reply->Write (LastMessage);
191
207
SPAN_ATTACH (Tracer, " Sent" , Sent);
192
208
SPAN_ATTACH (Tracer, " Failed to send" , FailedToSend);
209
+ logRequestSummary (" v1/Refs" , Sent, StartTime);
193
210
return grpc::Status::OK;
194
211
}
195
212
196
213
grpc::Status Relations (grpc::ServerContext *Context,
197
214
const RelationsRequest *Request,
198
215
grpc::ServerWriter<RelationsReply> *Reply) override {
199
- WithContextValue (CurrentRequest, Context);
216
+ auto StartTime = stopwatch::now ();
217
+ WithContextValue WithRequestContext (CurrentRequest, Context);
218
+ logRequest (*Request);
200
219
trace::Span Tracer (" RelationsRequest" );
201
220
auto Req = ProtobufMarshaller->fromProtobuf (Request);
202
221
if (!Req) {
@@ -217,17 +236,44 @@ class RemoteIndexServer final : public v1::SymbolIndex::Service {
217
236
}
218
237
RelationsReply NextMessage;
219
238
*NextMessage.mutable_stream_result () = *SerializedItem;
239
+ logResponse (NextMessage);
220
240
Reply->Write (NextMessage);
221
241
++Sent;
222
242
});
223
243
RelationsReply LastMessage;
224
244
LastMessage.mutable_final_result ()->set_has_more (true );
245
+ logResponse (LastMessage);
225
246
Reply->Write (LastMessage);
226
247
SPAN_ATTACH (Tracer, " Sent" , Sent);
227
248
SPAN_ATTACH (Tracer, " Failed to send" , FailedToSend);
249
+ logRequestSummary (" v1/Relations" , Sent, StartTime);
228
250
return grpc::Status::OK;
229
251
}
230
252
253
+ // Proxy object to allow proto messages to be lazily serialized as text.
254
+ struct TextProto {
255
+ const google::protobuf::Message &M;
256
+ friend llvm::raw_ostream &operator <<(llvm::raw_ostream &OS,
257
+ const TextProto &P) {
258
+ return OS << P.M .DebugString ();
259
+ }
260
+ };
261
+
262
+ void logRequest (const google::protobuf::Message &M) {
263
+ vlog (" <<< {0}\n {1}" , M.GetDescriptor ()->name (), TextProto{M});
264
+ }
265
+ void logResponse (const google::protobuf::Message &M) {
266
+ vlog (" >>> {0}\n {1}" , M.GetDescriptor ()->name (), TextProto{M});
267
+ }
268
+ void logRequestSummary (llvm::StringLiteral RequestName, unsigned Sent,
269
+ stopwatch::time_point StartTime) {
270
+ auto Duration = stopwatch::now () - StartTime;
271
+ auto Millis =
272
+ std::chrono::duration_cast<std::chrono::milliseconds>(Duration).count ();
273
+ log (" [public] request {0} => OK: {1} results in {2}ms" , RequestName, Sent,
274
+ Millis);
275
+ }
276
+
231
277
std::unique_ptr<Marshaller> ProtobufMarshaller;
232
278
clangd::SymbolIndex &Index;
233
279
};
0 commit comments