From d82dff4ea042752009f23aa2a87f56016050cc6c Mon Sep 17 00:00:00 2001 From: ncteisen Date: Tue, 30 Oct 2018 09:04:41 -0700 Subject: reviewer feedback, debuging helper --- src/core/lib/channel/channelz.cc | 19 ++++--------------- src/core/lib/channel/channelz.h | 2 +- src/core/lib/channel/channelz_registry.cc | 11 +++++++++++ src/core/lib/channel/channelz_registry.h | 6 ++++++ 4 files changed, 22 insertions(+), 16 deletions(-) (limited to 'src/core/lib') diff --git a/src/core/lib/channel/channelz.cc b/src/core/lib/channel/channelz.cc index bf8acebcd7..6da8a172b5 100644 --- a/src/core/lib/channel/channelz.cc +++ b/src/core/lib/channel/channelz.cc @@ -30,7 +30,6 @@ #include "src/core/lib/channel/channelz_registry.h" #include "src/core/lib/channel/status_util.h" -#include "src/core/lib/gpr/host_port.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" #include "src/core/lib/gprpp/memory.h" @@ -278,20 +277,10 @@ grpc_json* ServerNode::RenderJson() { return top_level_json; } -SocketNode::SocketNode(const char* remote_peer_string) - : BaseNode(EntityType::kSocket) { - const char* ipv6_prefix = "ipv6:"; - const int ipv6_prefix_len = 5; - char* host; - char* port; - int offset = (strncmp(remote_peer_string, ipv6_prefix, ipv6_prefix_len) == 0) - ? ipv6_prefix_len - : 0; - GPR_ASSERT(gpr_split_host_port(remote_peer_string + offset, &host, &port)); - remote_host_ = UniquePtr(host); - remote_port_ = atoi(port); - gpr_free(port); -} +SocketNode::SocketNode(UniquePtr remote_host, int remote_port) + : BaseNode(EntityType::kSocket), + remote_host_(std::move(remote_host)), + remote_port_(remote_port) {} void SocketNode::RecordStreamStartedFromLocal() { gpr_atm_no_barrier_fetch_add(&streams_started_, static_cast(1)); diff --git a/src/core/lib/channel/channelz.h b/src/core/lib/channel/channelz.h index ba10b1a5bf..404d8341ff 100644 --- a/src/core/lib/channel/channelz.h +++ b/src/core/lib/channel/channelz.h @@ -232,7 +232,7 @@ class ServerNode : public BaseNode { // Handles channelz bookkeeping for sockets class SocketNode : public BaseNode { public: - SocketNode(const char* remote_peer_string); + SocketNode(UniquePtr remote_host, int remote_port); ~SocketNode() override {} grpc_json* RenderJson() override; diff --git a/src/core/lib/channel/channelz_registry.cc b/src/core/lib/channel/channelz_registry.cc index 8fc1b58adc..bc23b90a66 100644 --- a/src/core/lib/channel/channelz_registry.cc +++ b/src/core/lib/channel/channelz_registry.cc @@ -210,6 +210,17 @@ char* ChannelzRegistry::InternalGetServers(intptr_t start_server_id) { return json_str; } +void ChannelzRegistry::InternalLogAllEntities() { + MutexLock lock(&mu_); + for (size_t i = 0; i < entities_.size(); ++i) { + if (entities_[i] != nullptr) { + char* json = entities_[i]->RenderJsonString(); + gpr_log(GPR_INFO, "%s", json); + gpr_free(json); + } + } +} + } // namespace channelz } // namespace grpc_core diff --git a/src/core/lib/channel/channelz_registry.h b/src/core/lib/channel/channelz_registry.h index 326f0201c7..73b330785d 100644 --- a/src/core/lib/channel/channelz_registry.h +++ b/src/core/lib/channel/channelz_registry.h @@ -62,6 +62,10 @@ class ChannelzRegistry { return Default()->InternalGetServers(start_server_id); } + // Test only helper function to dump the JSON representation to std out. + // This can aid in debugging channelz code. + static void LogAllEntities() { Default()->InternalLogAllEntities(); } + private: GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_NEW GPRC_ALLOW_CLASS_TO_USE_NON_PUBLIC_DELETE @@ -96,6 +100,8 @@ class ChannelzRegistry { // Else, will return idx of the first uuid higher than the target. int FindByUuidLocked(intptr_t uuid, bool direct_hit_needed); + void InternalLogAllEntities(); + // protects members gpr_mu mu_; InlinedVector entities_; -- cgit v1.2.3