2 """ Please make sure you read the README COMPLETELY BEFORE reading anything below.
3 It is very critical that you read coding guidelines in Section E in README file.
9 from mbufdefines
import *
13 @lldb_command('mbuf_stat')
14 def MBufStat(cmd_args
=None):
15 """ Print extended mbuf allocator statistics.
17 hdr_format
= "{0: <16s} {1: >8s} {2: >8s} {3: ^16s} {4: >8s} {5: >12s} {6: >8s} {7: >8s} {8: >8s}"
18 print hdr_format
.format('class', 'total', 'cached', 'uncached', 'inuse', 'failed', 'waiter', 'notified', 'purge')
19 print hdr_format
.format('name', 'objs', 'objs', 'objs/slabs', 'objs', 'alloc count', 'count', 'count', 'count')
20 print hdr_format
.format('-'*16, '-'*8, '-'*8, '-'*16, '-'*8, '-'*12, '-'*8, '-'*8, '-'*8)
21 entry_format
= "{0: <16s} {1: >8d} {2: >8d} {3:>7d} / {4:<6d} {5: >8d} {6: >12d} {7: >8d} {8: >8d} {9: >8d}"
22 num_items
= sizeof(kern
.globals.mbuf_table
) / sizeof(kern
.globals.mbuf_table
[0])
23 ncpus
= int(kern
.globals.ncpu
)
24 for i
in range(num_items
):
25 mbuf
= kern
.globals.mbuf_table
[i
]
26 mcs
= Cast(mbuf
.mtbl_stats
, 'mb_class_stat_t *')
29 total
+= int(mc
.mc_full
.bl_total
) * int(mc
.mc_cpu
[0].cc_bktsize
)
31 for i
in range(ncpus
):
33 if int(ccp
.cc_objs
) > 0:
34 total
+= int(ccp
.cc_objs
)
35 if int(ccp
.cc_pobjs
) > 0:
36 total
+= int(ccp
.cc_pobjs
)
37 print entry_format
.format(mcs
.mbcl_cname
, mcs
.mbcl_total
, total
,
38 mcs
.mbcl_infree
, mcs
.mbcl_slab_cnt
,
39 (mcs
.mbcl_total
- total
- mcs
.mbcl_infree
),
40 mcs
.mbcl_fail_cnt
, mbuf
.mtbl_cache
.mc_waiter_cnt
,
41 mcs
.mbcl_notified
, mcs
.mbcl_purge_cnt
46 @lldb_command('mbuf_walkpkt')
47 def MbufWalkPacket(cmd_args
=None):
48 """ Walk the mbuf packet chain (m_nextpkt)
51 raise ArgumentError("Missing argument 0 in user function.")
53 mp
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
58 mbuf_walk_packet_format
= "{0:4d} 0x{1:x} [len {2:4d}, type {3:2d}, "
59 out_string
+= mbuf_walk_packet_format
.format(cnt
, mp
, mp
.m_hdr
.mh_len
, mp
.m_hdr
.mh_type
)
60 if (kern
.globals.mclaudit
!= 0):
61 out_string
+= GetMbufBuf2Mca(mp
) + ", "
62 tot
= tot
+ mp
.m_hdr
.mh_len
63 out_string
+= "total " + str(tot
) + "]"
65 mp
= mp
.m_hdr
.mh_nextpkt
67 # EndMacro: mbuf_walkpkt
70 @lldb_command('mbuf_walk')
71 def MbufWalk(cmd_args
=None):
72 """ Walk the mbuf chain (m_next)
74 mp
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
79 mbuf_walk_format
= "{0:4d} 0x{1:x} [len {2:4d}, type {3:2d}, "
80 out_string
+= mbuf_walk_format
.format(cnt
, mp
, mp
.m_hdr
.mh_len
, mp
.m_hdr
.mh_type
)
81 if (kern
.globals.mclaudit
!= 0):
82 out_string
+= GetMbufBuf2Mca(mp
) + ", "
83 tot
= tot
+ mp
.m_hdr
.mh_len
84 out_string
+= "total " + str(tot
) + "]"
90 # Macro: mbuf_buf2slab
91 @lldb_command('mbuf_buf2slab')
92 def MbufBuf2Slab(cmd_args
=None):
93 """ Given an mbuf object, find its corresponding slab address
96 raise ArgumentError("Missing argument 0 in user function.")
98 m
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
100 if (kern
.ptrsize
== 8):
101 mbuf_slab_format
= "0x{0:<16x}"
102 print mbuf_slab_format
.format(slab
)
104 mbuf_slab_format
= "0x{0:<8x}"
105 print mbuf_slab_format
.format(slab
)
106 # EndMacro: mbuf_buf2slab
108 # Macro: mbuf_buf2mca
109 @lldb_command('mbuf_buf2mca')
110 def MbufBuf2Mca(cmd_args
=None):
111 """ Find the mcache audit structure of the corresponding mbuf
113 m
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
114 print GetMbufBuf2Mca(m
)
116 # EndMacro: mbuf_buf2mca
119 @lldb_command('mbuf_slabs')
120 def MbufSlabs(cmd_args
=None):
121 """ Print all slabs in the group
126 raise ArgumentError("Invalid arguments passed.")
128 slg
= kern
.GetValueFromAddress(cmd_args
[0], 'mcl_slabg_t *')
131 if (kern
.ptrsize
== 8):
132 slabs_string_format
= "{0:>4d}: 0x{1:16x} 0x{2:16x} 0x{3:16x} {4:4s} {5:20d} {6:3d} {7:3d} {8:3d} {9:3d} {10:>6s} "
133 out_string
+= "slot slab next obj mca tstamp C R N size flags\n"
134 out_string
+= "---- ------------------ ------------------ ------------------ ------------------ ---------- -- -- -- ------ -----\n"
136 slabs_string_format
= "{0:>4d}: 0x{1:8x} 0x{2:8x} 0x{3:8x} {4:4s} {5:20d} {6:3d} {7:3d} {8:3d} {9:3d} {10:>6s} "
137 out_string
+= "slot slab next obj mca tstamp C R N size flags\n"
138 out_string
+= "---- ---------- ---------- ---------- ---------- ---------- -- -- -- ------ -----\n"
140 mbutl
= cast(kern
.globals.mbutl
, 'unsigned char *')
141 nslabspmb
= int((1 << MBSHIFT
) >> unsigned(kern
.globals.page_shift
))
143 sl
= addressof(slg
.slg_slab
[x
])
148 if (kern
.globals.mclaudit
!= 0):
149 mca
= GetMbufMcaPtr(obj
, sl
.sl_class
)
150 trn
= (mca
.mca_next_trn
+ unsigned(kern
.globals.mca_trn_max
) - 1) % unsigned(kern
.globals.mca_trn_max
)
151 ts
= mca
.mca_trns
[trn
].mca_tstamp
153 out_string
+= slabs_string_format
.format((x
+ 1), sl
, sl
.sl_next
, obj
, hex(mca
), int(ts
), int(sl
.sl_class
), int(sl
.sl_refcnt
), int(sl
.sl_chunks
), int(sl
.sl_len
), hex(sl
.sl_flags
))
155 if (sl
.sl_flags
!= 0):
157 if sl
.sl_flags
& SLF_MAPPED
:
158 out_string
+= "mapped"
159 if sl
.sl_flags
& SLF_PARTIAL
:
160 out_string
+= ",partial"
161 if sl
.sl_flags
& SLF_DETACHED
:
162 out_string
+= ",detached"
168 c
= sl
.sl_len
/sl
.sl_chunks
170 while z
< sl
.sl_chunks
:
171 obj
= sl
.sl_base
+ (c
* z
)
175 if (kern
.globals.mclaudit
!= 0):
176 mca
= GetMbufMcaPtr(obj
, sl
.sl_class
)
177 trn
= (mca
.mca_next_trn
+ unsigned(kern
.globals.mca_trn_max
) - 1) % unsigned(kern
.globals.mca_trn_max
)
178 ts
= mca
.mca_trns
[trn
].mca_tstamp
180 if (kern
.ptrsize
== 8):
181 out_string
+= " " + hex(obj
) + " " + hex(mca
) + " " + str(unsigned(ts
)) + "\n"
183 out_string
+= " " + hex(obj
) + " " + hex(mca
) + " " + str(unsigned(ts
)) + "\n"
188 # EndMacro: mbuf_slabs
190 # Macro: mbuf_slabstbl
191 @lldb_command('mbuf_slabstbl')
192 def MbufSlabsTbl(cmd_args
=None):
193 """ Print slabs table
198 if (kern
.ptrsize
== 8):
199 out_string
+= "slot slabg slabs range\n"
200 out_string
+= "---- ------------------ -------------------------------------------\n"
202 out_string
+= "slot slabg slabs range\n"
203 out_string
+= "---- ---------- ---------------------------\n"
205 slabstbl
= kern
.globals.slabstbl
206 slabs_table_blank_string_format
= "{0:>3d}: - \n"
207 nslabspmb
= int(((1 << MBSHIFT
) >> unsigned(kern
.globals.page_shift
)))
208 while (x
< unsigned(kern
.globals.maxslabgrp
)):
211 out_string
+= slabs_table_blank_string_format
.format(x
+1)
213 if (kern
.ptrsize
== 8):
214 slabs_table_string_format
= "{0:>3d}: 0x{1:16x} [ 0x{2:16x} - 0x{3:16x} ]\n"
215 out_string
+= slabs_table_string_format
.format(x
+1, slg
, addressof(slg
.slg_slab
[0]), addressof(slg
.slg_slab
[nslabspmb
-1]))
217 slabs_table_string_format
= "{0:>3d}: 0x{1:8x} [ 0x{2:8x} - 0x{3:8x} ]\n"
218 out_string
+= slabs_table_string_format
.format(x
+1, slg
, addressof(slg
.slg_slab
[0]), addressof(slg
.slg_slab
[nslabspmb
-1]))
222 # EndMacro: mbuf_slabstbl
224 def GetMbufMcaPtr(m
, cl
):
225 pgshift
= int(kern
.globals.page_shift
)
226 ix
= int((m
- Cast(kern
.globals.mbutl
, 'char *')) >> pgshift
)
227 page_addr
= (Cast(kern
.globals.mbutl
, 'char *') + (ix
<< pgshift
))
230 midx
= int((m
- page_addr
) >> 8)
231 mca
= kern
.globals.mclaudit
[ix
].cl_audit
[midx
]
233 midx
= int((m
- page_addr
) >> 11)
234 mca
= kern
.globals.mclaudit
[ix
].cl_audit
[midx
]
236 midx
= int((m
- page_addr
) >> 12)
237 mca
= kern
.globals.mclaudit
[ix
].cl_audit
[midx
]
239 mca
= kern
.globals.mclaudit
[ix
].cl_audit
[0]
240 return Cast(mca
, 'mcache_audit_t *')
243 pgshift
= int(kern
.globals.page_shift
)
244 gix
= int((Cast(m
, 'char *') - Cast(kern
.globals.mbutl
, 'char *')) >> MBSHIFT
)
245 slabstbl
= kern
.globals.slabstbl
246 ix
= int((Cast(m
, 'char *') - Cast(slabstbl
[gix
].slg_slab
[0].sl_base
, 'char *')) >> pgshift
)
247 return addressof(slabstbl
[gix
].slg_slab
[ix
])
249 def GetMbufBuf2Mca(m
):
251 mca
= GetMbufMcaPtr(m
, sl
.sl_class
)
254 def GetMbufWalkAllSlabs(show_a
, show_f
, show_tr
):
257 kern
.globals.slabstbl
[0]
264 if (show_a
and not(show_f
)):
265 out_string
+= "Searching only for active... \n"
266 if (not(show_a
) and show_f
):
267 out_string
+= "Searching only for inactive... \n"
268 if (show_a
and show_f
):
269 out_string
+= "Displaying all... \n"
271 if (kern
.ptrsize
== 8):
272 show_mca_string_format
= "{0:>4s} {1:>4s} {2:>16s} {3:>16s} {4:>16} {5:>12s} {6:12s}"
273 out_string
+= show_mca_string_format
.format("slot", "idx", "slab address", "mca address", "obj address", "type", "allocation state\n")
275 show_mca_string_format
= "{0:4s} {1:4s} {2:8s} {3:8s} {4:8} {5:12s} {6:12s}"
276 out_string
+= show_mca_string_format
.format("slot", "idx", "slab address", "mca address", "obj address", "type", "allocation state\n")
278 nslabspmb
= unsigned((1 << MBSHIFT
) >> unsigned(kern
.globals.page_shift
))
279 while (x
< unsigned(kern
.globals.slabgrp
)):
280 slg
= kern
.globals.slabstbl
[x
]
283 while ((y
< nslabspmb
) and (stop
== 0)):
284 sl
= addressof(slg
.slg_slab
[y
])
286 mca
= GetMbufMcaPtr(base
, sl
.sl_class
)
289 while ((Cast(mca
, 'int') != 0) and (unsigned(mca
.mca_addr
) != 0)):
291 if (mca
.mca_uflags
& (MB_INUSE | MB_COMP_INUSE
)):
292 total_a
= total_a
+ 1
295 total_f
= total_f
+ 1
300 if (kern
.ptrsize
== 8):
301 mca_string_format
= "{0:4d} {1:4d} 0x{2:16x} "
302 out_string
+= mca_string_format
.format(x
, y
, sl
)
304 mca_string_format
= "{0:4d} {1:4d} 0x{02:8x} "
305 out_string
+= mca_string_format
.format(x
, y
, sl
)
307 if (kern
.ptrsize
== 8):
312 if (kern
.ptrsize
== 8):
313 mca_string_format
= "0x{0:16x} 0x{1:16x}"
314 out_string
+= mca_string_format
.format(mca
, mca
.mca_addr
)
316 mca_string_format
= "0x{0:8x} 0x{1:8x}"
317 out_string
+= mca_string_format
.format(mca
, mca
.mca_addr
)
319 out_string
+= GetMbufMcaCtype(mca
, 0)
321 if (mca
.mca_uflags
& (MB_INUSE | MB_COMP_INUSE
)):
322 out_string
+= "active "
324 out_string
+= " freed "
331 if (mca
.mca_next_trn
== 0):
335 out_string
+= "Transaction " + str(int(trn
)) + " at " + str(int(mca
.mca_trns
[int(trn
)].mca_tstamp
)) + " by thread: 0x" + str(hex(mca
.mca_trns
[int(trn
)].mca_thread
)) + ":\n"
337 while (cnt
< mca
.mca_trns
[int(trn
)].mca_depth
):
338 kgm_pc
= mca
.mca_trns
[int(trn
)].mca_stack
[int(cnt
)]
339 out_string
+= str(int(cnt
) + 1) + " "
340 out_string
+= GetPc(kgm_pc
)
348 if (slg
.slg_slab
[int(y
)].sl_base
== 0):
352 if (total
and show_a
and show_f
):
353 out_string
+= "total objects = " + str(int(total
)) + "\n"
354 out_string
+= "active/unfreed objects = " + str(int(total_a
)) + "\n"
355 out_string
+= "freed/in_cache objects = " + str(int(total_f
)) + "\n"
359 def GetMbufMcaCtype(mca
, vopt
):
361 mca_class
= unsigned(cp
.mc_private
)
362 csize
= unsigned(kern
.globals.mbuf_table
[mca_class
].mtbl_stats
.mbcl_size
)
367 out_string
+= "M (mbuf) "
371 if (csize
== MCLBYTES
):
373 out_string
+= "CL (2K cluster) "
377 if (csize
== MBIGCLBYTES
):
379 out_string
+= "BCL (4K cluster) "
383 if (csize
== M16KCLBYTES
):
385 out_string
+= "JCL (16K cluster) "
390 if (csize
== (MSIZE
+ MCLBYTES
)):
391 if (mca
.mca_uflags
& MB_SCVALID
):
393 out_string
+= "M+CL "
395 out_string
+= "(paired mbuf, 2K cluster) "
397 out_string
+= "M-CL "
399 out_string
+= "(unpaired mbuf, 2K cluster) "
402 out_string
+= "CL+M "
404 out_string
+= "(paired 2K cluster, mbuf) "
406 out_string
+= "CL-M "
408 out_string
+= "(unpaired 2K cluster, mbuf) "
411 if (csize
== (MSIZE
+ MBIGCLBYTES
)):
412 if (mca
.mca_uflags
& MB_SCVALID
):
414 out_string
+= "M+BCL "
416 out_string
+= "(paired mbuf, 4K cluster) "
418 out_string
+= "M-BCL "
420 out_string
+= "(unpaired mbuf, 4K cluster) "
423 out_string
+= "BCL+M "
425 out_string
+= "(paired 4K cluster, mbuf) "
427 out_string
+= "BCL-m "
429 out_string
+= "(unpaired 4K cluster, mbuf) "
432 if (csize
== (MSIZE
+ M16KCLBYTES
)):
433 if (mca
.mca_uflags
& MB_SCVALID
):
435 out_string
+= "M+BCL "
437 out_string
+= "(paired mbuf, 4K cluster) "
439 out_string
+= "M-BCL "
441 out_string
+= "(unpaired mbuf, 4K cluster) "
444 out_string
+= "BCL+M "
446 out_string
+= "(paired 4K cluster, mbuf) "
448 out_string
+= "BCL-m "
450 out_string
+= "(unpaired 4K cluster, mbuf) "
453 out_string
+= "unknown: " + cp
.mc_name
460 def GetPointerAsString(kgm_pc
):
461 if (kern
.ptrsize
== 8):
462 pointer_format_string
= "0x{0:<16x} "
464 pointer_format_string
= "0x{0:<8x} "
465 return pointer_format_string
.format(kgm_pc
)
468 out_string
= GetSourceInformationForAddress(unsigned(kgm_pc
)) + "\n"
472 # Macro: mbuf_showactive
473 @lldb_command('mbuf_showactive')
474 def MbufShowActive(cmd_args
=None):
475 """ Print all active/in-use mbuf objects
478 print GetMbufWalkAllSlabs(1, 0, cmd_args
[0])
480 print GetMbufWalkAllSlabs(1, 0, 0)
481 # EndMacro: mbuf_showactive
484 # Macro: mbuf_showinactive
485 @lldb_command('mbuf_showinactive')
486 def MbufShowInactive(cmd_args
=None):
487 """ Print all freed/in-cache mbuf objects
489 print GetMbufWalkAllSlabs(0, 1, 0)
490 # EndMacro: mbuf_showinactive
493 # Macro: mbuf_showmca
494 @lldb_command('mbuf_showmca')
495 def MbufShowMca(cmd_args
=None):
496 """ Print the contents of an mbuf mcache audit structure
499 pgshift
= unsigned(kern
.globals.page_shift
)
501 mca
= kern
.GetValueFromAddress(cmd_args
[0], 'mcache_audit_t *')
503 out_string
+= "object type:\t"
504 out_string
+= GetMbufMcaCtype(mca
, 1)
505 out_string
+= "\nControlling mcache :\t" + hex(mca
.mca_cache
) + " (" + str(cp
.mc_name
) + ")\n"
506 if (mca
.mca_uflags
& MB_SCVALID
):
507 mbutl
= Cast(kern
.globals.mbutl
, 'unsigned char *')
508 ix
= (mca
.mca_addr
- mbutl
) >> pgshift
509 clbase
= mbutl
+ (ix
<< pgshift
)
510 mclidx
= (mca
.mca_addr
- clbase
) >> 8
511 out_string
+= "mbuf obj :\t\t" + hex(mca
.mca_addr
) + "\n"
512 out_string
+= "mbuf index :\t\t" + str(mclidx
+ 1) + " (out of 16) in cluster base " + hex(clbase
) + "\n"
513 if (int(mca
.mca_uptr
) != 0):
514 peer_mca
= cast(mca
.mca_uptr
, 'mcache_audit_t *')
515 out_string
+= "paired cluster obj :\t" + hex(peer_mca
.mca_addr
) + " (mca " + hex(peer_mca
) + ")\n"
516 out_string
+= "saved contents :\t" + hex(mca
.mca_contents
) + " (" + str(int(mca
.mca_contents_size
)) + " bytes)\n"
518 out_string
+= "cluster obj :\t\t" + hex(mca
.mca_addr
) + "\n"
519 if (mca
.mca_uptr
!= 0):
520 peer_mca
= cast(mca
.mca_uptr
, 'mcache_audit_t *')
521 out_string
+= "paired mbuf obj :\t" + hex(peer_mca
.mca_addr
) + " (mca " + hex(peer_mca
) + ")\n"
523 for idx
in range(unsigned(kern
.globals.mca_trn_max
), 0, -1):
524 trn
= (mca
.mca_next_trn
+ idx
- 1) % unsigned(kern
.globals.mca_trn_max
)
525 out_string
+= "transaction {:d} (tstamp {:d}, thread 0x{:x}):\n".format(trn
, mca
.mca_trns
[trn
].mca_tstamp
, mca
.mca_trns
[trn
].mca_thread
)
527 while (cnt
< mca
.mca_trns
[trn
].mca_depth
):
528 kgm_pc
= mca
.mca_trns
[trn
].mca_stack
[cnt
]
529 out_string
+= " " + str(cnt
+ 1) + ". "
530 out_string
+= GetPc(kgm_pc
)
533 msc
= cast(mca
.mca_contents
, 'mcl_saved_contents_t *')
534 msa
= addressof(msc
.sc_scratch
)
535 if (mca
.mca_uflags
& MB_SCVALID
):
536 if (msa
.msa_depth
> 0):
537 out_string
+= "Recent scratch transaction (tstamp {:d}, thread 0x{:x}):\n".format(msa
.msa_tstamp
, msa
.msa_thread
)
539 while (cnt
< msa
.msa_depth
):
540 kgm_pc
= msa
.msa_stack
[cnt
]
541 out_string
+= " " + str(cnt
+ 1) + ". "
542 out_string
+= GetPc(kgm_pc
)
545 if (msa
.msa_pdepth
> 0):
546 out_string
+= "previous scratch transaction (tstamp {:d}, thread 0x{:x}):\n".format(msa
.msa_ptstamp
, msa
.msa_pthread
)
549 while (cnt
< msa
.msa_pdepth
):
550 kgm_pc
= msa
.msa_pstack
[cnt
]
551 out_string
+= " " + str(cnt
+ 1) + ". "
552 out_string
+= GetPc(kgm_pc
)
555 out_string
+= "Missing argument 0 in user function."
558 # EndMacro: mbuf_showmca
561 # Macro: mbuf_showall
562 @lldb_command('mbuf_showall')
563 def MbufShowAll(cmd_args
=None):
564 """ Print all mbuf objects
566 print GetMbufWalkAllSlabs(1, 1, 1)
567 # EndMacro: mbuf_showall
569 # Macro: mbuf_countchain
570 @lldb_command('mbuf_countchain')
571 def MbufCountChain(cmd_args
=None):
572 """ Count the length of an mbuf chain
575 raise ArgumentError("Missing argument 0 in user function.")
577 mp
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
584 mn
= mp
.m_hdr
.mh_next
587 mn
= mn
.m_hdr
.mh_next
589 mp
= mp
.m_hdr
.mh_nextpkt
591 if (((pkt
+ nxt
) % 50) == 0):
592 print " ..." + str(pkt_nxt
)
594 print "Total: " + str(pkt
+ nxt
) + " (via m_next: " + str(nxt
) + ")"
595 # EndMacro: mbuf_countchain
599 # Macro: mbuf_topleak
600 @lldb_command('mbuf_topleak')
601 def MbufTopLeak(cmd_args
=None):
602 """ Print the top suspected mbuf leakers
605 if (int(len(cmd_args
)) > 0 and int(cmd_args
[0]) < 5):
609 while (topcnt
< maxcnt
):
610 print GetMbufTraceLeak(kern
.globals.mleak_top_trace
[topcnt
])
613 # EndMacro: mbuf_topleak
615 def GetMbufTraceLeak(trace
):
617 if (trace
.allocs
!= 0):
618 out_string
+= hex(trace
) + ":" + str(trace
.allocs
) + " outstanding allocs\n"
619 out_string
+= "Backtrace saved " + str(trace
.depth
) + " deep\n"
620 if (trace
.depth
!= 0):
622 while (cnt
< trace
.depth
):
623 out_string
+= str(cnt
+ 1) + ": "
624 out_string
+= GetPc(trace
.addr
[cnt
])
629 @lldb_command('mbuf_largefailures')
630 def MbufLargeFailures(cmd_args
=None):
631 """ Print the largest allocation failures
634 if (int(len(cmd_args
)) > 0 and int(cmd_args
[0]) < 5):
638 while (topcnt
< maxcnt
):
639 trace
= kern
.globals.mtracelarge_table
[topcnt
]
640 if (trace
.size
== 0):
643 print str(trace
.size
)
644 if (trace
.depth
!= 0):
646 while (cnt
< trace
.depth
):
647 print str(cnt
+ 1) + ": " + GetPc(trace
.addr
[cnt
])
652 # Macro: mbuf_traceleak
653 @lldb_command('mbuf_traceleak')
654 def MbufTraceLeak(cmd_args
=None):
655 """ Print the leak information for a given leak address
656 Given an mbuf leak trace (mtrace) structure address, print out the
657 stored information with that trace
658 syntax: (lldb) mbuf_traceleak <addr>
661 raise ArgumentError("Missing argument 0 in user function.")
663 trace
= kern
.GetValueFromAddress(cmd_args
[0], 'mtrace *')
664 print GetMbufTraceLeak(trace
)
665 # EndMacro: mbuf_traceleak
668 # Macro: mcache_walkobj
669 @lldb_command('mcache_walkobj')
670 def McacheWalkObject(cmd_args
=None):
671 """ Given a mcache object address, walk its obj_next pointer
674 raise ArgumentError("Missing argument 0 in user function.")
677 p
= kern
.GetValueFromAddress(cmd_args
[0], 'mcache_obj_t *')
681 mcache_object_format
= "{0:>4d}: 0x{1:>16x}"
682 out_string
+= mcache_object_format
.format(cnt
, p
) + "\n"
686 # EndMacro: mcache_walkobj
689 @lldb_command('mcache_stat')
690 def McacheStat(cmd_args
=None):
691 """ Print all mcaches in the system.
693 head
= kern
.globals.mcache_head
695 mc
= cast(head
.lh_first
, 'mcache *')
696 if (kern
.ptrsize
== 8):
697 mcache_stat_format_string
= "{0:<24s} {1:>8s} {2:>20s} {3:>5s} {4:>5s} {5:>20s} {6:>30s} {7:>18s}"
699 mcache_stat_format_string
= "{0:<24s} {1:>8s} {2:>12s} {3:>5s} {4:>5s} {5:>12s} {6:>30s} {7:>18s}"
701 if (kern
.ptrsize
== 8):
702 mcache_stat_data_format_string
= "{0:<24s} {1:>12s} {2:>20s} {3:>5s} {4:>5s} {5:>22s} {6:>12d} {7:>8d} {8:>8d} {9:>18d}"
704 mcache_stat_data_format_string
= "{0:<24s} {1:>12s} {2:>12s} {3:>5s} {4:>5s} {5:>14s} {6:>12d} {7:>8d} {8:>8d} {9:>18d}"
706 out_string
+= mcache_stat_format_string
.format("cache name", "cache state", "cache addr", "buf size", "buf align", "backing zone", "wait nowait failed", "bufs incache")
709 ncpu
= int(kern
.globals.ncpu
)
711 bktsize
= mc
.mc_cpu
[0].cc_bktsize
713 if (mc
.mc_flags
& MCF_NOCPUCACHE
):
714 cache_state
= "disabled"
717 cache_state
= " offline"
719 cache_state
= " online"
720 if (mc
.mc_slab_zone
!= 0):
721 backing_zone
= mc
.mc_slab_zone
723 if (kern
.ptrsize
== 8):
724 backing_zone
= " custom"
726 backing_zone
= " custom"
729 total
+= mc
.mc_full
.bl_total
* bktsize
733 if (ccp
.cc_objs
> 0):
735 if (ccp
.cc_pobjs
> 0):
736 total
+= ccp
.cc_pobjs
740 out_string
+= mcache_stat_data_format_string
.format(mc
.mc_name
, cache_state
, hex(mc
), str(int(mc
.mc_bufsize
)), str(int(mc
.mc_align
)), hex(mc
.mc_slab_zone
), int(mc
.mc_wretry_cnt
), int(mc
.mc_nwretry_cnt
), int(mc
.mc_nwfail_cnt
), total
)
742 mc
= cast(mc
.mc_list
.le_next
, 'mcache *')
744 # EndMacro: mcache_stat
746 # Macro: mcache_showcache
747 @lldb_command('mcache_showcache')
748 def McacheShowCache(cmd_args
=None):
749 """Display the number of objects in cache.
752 cp
= kern
.GetValueFromAddress(cmd_args
[0], 'mcache_t *')
753 bktsize
= cp
.mc_cpu
[0].cc_bktsize
756 mcache_cache_format
= "{0:<4d} {1:>8d} {2:>8d} {3:>8d}"
757 out_string
+= "Showing cache " + str(cp
.mc_name
) + " :\n\n"
758 out_string
+= " CPU cc_objs cc_pobjs total\n"
759 out_string
+= "---- ------- -------- --------\n"
760 ncpu
= int(kern
.globals.ncpu
)
769 tot_cpu
= objs
+ pobjs
771 out_string
+= mcache_cache_format
.format(cnt
, objs
, pobjs
, tot_cpu
)
775 out_string
+= " ========\n"
776 out_string
+= " " + str(total
) + "\n\n"
777 total
+= cp
.mc_full
.bl_total
* bktsize
779 out_string
+= "Total # of full buckets (" + str(int(bktsize
)) + " objs/bkt):\t" + str(int(cp
.mc_full
.bl_total
)) + "\n"
780 out_string
+= "Total # of objects cached:\t\t" + str(total
) + "\n"
782 # EndMacro: mcache_showcache