MCPcopy
hub / github.com/grpc/grpc-go / getTopChannels

Method getTopChannels

internal/channelz/channelmap.go:237–263  ·  view source on GitHub ↗
(id int64, maxResults int)

Source from the content-addressed store, hash-verified

235}
236
237func (c *channelMap) getTopChannels(id int64, maxResults int) ([]*Channel, bool) {
238 if maxResults <= 0 {
239 maxResults = EntriesPerPage
240 }
241 c.mu.RLock()
242 defer c.mu.RUnlock()
243 l := int64(len(c.topLevelChannels))
244 ids := make([]int64, 0, l)
245
246 for k := range c.topLevelChannels {
247 ids = append(ids, k)
248 }
249 sort.Sort(int64Slice(ids))
250 idx := sort.Search(len(ids), func(i int) bool { return ids[i] >= id })
251 end := true
252 var t []*Channel
253 for _, v := range ids[idx:] {
254 if len(t) == maxResults {
255 end = false
256 break
257 }
258 if cn, ok := c.channels[v]; ok {
259 t = append(t, cn)
260 }
261 }
262 return t, end
263}
264
265func (c *channelMap) getServers(id int64, maxResults int) ([]*Server, bool) {
266 if maxResults <= 0 {

Callers 1

GetTopChannelsFunction · 0.80

Calls 2

int64SliceTypeAlias · 0.85
SearchMethod · 0.65

Tested by

no test coverage detected