|
|
|
@ -79,12 +79,13 @@ void ChannelzRegistry::MaybePerformCompactionLocked() { |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
int ChannelzRegistry::FindByUuidLocked(intptr_t target_uuid) { |
|
|
|
|
size_t left = 0; |
|
|
|
|
size_t right = entities_.size() - 1; |
|
|
|
|
int ChannelzRegistry::FindByUuidLocked(intptr_t target_uuid, |
|
|
|
|
bool direct_hit_needed) { |
|
|
|
|
int left = 0; |
|
|
|
|
int right = int(entities_.size() - 1); |
|
|
|
|
while (left <= right) { |
|
|
|
|
size_t true_middle = left + (right - left) / 2; |
|
|
|
|
size_t first_non_null = true_middle; |
|
|
|
|
int true_middle = left + (right - left) / 2; |
|
|
|
|
int first_non_null = true_middle; |
|
|
|
|
while (first_non_null < right && entities_[first_non_null] == nullptr) { |
|
|
|
|
first_non_null++; |
|
|
|
|
} |
|
|
|
@ -102,14 +103,14 @@ int ChannelzRegistry::FindByUuidLocked(intptr_t target_uuid) { |
|
|
|
|
right = true_middle - 1; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
return -1; |
|
|
|
|
return direct_hit_needed ? -1 : right; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void ChannelzRegistry::InternalUnregister(intptr_t uuid) { |
|
|
|
|
GPR_ASSERT(uuid >= 1); |
|
|
|
|
MutexLock lock(&mu_); |
|
|
|
|
GPR_ASSERT(uuid <= uuid_generator_); |
|
|
|
|
int idx = FindByUuidLocked(uuid); |
|
|
|
|
int idx = FindByUuidLocked(uuid, true); |
|
|
|
|
GPR_ASSERT(idx >= 0); |
|
|
|
|
entities_[idx] = nullptr; |
|
|
|
|
num_empty_slots_++; |
|
|
|
@ -121,7 +122,7 @@ BaseNode* ChannelzRegistry::InternalGet(intptr_t uuid) { |
|
|
|
|
if (uuid < 1 || uuid > uuid_generator_) { |
|
|
|
|
return nullptr; |
|
|
|
|
} |
|
|
|
|
int idx = FindByUuidLocked(uuid); |
|
|
|
|
int idx = FindByUuidLocked(uuid, true); |
|
|
|
|
return idx < 0 ? nullptr : entities_[idx]; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -132,7 +133,8 @@ char* ChannelzRegistry::InternalGetTopChannels(intptr_t start_channel_id) { |
|
|
|
|
grpc_json* json_iterator = nullptr; |
|
|
|
|
InlinedVector<BaseNode*, 10> top_level_channels; |
|
|
|
|
bool reached_pagination_limit = false; |
|
|
|
|
for (size_t i = 0; i < entities_.size(); ++i) { |
|
|
|
|
int start_idx = GPR_MAX(FindByUuidLocked(start_channel_id, false), 0); |
|
|
|
|
for (size_t i = start_idx; i < entities_.size(); ++i) { |
|
|
|
|
if (entities_[i] != nullptr && |
|
|
|
|
entities_[i]->type() == |
|
|
|
|
grpc_core::channelz::BaseNode::EntityType::kTopLevelChannel && |
|
|
|
@ -173,7 +175,8 @@ char* ChannelzRegistry::InternalGetServers(intptr_t start_server_id) { |
|
|
|
|
grpc_json* json_iterator = nullptr; |
|
|
|
|
InlinedVector<BaseNode*, 10> servers; |
|
|
|
|
bool reached_pagination_limit = false; |
|
|
|
|
for (size_t i = 0; i < entities_.size(); ++i) { |
|
|
|
|
int start_idx = GPR_MAX(FindByUuidLocked(start_server_id, false), 0); |
|
|
|
|
for (size_t i = start_idx; i < entities_.size(); ++i) { |
|
|
|
|
if (entities_[i] != nullptr && |
|
|
|
|
entities_[i]->type() == |
|
|
|
|
grpc_core::channelz::BaseNode::EntityType::kServer && |
|
|
|
|