in tools/lldbmacros/waitq.py [0:0]
def ShowAllPreposts(cmd_args=None, cmd_options={}):
""" Dump / summarize all waitq prepost linkage elements
usage: showallpreposts [-V] [-T {type}] [-Y n] [-F n] [-Q]
-V : only show valid / live links
-T {type} : only display objects of type {type}
-Y {0|1} : only only show POST objects that are
valid (-Y 1) or invalid (-Y 0)
-F n : summarize the backtraces at frame level 'n'
-Q : be quiet, only summarize
"""
opt_summary = 0
opt_type_filt = ""
opt_valid_only = 0
opt_post_type = -1
opt_bt_idx = 0
verbose = False
if config['verbosity'] > vHUMAN:
verbose = True
if "-Q" in cmd_options:
opt_summary = 1
if "-V" in cmd_options:
opt_valid_only = 1
if "-Y" in cmd_options:
opt_post_type = unsigned(cmd_options["-Y"])
if opt_post_type != 0 and opt_post_type != 1:
raise ArgumentError("Invalid POST obj specifier [-Y %d] (expected 0 or 1)" % cmd_options["-Y"])
if "-F" in cmd_options:
opt_bt_idx = unsigned(cmd_options["-F"])
if hasattr(kern.globals, "g_nwaitq_btframes"):
if opt_bt_idx >= unsigned(kern.globals.g_nwaitq_btframes):
raise ArgumentError("Invalid BT index '{:s}' max:{:d}".format(cmd_options["-F"], unsigned(kern.globals.g_nwaitq_btframes) - 1))
if "-T" in cmd_options:
opt_type_filt = cmd_options["-T"]
if opt_type_filt == "FREE" or opt_type_filt == "RSVD":
pass
elif opt_type_filt == "POST":
opt_type_filt = "LINK"
elif opt_type_filt == "WQ":
opt_type_filt = "ELEM"
else:
raise ArgumentError("Invalid type filter'{:s}'".format(cmd_options["-T"]))
table = kern.globals.g_prepost_table
nelem = int(table.nelem)
bt_summary = {}
nfree = 0
ninv = 0
nwq = 0
npost = 0
nrsvd = 0
hdr_str = "Looking through {:d} objects from g_prepost_table@{:<#x}".format(nelem, addressof(kern.globals.g_prepost_table))
if opt_type_filt != "" or opt_valid_only != 0:
hdr_str += "\n\t`-> for "
if opt_valid_only:
hdr_str += "valid "
else:
hdr_str += "all "
if opt_type_filt == "":
hdr_str += "objects"
else:
hdr_str += "{:s} objects".format(cmd_options["-T"])
print hdr_str
if not opt_summary:
print GetWaitqPrepostSummary.header
id = 0
while id < nelem:
wqp = GetWaitqPrepost(id)[0]
if wqp == 0:
print "<<<invalid prepost:{:d}>>>".format(id)
ninv += 1
else:
lt = WaitqTableElemType(wqp)
isvalid = WaitqTableElemValid(wqp)
should_count = 1
if isvalid and opt_post_type > -1 and lt == "LINK":
post_wqp = GetWaitqPrepost(wqp.wqp_post.wqp_wq_id)[0]
post_valid = WaitqTableElemValid(post_wqp)
if opt_post_type == 0 and post_valid: # only count _invalid_ POST objects
should_count = 0
elif opt_post_type == 1 and not post_valid: # only count _valid_ POST objects
should_count = 0
if should_count and (opt_type_filt == "" or opt_type_filt == lt) and ((opt_valid_only == 0 or isvalid)):
if lt == "ELEM":
nwq += 1
elif lt == "LINK":
npost += 1
elif lt == "RSVD":
nrsvd += 1
elif lt == "FREE":
nfree += 1
else:
ninv += 1
if hasattr(wqp, 'wqp_alloc_bt'):
pc = unsigned(wqp.wqp_alloc_bt[opt_bt_idx])
pc_str = str(pc)
if pc > 0:
if pc_str in bt_summary:
bt_summary[pc_str] += 1
else:
bt_summary[pc_str] = 1
if not opt_summary:
print GetWaitqPrepostSummary(wqp)
if verbose:
sys.stderr.write('id: {:d}/{:d}... \r'.format(id, nelem))
id += 1
nused = nwq + npost + nrsvd
nfound = nused + nfree + ninv
print "\nFound {:d} objects: {:d} WQ, {:d} POST, {:d} RSVD, {:d} FREE".format(nfound, nwq, npost, nrsvd, nfree)
if (opt_type_filt == "" and opt_valid_only == 0) and (nused != table.used_elem):
print"\tWARNING: inconsistent state! Table reports {:d}/{:d} used elem, found {:d}/{:d}".format(table.used_elem, nelem, nused, nfound)
if len(bt_summary) > 0:
print "Link allocation BT (frame={:d})".format(opt_bt_idx)
for k,v in bt_summary.iteritems():
print "\t[{:d}] from: {:s}".format(v, GetSourceInformationForAddress(unsigned(k)))