3 * Copyright 2015 gRPC authors.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
19 #include <grpc/support/port_platform.h>
21 #include "src/core/lib/surface/call.h"
25 #include <grpc/support/alloc.h>
26 #include <grpc/support/string_util.h>
27 #include "src/core/lib/gpr/string.h"
28 #include "src/core/lib/slice/slice_string_helpers.h"
30 static void add_metadata(gpr_strvec* b, const grpc_metadata* md, size_t count) {
33 gpr_strvec_add(b, gpr_strdup("(nil)"));
36 for (i = 0; i < count; i++) {
37 gpr_strvec_add(b, gpr_strdup("\nkey="));
38 gpr_strvec_add(b, grpc_slice_to_c_string(md[i].key));
40 gpr_strvec_add(b, gpr_strdup(" value="));
42 grpc_dump_slice(md[i].value, GPR_DUMP_HEX | GPR_DUMP_ASCII));
46 char* grpc_op_string(const grpc_op* op) {
54 case GRPC_OP_SEND_INITIAL_METADATA:
55 gpr_strvec_add(&b, gpr_strdup("SEND_INITIAL_METADATA"));
56 add_metadata(&b, op->data.send_initial_metadata.metadata,
57 op->data.send_initial_metadata.count);
59 case GRPC_OP_SEND_MESSAGE:
60 gpr_asprintf(&tmp, "SEND_MESSAGE ptr=%p",
61 op->data.send_message.send_message);
62 gpr_strvec_add(&b, tmp);
64 case GRPC_OP_SEND_CLOSE_FROM_CLIENT:
65 gpr_strvec_add(&b, gpr_strdup("SEND_CLOSE_FROM_CLIENT"));
67 case GRPC_OP_SEND_STATUS_FROM_SERVER:
68 gpr_asprintf(&tmp, "SEND_STATUS_FROM_SERVER status=%d details=",
69 op->data.send_status_from_server.status);
70 gpr_strvec_add(&b, tmp);
71 if (op->data.send_status_from_server.status_details != nullptr) {
72 gpr_strvec_add(&b, grpc_dump_slice(
73 *op->data.send_status_from_server.status_details,
76 gpr_strvec_add(&b, gpr_strdup("(null)"));
78 add_metadata(&b, op->data.send_status_from_server.trailing_metadata,
79 op->data.send_status_from_server.trailing_metadata_count);
81 case GRPC_OP_RECV_INITIAL_METADATA:
82 gpr_asprintf(&tmp, "RECV_INITIAL_METADATA ptr=%p",
83 op->data.recv_initial_metadata.recv_initial_metadata);
84 gpr_strvec_add(&b, tmp);
86 case GRPC_OP_RECV_MESSAGE:
87 gpr_asprintf(&tmp, "RECV_MESSAGE ptr=%p",
88 op->data.recv_message.recv_message);
89 gpr_strvec_add(&b, tmp);
91 case GRPC_OP_RECV_STATUS_ON_CLIENT:
93 "RECV_STATUS_ON_CLIENT metadata=%p status=%p details=%p",
94 op->data.recv_status_on_client.trailing_metadata,
95 op->data.recv_status_on_client.status,
96 op->data.recv_status_on_client.status_details);
97 gpr_strvec_add(&b, tmp);
99 case GRPC_OP_RECV_CLOSE_ON_SERVER:
100 gpr_asprintf(&tmp, "RECV_CLOSE_ON_SERVER cancelled=%p",
101 op->data.recv_close_on_server.cancelled);
102 gpr_strvec_add(&b, tmp);
104 out = gpr_strvec_flatten(&b, nullptr);
105 gpr_strvec_destroy(&b);
110 void grpc_call_log_batch(const char* file, int line, gpr_log_severity severity,
111 grpc_call* call, const grpc_op* ops, size_t nops,
115 for (i = 0; i < nops; i++) {
116 tmp = grpc_op_string(&ops[i]);
117 gpr_log(file, line, severity, "ops[%" PRIuPTR "]: %s", i, tmp);