aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/lib
diff options
context:
space:
mode:
authorGravatar ncteisen <ncteisen@gmail.com>2018-10-30 09:04:41 -0700
committerGravatar ncteisen <ncteisen@gmail.com>2018-10-30 09:04:41 -0700
commitd82dff4ea042752009f23aa2a87f56016050cc6c (patch)
tree30f04165f3a8200a39f32ba751e0f8be142ba896 /src/core/lib
parentba6f81297ce112f429ec88e7c62274a88655234f (diff)
reviewer feedback, debuging helper
Diffstat (limited to 'src/core/lib')
-rw-r--r--src/core/lib/channel/channelz.cc19
-rw-r--r--src/core/lib/channel/channelz.h2
-rw-r--r--src/core/lib/channel/channelz_registry.cc11
-rw-r--r--src/core/lib/channel/channelz_registry.h6
4 files changed, 22 insertions, 16 deletions
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<char>(host);
- remote_port_ = atoi(port);
- gpr_free(port);
-}
+SocketNode::SocketNode(UniquePtr<char> 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<gpr_atm>(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<char> 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<BaseNode*, 20> entities_;