MCPcopy Create free account
hub / github.com/apache/brpc / get_all_bthreads

Function get_all_bthreads

tools/lldb_bthread_stack.py:128–165  ·  view source on GitHub ↗
(target: lldb.SBTarget, total: int)

Source from the content-addressed store, hash-verified

126
127
128def get_all_bthreads(target: lldb.SBTarget, total: int):
129 bthreads = []
130 groups = find_global_value(
131 target, "butil::ResourcePool<bthread::TaskMeta>::_ngroup.val").GetValueAsUnsigned()
132 long_type = target.GetBasicType(lldb.eBasicTypeLong)
133 uint32_t_type = target.FindFirstType("uint32_t")
134 block_groups = find_global_value(
135 target, "butil::ResourcePool<bthread::TaskMeta>::_block_groups")
136 for group in range(groups):
137 block_group = get_child(
138 block_groups.GetChildAtIndex(group), "val").Dereference()
139 nblock = get_child(block_group, "nblock").Cast(
140 long_type).GetValueAsUnsigned()
141 blocks = get_child(block_group, "blocks")
142 for block in range(nblock):
143 # block_type: butil::ResourcePool<bthread::TaskMeta>::Block
144 block_type = blocks.GetChildAtIndex(
145 block).GetType().GetTemplateArgumentType(0)
146 block = blocks.GetChildAtIndex(
147 block).Cast(block_type).Dereference()
148 nitem = get_child(block, "nitem").GetValueAsUnsigned()
149 task_meta_array_type = target.FindFirstType(
150 "bthread::TaskMeta").GetArrayType(nitem)
151 tasks = get_child(block, "items").Cast(task_meta_array_type)
152 for i in range(nitem):
153 task_meta = tasks.GetChildAtIndex(i)
154 version_tid = get_child(
155 task_meta, "tid").GetValueAsUnsigned() >> 32
156 version_butex = get_child(task_meta, "version_butex").Cast(
157 uint32_t_type.GetPointerType()).Dereference().GetValueAsUnsigned()
158 # stack_type: bthread::ContextualStack
159 stack_type = get_child(
160 task_meta, "attr.stack_type").GetValueAsUnsigned()
161 if version_tid == version_butex and stack_type != 0:
162 if len(bthreads) >= total:
163 return bthreads
164 bthreads.append(task_meta)
165 return bthreads
166
167# lldb bthread commands
168def bthread_begin(debugger, command, result, internal_dict):

Callers 1

bthread_beginFunction · 0.70

Calls 5

find_global_valueFunction · 0.85
get_childFunction · 0.85
DereferenceMethod · 0.80
CastMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected