Debian Codegraph @

src/core/lib/transport/transport_op_string.cc

raw
1 /*
2 *
3 * Copyright 2015 gRPC authors.
4 *
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
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
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.
16 *
17 */
18
19 #include <grpc/support/port_platform.h>
20
21 #include <algorithm>
22 #include <memory>
23 #include <string>
24 #include <vector>
25
26 #include "absl/strings/str_cat.h"
27 #include "absl/strings/str_format.h"
28 #include "absl/strings/str_join.h"
29
30 #include <grpc/support/log.h>
31
32 #include "src/core/lib/channel/channel_fwd.h"
33 #include "src/core/lib/channel/channel_stack.h"
34 #include "src/core/lib/gprpp/orphanable.h"
35 #include "src/core/lib/gprpp/status_helper.h"
36 #include "src/core/lib/iomgr/error.h"
37 #include "src/core/lib/slice/slice_buffer.h"
38 #include "src/core/lib/transport/connectivity_state.h"
39 #include "src/core/lib/transport/metadata_batch.h"
40 #include "src/core/lib/transport/transport.h"
41
42 /* These routines are here to facilitate debugging - they produce string
43 representations of various transport data structures */
44
45 std::string grpc_transport_stream_op_batch_string(
46 grpc_transport_stream_op_batch* op) {
47 std::vector<std::string> out;
48
49 if (op->send_initial_metadata) {
50 out.push_back(" SEND_INITIAL_METADATA{");
51 out.push_back(op->payload->send_initial_metadata.send_initial_metadata
52 ->DebugString());
53 out.push_back("}");
54 }
55
56 if (op->send_message) {
57 if (op->payload->send_message.send_message != nullptr) {
58 out.push_back(absl::StrFormat(
59 " SEND_MESSAGE:flags=0x%08x:len=%d", op->payload->send_message.flags,
60 op->payload->send_message.send_message->Length()));
61 } else {
62 // This can happen when we check a batch after the transport has
63 // processed and cleared the send_message op.
64 out.push_back(" SEND_MESSAGE(flag and length unknown, already orphaned)");
65 }
66 }
67
68 if (op->send_trailing_metadata) {
69 out.push_back(" SEND_TRAILING_METADATA{");
70 out.push_back(op->payload->send_trailing_metadata.send_trailing_metadata
71 ->DebugString());
72 out.push_back("}");
73 }
74
75 if (op->recv_initial_metadata) {
76 out.push_back(" RECV_INITIAL_METADATA");
77 }
78
79 if (op->recv_message) {
80 out.push_back(" RECV_MESSAGE");
81 }
82
83 if (op->recv_trailing_metadata) {
84 out.push_back(" RECV_TRAILING_METADATA");
85 }
86
87 if (op->cancel_stream) {
88 out.push_back(absl::StrCat(
89 " CANCEL:",
90 grpc_core::StatusToString(op->payload->cancel_stream.cancel_error)));
91 }
92
93 return absl::StrJoin(out, "");
94 }
95
96 std::string grpc_transport_op_string(grpc_transport_op* op) {
97 std::vector<std::string> out;
98
99 if (op->start_connectivity_watch != nullptr) {
100 out.push_back(absl::StrFormat(
101 " START_CONNECTIVITY_WATCH:watcher=%p:from=%s",
102 op->start_connectivity_watch.get(),
103 grpc_core::ConnectivityStateName(op->start_connectivity_watch_state)));
104 }
105
106 if (op->stop_connectivity_watch != nullptr) {
107 out.push_back(absl::StrFormat(" STOP_CONNECTIVITY_WATCH:watcher=%p",
108 op->stop_connectivity_watch));
109 }
110
111 if (!op->disconnect_with_error.ok()) {
112 out.push_back(absl::StrCat(
113 " DISCONNECT:", grpc_core::StatusToString(op->disconnect_with_error)));
114 }
115
116 if (!op->goaway_error.ok()) {
117 out.push_back(absl::StrCat(" SEND_GOAWAY:",
118 grpc_core::StatusToString(op->goaway_error)));
119 }
120
121 if (op->set_accept_stream) {
122 out.push_back(absl::StrFormat(" SET_ACCEPT_STREAM:%p(%p,...)",
123 op->set_accept_stream_fn,
124 op->set_accept_stream_user_data));
125 }
126
127 if (op->bind_pollset != nullptr) {
128 out.push_back(" BIND_POLLSET");
129 }
130
131 if (op->bind_pollset_set != nullptr) {
132 out.push_back(" BIND_POLLSET_SET");
133 }
134
135 if (op->send_ping.on_initiate != nullptr || op->send_ping.on_ack != nullptr) {
136 out.push_back(" SEND_PING");
137 }
138
139 return absl::StrJoin(out, "");
140 }
141
142 void grpc_call_log_op(const char* file, int line, gpr_log_severity severity,
143 grpc_call_element* elem,
144 grpc_transport_stream_op_batch* op) {
145 gpr_log(file, line, severity, "OP[%s:%p]: %s", elem->filter->name, elem,
146 grpc_transport_stream_op_batch_string(op).c_str());
147 }