transport_op_string.cc
Go to the documentation of this file.
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 
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 
40 
41 /* These routines are here to facilitate debugging - they produce string
42  representations of various transport data structures */
43 
46  std::vector<std::string> out;
47 
48  if (op->send_initial_metadata) {
49  out.push_back(" SEND_INITIAL_METADATA{");
50  out.push_back(op->payload->send_initial_metadata.send_initial_metadata
51  ->DebugString());
52  out.push_back("}");
53  }
54 
55  if (op->send_message) {
56  if (op->payload->send_message.send_message != nullptr) {
57  out.push_back(absl::StrFormat(
58  " SEND_MESSAGE:flags=0x%08x:len=%d", op->payload->send_message.flags,
59  op->payload->send_message.send_message->Length()));
60  } else {
61  // This can happen when we check a batch after the transport has
62  // processed and cleared the send_message op.
63  out.push_back(" SEND_MESSAGE(flag and length unknown, already orphaned)");
64  }
65  }
66 
67  if (op->send_trailing_metadata) {
68  out.push_back(" SEND_TRAILING_METADATA{");
69  out.push_back(op->payload->send_trailing_metadata.send_trailing_metadata
70  ->DebugString());
71  out.push_back("}");
72  }
73 
74  if (op->recv_initial_metadata) {
75  out.push_back(" RECV_INITIAL_METADATA");
76  }
77 
78  if (op->recv_message) {
79  out.push_back(" RECV_MESSAGE");
80  }
81 
82  if (op->recv_trailing_metadata) {
83  out.push_back(" RECV_TRAILING_METADATA");
84  }
85 
86  if (op->cancel_stream) {
87  out.push_back(absl::StrCat(
88  " CANCEL:",
89  grpc_error_std_string(op->payload->cancel_stream.cancel_error)));
90  }
91 
92  return absl::StrJoin(out, "");
93 }
94 
96  std::vector<std::string> out;
97 
98  if (op->start_connectivity_watch != nullptr) {
99  out.push_back(absl::StrFormat(
100  " START_CONNECTIVITY_WATCH:watcher=%p:from=%s",
101  op->start_connectivity_watch.get(),
102  grpc_core::ConnectivityStateName(op->start_connectivity_watch_state)));
103  }
104 
105  if (op->stop_connectivity_watch != nullptr) {
106  out.push_back(absl::StrFormat(" STOP_CONNECTIVITY_WATCH:watcher=%p",
107  op->stop_connectivity_watch));
108  }
109 
110  if (!GRPC_ERROR_IS_NONE(op->disconnect_with_error)) {
111  out.push_back(absl::StrCat(
112  " DISCONNECT:", grpc_error_std_string(op->disconnect_with_error)));
113  }
114 
115  if (!GRPC_ERROR_IS_NONE(op->goaway_error)) {
116  out.push_back(
117  absl::StrCat(" SEND_GOAWAY:", grpc_error_std_string(op->goaway_error)));
118  }
119 
120  if (op->set_accept_stream) {
121  out.push_back(absl::StrFormat(" SET_ACCEPT_STREAM:%p(%p,...)",
122  op->set_accept_stream_fn,
123  op->set_accept_stream_user_data));
124  }
125 
126  if (op->bind_pollset != nullptr) {
127  out.push_back(" BIND_POLLSET");
128  }
129 
130  if (op->bind_pollset_set != nullptr) {
131  out.push_back(" BIND_POLLSET_SET");
132  }
133 
134  if (op->send_ping.on_initiate != nullptr || op->send_ping.on_ack != nullptr) {
135  out.push_back(" SEND_PING");
136  }
137 
138  return absl::StrJoin(out, "");
139 }
140 
144  gpr_log(file, line, severity, "OP[%s:%p]: %s", elem->filter->name, elem,
146 }
grpc_op::flags
uint32_t flags
Definition: grpc_types.h:644
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
orphanable.h
log.h
bloat_diff.severity
def severity
Definition: bloat_diff.py:143
metadata_batch.h
absl::StrCat
std::string StrCat(const AlphaNum &a, const AlphaNum &b)
Definition: abseil-cpp/absl/strings/str_cat.cc:98
channel_fwd.h
connectivity_state.h
absl::StrFormat
ABSL_MUST_USE_RESULT std::string StrFormat(const FormatSpec< Args... > &format, const Args &... args)
Definition: abseil-cpp/absl/strings/str_format.h:338
elem
Timer elem
Definition: event_engine/iomgr_event_engine/timer_heap_test.cc:109
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
file
Definition: bloaty/third_party/zlib/examples/gzappend.c:170
grpc_call_element
Definition: channel_stack.h:194
grpc_transport_op
Definition: transport.h:452
gpr_log_severity
gpr_log_severity
Definition: include/grpc/impl/codegen/log.h:45
grpc_call_log_op
void grpc_call_log_op(const char *file, int line, gpr_log_severity severity, grpc_call_element *elem, grpc_transport_stream_op_batch *op)
Definition: transport_op_string.cc:141
absl::StrJoin
std::string StrJoin(Iterator start, Iterator end, absl::string_view sep, Formatter &&fmt)
Definition: abseil-cpp/absl/strings/str_join.h:239
gen_stats_data.c_str
def c_str(s, encoding='ascii')
Definition: gen_stats_data.py:38
channel_stack.h
gpr_log
GPRAPI void gpr_log(const char *file, int line, gpr_log_severity severity, const char *format,...) GPR_PRINT_FORMAT_CHECK(4
error.h
grpc_core::ConnectivityStateName
const char * ConnectivityStateName(grpc_connectivity_state state)
Definition: connectivity_state.cc:38
grpc_error_std_string
std::string grpc_error_std_string(grpc_error_handle error)
Definition: error.cc:944
regen-readme.line
line
Definition: regen-readme.py:30
transport.h
grpc_transport_stream_op_batch_string
std::string grpc_transport_stream_op_batch_string(grpc_transport_stream_op_batch *op)
Definition: transport_op_string.cc:44
grpc_transport_stream_op_batch
Definition: transport.h:284
op
static grpc_op * op
Definition: test/core/fling/client.cc:47
slice_buffer.h
grpc_transport_op_string
std::string grpc_transport_op_string(grpc_transport_op *op)
Definition: transport_op_string.cc:95
GRPC_ERROR_IS_NONE
#define GRPC_ERROR_IS_NONE(err)
Definition: error.h:241
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:40