channelz_registry.h
Go to the documentation of this file.
1 /*
2  *
3  * Copyright 2017 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 #ifndef GRPC_CORE_LIB_CHANNEL_CHANNELZ_REGISTRY_H
20 #define GRPC_CORE_LIB_CHANNEL_CHANNELZ_REGISTRY_H
21 
23 
24 #include <cstdint>
25 #include <map>
26 #include <string>
27 
31 
32 namespace grpc_core {
33 namespace channelz {
34 
35 // singleton registry object to track all objects that are needed to support
36 // channelz bookkeeping. All objects share globally distributed uuids.
38  public:
39  static void Register(BaseNode* node) {
40  return Default()->InternalRegister(node);
41  }
42  static void Unregister(intptr_t uuid) { Default()->InternalUnregister(uuid); }
44  return Default()->InternalGet(uuid);
45  }
46 
47  // Returns the allocated JSON string that represents the proto
48  // GetTopChannelsResponse as per channelz.proto.
49  static std::string GetTopChannels(intptr_t start_channel_id) {
50  return Default()->InternalGetTopChannels(start_channel_id);
51  }
52 
53  // Returns the allocated JSON string that represents the proto
54  // GetServersResponse as per channelz.proto.
55  static std::string GetServers(intptr_t start_server_id) {
56  return Default()->InternalGetServers(start_server_id);
57  }
58 
59  // Test only helper function to dump the JSON representation to std out.
60  // This can aid in debugging channelz code.
62 
63  // Test only helper function to reset to initial state.
64  static void TestOnlyReset() {
65  auto* p = Default();
66  MutexLock lock(&p->mu_);
67  p->node_map_.clear();
68  p->uuid_generator_ = 0;
69  }
70 
71  private:
72  // Returned the singleton instance of ChannelzRegistry;
73  static ChannelzRegistry* Default();
74 
75  // globally registers an Entry. Returns its unique uuid
76  void InternalRegister(BaseNode* node);
77 
78  // globally unregisters the object that is associated to uuid. Also does
79  // sanity check that an object doesn't try to unregister the wrong type.
80  void InternalUnregister(intptr_t uuid);
81 
82  // if object with uuid has previously been registered as the correct type,
83  // returns the void* associated with that uuid. Else returns nullptr.
85 
87  std::string InternalGetServers(intptr_t start_server_id);
88 
90 
91  // protects members
93  std::map<intptr_t, BaseNode*> node_map_;
95 };
96 
97 } // namespace channelz
98 } // namespace grpc_core
99 
100 #endif /* GRPC_CORE_LIB_CHANNEL_CHANNELZ_REGISTRY_H */
grpc_core::channelz::ChannelzRegistry
Definition: channelz_registry.h:37
grpc_core::channelz::ChannelzRegistry::Get
static RefCountedPtr< BaseNode > Get(intptr_t uuid)
Definition: channelz_registry.h:43
grpc_core
Definition: call_metric_recorder.h:31
grpc_core::MutexLock
Definition: src/core/lib/gprpp/sync.h:88
grpc_core::channelz::ChannelzRegistry::GetServers
static std::string GetServers(intptr_t start_server_id)
Definition: channelz_registry.h:55
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
grpc_core::channelz::ChannelzRegistry::TestOnlyReset
static void TestOnlyReset()
Definition: channelz_registry.h:64
grpc_core::channelz::ChannelzRegistry::mu_
Mutex mu_
Definition: channelz_registry.h:92
channelz.h
grpc_core::channelz::ChannelzRegistry::Default
static ChannelzRegistry * Default()
Definition: channelz_registry.cc:46
grpc_core::RefCountedPtr
Definition: ref_counted_ptr.h:35
grpc_core::channelz::ChannelzRegistry::uuid_generator_
intptr_t uuid_generator_
Definition: channelz_registry.h:94
grpc_core::channelz::ChannelzRegistry::InternalGetTopChannels
std::string InternalGetTopChannels(intptr_t start_channel_id)
Definition: channelz_registry.cc:77
grpc_core::channelz::ChannelzRegistry::LogAllEntities
static void LogAllEntities()
Definition: channelz_registry.h:61
grpc_core::channelz::ChannelzRegistry::InternalLogAllEntities
void InternalLogAllEntities()
Definition: channelz_registry.cc:156
grpc_core::channelz::BaseNode
Definition: channelz.h:78
grpc_core::channelz::ChannelzRegistry::InternalGetServers
std::string InternalGetServers(intptr_t start_server_id)
Definition: channelz_registry.cc:117
grpc_core::channelz::ChannelzRegistry::Unregister
static void Unregister(intptr_t uuid)
Definition: channelz_registry.h:42
grpc_core::channelz::ChannelzRegistry::GetTopChannels
static std::string GetTopChannels(intptr_t start_channel_id)
Definition: channelz_registry.h:49
intptr_t
_W64 signed int intptr_t
Definition: stdint-msvc2008.h:118
grpc_core::channelz::ChannelzRegistry::Register
static void Register(BaseNode *node)
Definition: channelz_registry.h:39
grpc_core::channelz::ChannelzRegistry::node_map_
std::map< intptr_t, BaseNode * > node_map_
Definition: channelz_registry.h:93
grpc_core::Mutex
Definition: src/core/lib/gprpp/sync.h:61
grpc_core::channelz::ChannelzRegistry::InternalGet
RefCountedPtr< BaseNode > InternalGet(intptr_t uuid)
Definition: channelz_registry.cc:64
grpc_core::channelz::ChannelzRegistry::InternalRegister
void InternalRegister(BaseNode *node)
Definition: channelz_registry.cc:51
channelz
void channelz(grpc_end2end_test_config config)
Definition: test/core/end2end/tests/channelz.cc:318
ref_counted_ptr.h
sync.h
grpc_core::channelz::ChannelzRegistry::InternalUnregister
void InternalUnregister(intptr_t uuid)
Definition: channelz_registry.cc:57
port_platform.h


grpc
Author(s):
autogenerated on Fri May 16 2025 02:57:53