• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
22 #include <string>
23 
24 #include "absl/strings/str_cat.h"
25 #include "absl/strings/str_format.h"
26 #include "src/core/lib/channel/channel_fwd.h"
27 #include "src/core/lib/slice/slice_buffer.h"
28 #include "src/core/lib/transport/connectivity_state.h"
29 #include "src/core/lib/transport/metadata_batch.h"
30 #include "src/core/lib/transport/transport.h"
31 #include "src/core/util/orphanable.h"
32 #include "src/core/util/status_helper.h"
33 
34 // These routines are here to facilitate debugging - they produce string
35 // representations of various transport data structures
36 
grpc_transport_stream_op_batch_string(grpc_transport_stream_op_batch * op,bool truncate)37 std::string grpc_transport_stream_op_batch_string(
38     grpc_transport_stream_op_batch* op, bool truncate) {
39   std::string out;
40 
41   if (op->send_initial_metadata) {
42     absl::StrAppend(&out, " SEND_INITIAL_METADATA{");
43     if (truncate) {
44       absl::StrAppend(&out, "Length=",
45                       op->payload->send_initial_metadata.send_initial_metadata
46                           ->TransportSize());
47     } else {
48       absl::StrAppend(&out, op->payload->send_initial_metadata
49                                 .send_initial_metadata->DebugString());
50     }
51     absl::StrAppend(&out, "}");
52   }
53 
54   if (op->send_message) {
55     if (op->payload->send_message.send_message != nullptr) {
56       absl::StrAppendFormat(&out, " SEND_MESSAGE:flags=0x%08x:len=%d",
57                             op->payload->send_message.flags,
58                             op->payload->send_message.send_message->Length());
59     } else {
60       // This can happen when we check a batch after the transport has
61       // processed and cleared the send_message op.
62       absl::StrAppend(
63           &out, " SEND_MESSAGE(flag and length unknown, already orphaned)");
64     }
65   }
66 
67   if (op->send_trailing_metadata) {
68     absl::StrAppend(&out, " SEND_TRAILING_METADATA{");
69     if (truncate) {
70       absl::StrAppend(&out, "Length=",
71                       op->payload->send_trailing_metadata
72                           .send_trailing_metadata->TransportSize());
73     } else {
74       absl::StrAppend(&out, op->payload->send_trailing_metadata
75                                 .send_trailing_metadata->DebugString());
76     }
77     absl::StrAppend(&out, "}");
78   }
79 
80   if (op->recv_initial_metadata) {
81     absl::StrAppend(&out, " RECV_INITIAL_METADATA");
82   }
83 
84   if (op->recv_message) {
85     absl::StrAppend(&out, " RECV_MESSAGE");
86   }
87 
88   if (op->recv_trailing_metadata) {
89     absl::StrAppend(&out, " RECV_TRAILING_METADATA");
90   }
91 
92   if (op->cancel_stream) {
93     absl::StrAppend(
94         &out, " CANCEL:",
95         grpc_core::StatusToString(op->payload->cancel_stream.cancel_error));
96   }
97 
98   return out;
99 }
100 
grpc_transport_op_string(grpc_transport_op * op)101 std::string grpc_transport_op_string(grpc_transport_op* op) {
102   std::string out;
103 
104   if (op->start_connectivity_watch != nullptr) {
105     absl::StrAppendFormat(
106         &out, " START_CONNECTIVITY_WATCH:watcher=%p:from=%s",
107         op->start_connectivity_watch.get(),
108         grpc_core::ConnectivityStateName(op->start_connectivity_watch_state));
109   }
110 
111   if (op->stop_connectivity_watch != nullptr) {
112     absl::StrAppendFormat(&out, " STOP_CONNECTIVITY_WATCH:watcher=%p",
113                           op->stop_connectivity_watch);
114   }
115 
116   if (!op->disconnect_with_error.ok()) {
117     absl::StrAppend(&out, " DISCONNECT:",
118                     grpc_core::StatusToString(op->disconnect_with_error));
119   }
120 
121   if (!op->goaway_error.ok()) {
122     absl::StrAppend(
123         &out, " SEND_GOAWAY:", grpc_core::StatusToString(op->goaway_error));
124   }
125 
126   if (op->set_accept_stream) {
127     absl::StrAppendFormat(&out, " SET_ACCEPT_STREAM:%p(%p,...)",
128                           op->set_accept_stream_fn,
129                           op->set_accept_stream_user_data);
130   }
131 
132   if (op->bind_pollset != nullptr) {
133     absl::StrAppend(&out, " BIND_POLLSET");
134   }
135 
136   if (op->bind_pollset_set != nullptr) {
137     absl::StrAppend(&out, " BIND_POLLSET_SET");
138   }
139 
140   if (op->send_ping.on_initiate != nullptr || op->send_ping.on_ack != nullptr) {
141     absl::StrAppend(&out, " SEND_PING");
142   }
143 
144   return out;
145 }
146