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} {9: >8s}"
18 print hdr_format
.format('class', 'total', 'cached', 'uncached', 'inuse', 'failed', 'waiter', 'notified', 'purge', 'max')
19 print hdr_format
.format('name', 'objs', 'objs', 'objs/slabs', 'objs', 'alloc count', 'count', 'count', 'count', 'objs')
20 print hdr_format
.format('-'*16, '-'*8, '-'*8, '-'*16, '-'*8, '-'*12, '-'*8, '-'*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} {10: >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
,
47 @lldb_command('mbuf_walkpkt')
48 def MbufWalkPacket(cmd_args
=None):
49 """ Walk the mbuf packet chain (m_nextpkt)
52 raise ArgumentError("Missing argument 0 in user function.")
54 mp
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
59 mbuf_walk_packet_format
= "{0:4d} 0x{1:x} [len {2:4d}, type {3:2d}, "
60 out_string
+= mbuf_walk_packet_format
.format(cnt
, mp
, mp
.m_hdr
.mh_len
, mp
.m_hdr
.mh_type
)
61 if (kern
.globals.mclaudit
!= 0):
62 out_string
+= GetMbufBuf2Mca(mp
) + ", "
63 tot
= tot
+ mp
.m_hdr
.mh_len
64 out_string
+= "total " + str(tot
) + "]"
66 mp
= mp
.m_hdr
.mh_nextpkt
68 # EndMacro: mbuf_walkpkt
71 @lldb_command('mbuf_walk')
72 def MbufWalk(cmd_args
=None):
73 """ Walk the mbuf chain (m_next)
75 mp
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
80 mbuf_walk_format
= "{0:4d} 0x{1:x} [len {2:4d}, type {3:2d}, "
81 out_string
+= mbuf_walk_format
.format(cnt
, mp
, mp
.m_hdr
.mh_len
, mp
.m_hdr
.mh_type
)
82 if (kern
.globals.mclaudit
!= 0):
83 out_string
+= GetMbufBuf2Mca(mp
) + ", "
84 tot
= tot
+ mp
.m_hdr
.mh_len
85 out_string
+= "total " + str(tot
) + "]"
91 # Macro: mbuf_buf2slab
92 @lldb_command('mbuf_buf2slab')
93 def MbufBuf2Slab(cmd_args
=None):
94 """ Given an mbuf object, find its corresponding slab address
97 raise ArgumentError("Missing argument 0 in user function.")
99 m
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
100 slab
= GetMbufSlab(m
)
101 if (kern
.ptrsize
== 8):
102 mbuf_slab_format
= "0x{0:<16x}"
103 print mbuf_slab_format
.format(slab
)
105 mbuf_slab_format
= "0x{0:<8x}"
106 print mbuf_slab_format
.format(slab
)
107 # EndMacro: mbuf_buf2slab
109 # Macro: mbuf_buf2mca
110 @lldb_command('mbuf_buf2mca')
111 def MbufBuf2Mca(cmd_args
=None):
112 """ Find the mcache audit structure of the corresponding mbuf
114 m
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
115 print GetMbufBuf2Mca(m
)
117 # EndMacro: mbuf_buf2mca
120 @lldb_command('mbuf_slabs')
121 def MbufSlabs(cmd_args
=None):
122 """ Print all slabs in the group
127 raise ArgumentError("Invalid arguments passed.")
129 slg
= kern
.GetValueFromAddress(cmd_args
[0], 'mcl_slabg_t *')
132 if (kern
.ptrsize
== 8):
133 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} "
134 out_string
+= "slot slab next obj mca tstamp C R N size flags\n"
135 out_string
+= "---- ------------------ ------------------ ------------------ ------------------ ---------- -- -- -- ------ -----\n"
137 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} "
138 out_string
+= "slot slab next obj mca tstamp C R N size flags\n"
139 out_string
+= "---- ---------- ---------- ---------- ---------- ---------- -- -- -- ------ -----\n"
141 mbutl
= cast(kern
.globals.mbutl
, 'unsigned char *')
142 nslabspmb
= int((1 << MBSHIFT
) >> unsigned(kern
.globals.page_shift
))
144 sl
= addressof(slg
.slg_slab
[x
])
149 if (kern
.globals.mclaudit
!= 0):
150 mca
= GetMbufMcaPtr(obj
, sl
.sl_class
)
151 trn
= (mca
.mca_next_trn
+ unsigned(kern
.globals.mca_trn_max
) - 1) % unsigned(kern
.globals.mca_trn_max
)
152 ts
= mca
.mca_trns
[trn
].mca_tstamp
154 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
))
156 if (sl
.sl_flags
!= 0):
158 if sl
.sl_flags
& SLF_MAPPED
:
159 out_string
+= "mapped"
160 if sl
.sl_flags
& SLF_PARTIAL
:
161 out_string
+= ",partial"
162 if sl
.sl_flags
& SLF_DETACHED
:
163 out_string
+= ",detached"
169 c
= sl
.sl_len
/sl
.sl_chunks
171 while z
< sl
.sl_chunks
:
172 obj
= sl
.sl_base
+ (c
* z
)
176 if (kern
.globals.mclaudit
!= 0):
177 mca
= GetMbufMcaPtr(obj
, sl
.sl_class
)
178 trn
= (mca
.mca_next_trn
+ unsigned(kern
.globals.mca_trn_max
) - 1) % unsigned(kern
.globals.mca_trn_max
)
179 ts
= mca
.mca_trns
[trn
].mca_tstamp
181 if (kern
.ptrsize
== 8):
182 out_string
+= " " + hex(obj
) + " " + hex(mca
) + " " + str(unsigned(ts
)) + "\n"
184 out_string
+= " " + hex(obj
) + " " + hex(mca
) + " " + str(unsigned(ts
)) + "\n"
189 # EndMacro: mbuf_slabs
191 # Macro: mbuf_slabstbl
192 @lldb_command('mbuf_slabstbl')
193 def MbufSlabsTbl(cmd_args
=None):
194 """ Print slabs table
199 if (kern
.ptrsize
== 8):
200 out_string
+= "slot slabg slabs range\n"
201 out_string
+= "---- ------------------ -------------------------------------------\n"
203 out_string
+= "slot slabg slabs range\n"
204 out_string
+= "---- ---------- ---------------------------\n"
206 slabstbl
= kern
.globals.slabstbl
207 slabs_table_blank_string_format
= "{0:>3d}: - \n"
208 nslabspmb
= int(((1 << MBSHIFT
) >> unsigned(kern
.globals.page_shift
)))
209 while (x
< unsigned(kern
.globals.maxslabgrp
)):
212 out_string
+= slabs_table_blank_string_format
.format(x
+1)
214 if (kern
.ptrsize
== 8):
215 slabs_table_string_format
= "{0:>3d}: 0x{1:16x} [ 0x{2:16x} - 0x{3:16x} ]\n"
216 out_string
+= slabs_table_string_format
.format(x
+1, slg
, addressof(slg
.slg_slab
[0]), addressof(slg
.slg_slab
[nslabspmb
-1]))
218 slabs_table_string_format
= "{0:>3d}: 0x{1:8x} [ 0x{2:8x} - 0x{3:8x} ]\n"
219 out_string
+= slabs_table_string_format
.format(x
+1, slg
, addressof(slg
.slg_slab
[0]), addressof(slg
.slg_slab
[nslabspmb
-1]))
223 # EndMacro: mbuf_slabstbl
225 def GetMbufMcaPtr(m
, cl
):
226 pgshift
= int(kern
.globals.page_shift
)
227 ix
= int((m
- Cast(kern
.globals.mbutl
, 'char *')) >> pgshift
)
228 page_addr
= (Cast(kern
.globals.mbutl
, 'char *') + (ix
<< pgshift
))
231 midx
= int((m
- page_addr
) >> 8)
232 mca
= kern
.globals.mclaudit
[ix
].cl_audit
[midx
]
234 midx
= int((m
- page_addr
) >> 11)
235 mca
= kern
.globals.mclaudit
[ix
].cl_audit
[midx
]
237 midx
= int((m
- page_addr
) >> 12)
238 mca
= kern
.globals.mclaudit
[ix
].cl_audit
[midx
]
240 mca
= kern
.globals.mclaudit
[ix
].cl_audit
[0]
241 return Cast(mca
, 'mcache_audit_t *')
244 pgshift
= int(kern
.globals.page_shift
)
245 gix
= int((Cast(m
, 'char *') - Cast(kern
.globals.mbutl
, 'char *')) >> MBSHIFT
)
246 slabstbl
= kern
.globals.slabstbl
247 ix
= int((Cast(m
, 'char *') - Cast(slabstbl
[gix
].slg_slab
[0].sl_base
, 'char *')) >> pgshift
)
248 return addressof(slabstbl
[gix
].slg_slab
[ix
])
250 def GetMbufBuf2Mca(m
):
252 mca
= GetMbufMcaPtr(m
, sl
.sl_class
)
255 def GetMbufWalkAllSlabs(show_a
, show_f
, show_tr
):
258 kern
.globals.slabstbl
[0]
265 if (show_a
and not(show_f
)):
266 out_string
+= "Searching only for active... \n"
267 if (not(show_a
) and show_f
):
268 out_string
+= "Searching only for inactive... \n"
269 if (show_a
and show_f
):
270 out_string
+= "Displaying all... \n"
272 if (kern
.ptrsize
== 8):
273 show_mca_string_format
= "{0:>4s} {1:>4s} {2:>16s} {3:>16s} {4:>16} {5:>12s} {6:12s}"
274 out_string
+= show_mca_string_format
.format("slot", "idx", "slab address", "mca address", "obj address", "type", "allocation state\n")
276 show_mca_string_format
= "{0:4s} {1:4s} {2:8s} {3:8s} {4:8} {5:12s} {6:12s}"
277 out_string
+= show_mca_string_format
.format("slot", "idx", "slab address", "mca address", "obj address", "type", "allocation state\n")
279 nslabspmb
= unsigned((1 << MBSHIFT
) >> unsigned(kern
.globals.page_shift
))
280 while (x
< unsigned(kern
.globals.slabgrp
)):
281 slg
= kern
.globals.slabstbl
[x
]
284 while ((y
< nslabspmb
) and (stop
== 0)):
285 sl
= addressof(slg
.slg_slab
[y
])
287 mca
= GetMbufMcaPtr(base
, sl
.sl_class
)
290 while ((Cast(mca
, 'int') != 0) and (unsigned(mca
.mca_addr
) != 0)):
292 if (mca
.mca_uflags
& (MB_INUSE | MB_COMP_INUSE
)):
293 total_a
= total_a
+ 1
296 total_f
= total_f
+ 1
301 if (kern
.ptrsize
== 8):
302 mca_string_format
= "{0:4d} {1:4d} 0x{2:16x} "
303 out_string
+= mca_string_format
.format(x
, y
, sl
)
305 mca_string_format
= "{0:4d} {1:4d} 0x{02:8x} "
306 out_string
+= mca_string_format
.format(x
, y
, sl
)
308 if (kern
.ptrsize
== 8):
313 if (kern
.ptrsize
== 8):
314 mca_string_format
= "0x{0:16x} 0x{1:16x}"
315 out_string
+= mca_string_format
.format(mca
, mca
.mca_addr
)
317 mca_string_format
= "0x{0:8x} 0x{1:8x}"
318 out_string
+= mca_string_format
.format(mca
, mca
.mca_addr
)
320 out_string
+= GetMbufMcaCtype(mca
, 0)
322 if (mca
.mca_uflags
& (MB_INUSE | MB_COMP_INUSE
)):
323 out_string
+= "active "
325 out_string
+= " freed "
332 if (mca
.mca_next_trn
== 0):
336 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"
338 while (cnt
< mca
.mca_trns
[int(trn
)].mca_depth
):
339 kgm_pc
= mca
.mca_trns
[int(trn
)].mca_stack
[int(cnt
)]
340 out_string
+= str(int(cnt
) + 1) + " "
341 out_string
+= GetPc(kgm_pc
)
349 if (slg
.slg_slab
[int(y
)].sl_base
== 0):
353 if (total
and show_a
and show_f
):
354 out_string
+= "total objects = " + str(int(total
)) + "\n"
355 out_string
+= "active/unfreed objects = " + str(int(total_a
)) + "\n"
356 out_string
+= "freed/in_cache objects = " + str(int(total_f
)) + "\n"
360 def GetMbufMcaCtype(mca
, vopt
):
362 mca_class
= unsigned(cp
.mc_private
)
363 csize
= unsigned(kern
.globals.mbuf_table
[mca_class
].mtbl_stats
.mbcl_size
)
368 out_string
+= "M (mbuf) "
372 if (csize
== MCLBYTES
):
374 out_string
+= "CL (2K cluster) "
378 if (csize
== MBIGCLBYTES
):
380 out_string
+= "BCL (4K cluster) "
384 if (csize
== M16KCLBYTES
):
386 out_string
+= "JCL (16K cluster) "
391 if (csize
== (MSIZE
+ MCLBYTES
)):
392 if (mca
.mca_uflags
& MB_SCVALID
):
394 out_string
+= "M+CL "
396 out_string
+= "(paired mbuf, 2K cluster) "
398 out_string
+= "M-CL "
400 out_string
+= "(unpaired mbuf, 2K cluster) "
403 out_string
+= "CL+M "
405 out_string
+= "(paired 2K cluster, mbuf) "
407 out_string
+= "CL-M "
409 out_string
+= "(unpaired 2K cluster, mbuf) "
412 if (csize
== (MSIZE
+ MBIGCLBYTES
)):
413 if (mca
.mca_uflags
& MB_SCVALID
):
415 out_string
+= "M+BCL "
417 out_string
+= "(paired mbuf, 4K cluster) "
419 out_string
+= "M-BCL "
421 out_string
+= "(unpaired mbuf, 4K cluster) "
424 out_string
+= "BCL+M "
426 out_string
+= "(paired 4K cluster, mbuf) "
428 out_string
+= "BCL-m "
430 out_string
+= "(unpaired 4K cluster, mbuf) "
433 if (csize
== (MSIZE
+ M16KCLBYTES
)):
434 if (mca
.mca_uflags
& MB_SCVALID
):
436 out_string
+= "M+BCL "
438 out_string
+= "(paired mbuf, 4K cluster) "
440 out_string
+= "M-BCL "
442 out_string
+= "(unpaired mbuf, 4K cluster) "
445 out_string
+= "BCL+M "
447 out_string
+= "(paired 4K cluster, mbuf) "
449 out_string
+= "BCL-m "
451 out_string
+= "(unpaired 4K cluster, mbuf) "
454 out_string
+= "unknown: " + cp
.mc_name
461 def GetPointerAsString(kgm_pc
):
462 if (kern
.ptrsize
== 8):
463 pointer_format_string
= "0x{0:<16x} "
465 pointer_format_string
= "0x{0:<8x} "
466 return pointer_format_string
.format(kgm_pc
)
469 out_string
= GetSourceInformationForAddress(unsigned(kgm_pc
)) + "\n"
473 # Macro: mbuf_showactive
474 @lldb_command('mbuf_showactive')
475 def MbufShowActive(cmd_args
=None):
476 """ Print all active/in-use mbuf objects
479 print GetMbufWalkAllSlabs(1, 0, cmd_args
[0])
481 print GetMbufWalkAllSlabs(1, 0, 0)
482 # EndMacro: mbuf_showactive
485 # Macro: mbuf_showinactive
486 @lldb_command('mbuf_showinactive')
487 def MbufShowInactive(cmd_args
=None):
488 """ Print all freed/in-cache mbuf objects
490 print GetMbufWalkAllSlabs(0, 1, 0)
491 # EndMacro: mbuf_showinactive
494 # Macro: mbuf_showmca
495 @lldb_command('mbuf_showmca')
496 def MbufShowMca(cmd_args
=None):
497 """ Print the contents of an mbuf mcache audit structure
500 pgshift
= unsigned(kern
.globals.page_shift
)
502 mca
= kern
.GetValueFromAddress(cmd_args
[0], 'mcache_audit_t *')
504 out_string
+= "object type:\t"
505 out_string
+= GetMbufMcaCtype(mca
, 1)
506 out_string
+= "\nControlling mcache :\t" + hex(mca
.mca_cache
) + " (" + str(cp
.mc_name
) + ")\n"
507 if (mca
.mca_uflags
& MB_SCVALID
):
508 mbutl
= Cast(kern
.globals.mbutl
, 'unsigned char *')
509 ix
= (mca
.mca_addr
- mbutl
) >> pgshift
510 clbase
= mbutl
+ (ix
<< pgshift
)
511 mclidx
= (mca
.mca_addr
- clbase
) >> 8
512 out_string
+= "mbuf obj :\t\t" + hex(mca
.mca_addr
) + "\n"
513 out_string
+= "mbuf index :\t\t" + str(mclidx
+ 1) + " (out of 16) in cluster base " + hex(clbase
) + "\n"
514 if (int(mca
.mca_uptr
) != 0):
515 peer_mca
= cast(mca
.mca_uptr
, 'mcache_audit_t *')
516 out_string
+= "paired cluster obj :\t" + hex(peer_mca
.mca_addr
) + " (mca " + hex(peer_mca
) + ")\n"
517 out_string
+= "saved contents :\t" + hex(mca
.mca_contents
) + " (" + str(int(mca
.mca_contents_size
)) + " bytes)\n"
519 out_string
+= "cluster obj :\t\t" + hex(mca
.mca_addr
) + "\n"
520 if (mca
.mca_uptr
!= 0):
521 peer_mca
= cast(mca
.mca_uptr
, 'mcache_audit_t *')
522 out_string
+= "paired mbuf obj :\t" + hex(peer_mca
.mca_addr
) + " (mca " + hex(peer_mca
) + ")\n"
524 for idx
in range(unsigned(kern
.globals.mca_trn_max
), 0, -1):
525 trn
= (mca
.mca_next_trn
+ idx
- 1) % unsigned(kern
.globals.mca_trn_max
)
526 out_string
+= "transaction {:d} (tstamp {:d}, thread 0x{:x}):\n".format(trn
, mca
.mca_trns
[trn
].mca_tstamp
, mca
.mca_trns
[trn
].mca_thread
)
528 while (cnt
< mca
.mca_trns
[trn
].mca_depth
):
529 kgm_pc
= mca
.mca_trns
[trn
].mca_stack
[cnt
]
530 out_string
+= " " + str(cnt
+ 1) + ". "
531 out_string
+= GetPc(kgm_pc
)
534 msc
= cast(mca
.mca_contents
, 'mcl_saved_contents_t *')
535 msa
= addressof(msc
.sc_scratch
)
536 if (mca
.mca_uflags
& MB_SCVALID
):
537 if (msa
.msa_depth
> 0):
538 out_string
+= "Recent scratch transaction (tstamp {:d}, thread 0x{:x}):\n".format(msa
.msa_tstamp
, msa
.msa_thread
)
540 while (cnt
< msa
.msa_depth
):
541 kgm_pc
= msa
.msa_stack
[cnt
]
542 out_string
+= " " + str(cnt
+ 1) + ". "
543 out_string
+= GetPc(kgm_pc
)
546 if (msa
.msa_pdepth
> 0):
547 out_string
+= "previous scratch transaction (tstamp {:d}, thread 0x{:x}):\n".format(msa
.msa_ptstamp
, msa
.msa_pthread
)
550 while (cnt
< msa
.msa_pdepth
):
551 kgm_pc
= msa
.msa_pstack
[cnt
]
552 out_string
+= " " + str(cnt
+ 1) + ". "
553 out_string
+= GetPc(kgm_pc
)
556 out_string
+= "Missing argument 0 in user function."
559 # EndMacro: mbuf_showmca
562 # Macro: mbuf_showall
563 @lldb_command('mbuf_showall')
564 def MbufShowAll(cmd_args
=None):
565 """ Print all mbuf objects
567 print GetMbufWalkAllSlabs(1, 1, 1)
568 # EndMacro: mbuf_showall
570 # Macro: mbuf_countchain
571 @lldb_command('mbuf_countchain')
572 def MbufCountChain(cmd_args
=None):
573 """ Count the length of an mbuf chain
576 raise ArgumentError("Missing argument 0 in user function.")
578 mp
= kern
.GetValueFromAddress(cmd_args
[0], 'mbuf *')
585 mn
= mp
.m_hdr
.mh_next
588 mn
= mn
.m_hdr
.mh_next
590 mp
= mp
.m_hdr
.mh_nextpkt
592 if (((pkt
+ nxt
) % 50) == 0):
593 print " ..." + str(pkt_nxt
)
595 print "Total: " + str(pkt
+ nxt
) + " (via m_next: " + str(nxt
) + ")"
596 # EndMacro: mbuf_countchain
600 # Macro: mbuf_topleak
601 @lldb_command('mbuf_topleak')
602 def MbufTopLeak(cmd_args
=None):
603 """ Print the top suspected mbuf leakers
606 if (int(len(cmd_args
)) > 0 and int(cmd_args
[0]) < 5):
610 while (topcnt
< maxcnt
):
611 print GetMbufTraceLeak(kern
.globals.mleak_top_trace
[topcnt
])
614 # EndMacro: mbuf_topleak
616 def GetMbufTraceLeak(trace
):
618 if (trace
.allocs
!= 0):
619 out_string
+= hex(trace
) + ":" + str(trace
.allocs
) + " outstanding allocs\n"
620 out_string
+= "Backtrace saved " + str(trace
.depth
) + " deep\n"
621 if (trace
.depth
!= 0):
623 while (cnt
< trace
.depth
):
624 out_string
+= str(cnt
+ 1) + ": "
625 out_string
+= GetPc(trace
.addr
[cnt
])
630 @lldb_command('mbuf_largefailures')
631 def MbufLargeFailures(cmd_args
=None):
632 """ Print the largest allocation failures
635 if (int(len(cmd_args
)) > 0 and int(cmd_args
[0]) < 5):
639 while (topcnt
< maxcnt
):
640 trace
= kern
.globals.mtracelarge_table
[topcnt
]
641 if (trace
.size
== 0):
644 print str(trace
.size
)
645 if (trace
.depth
!= 0):
647 while (cnt
< trace
.depth
):
648 print str(cnt
+ 1) + ": " + GetPc(trace
.addr
[cnt
])
653 # Macro: mbuf_traceleak
654 @lldb_command('mbuf_traceleak')
655 def MbufTraceLeak(cmd_args
=None):
656 """ Print the leak information for a given leak address
657 Given an mbuf leak trace (mtrace) structure address, print out the
658 stored information with that trace
659 syntax: (lldb) mbuf_traceleak <addr>
662 raise ArgumentError("Missing argument 0 in user function.")
664 trace
= kern
.GetValueFromAddress(cmd_args
[0], 'mtrace *')
665 print GetMbufTraceLeak(trace
)
666 # EndMacro: mbuf_traceleak
669 # Macro: mcache_walkobj
670 @lldb_command('mcache_walkobj')
671 def McacheWalkObject(cmd_args
=None):
672 """ Given a mcache object address, walk its obj_next pointer
675 raise ArgumentError("Missing argument 0 in user function.")
678 p
= kern
.GetValueFromAddress(cmd_args
[0], 'mcache_obj_t *')
682 mcache_object_format
= "{0:>4d}: 0x{1:>16x}"
683 out_string
+= mcache_object_format
.format(cnt
, p
) + "\n"
687 # EndMacro: mcache_walkobj
690 @lldb_command('mcache_stat')
691 def McacheStat(cmd_args
=None):
692 """ Print all mcaches in the system.
694 head
= kern
.globals.mcache_head
696 mc
= cast(head
.lh_first
, 'mcache *')
697 if (kern
.ptrsize
== 8):
698 mcache_stat_format_string
= "{0:<24s} {1:>8s} {2:>20s} {3:>5s} {4:>5s} {5:>20s} {6:>30s} {7:>18s}"
700 mcache_stat_format_string
= "{0:<24s} {1:>8s} {2:>12s} {3:>5s} {4:>5s} {5:>12s} {6:>30s} {7:>18s}"
702 if (kern
.ptrsize
== 8):
703 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}"
705 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}"
707 out_string
+= mcache_stat_format_string
.format("cache name", "cache state", "cache addr", "buf size", "buf align", "backing zone", "wait nowait failed", "bufs incache")
710 ncpu
= int(kern
.globals.ncpu
)
712 bktsize
= mc
.mc_cpu
[0].cc_bktsize
714 if (mc
.mc_flags
& MCF_NOCPUCACHE
):
715 cache_state
= "disabled"
718 cache_state
= " offline"
720 cache_state
= " online"
721 if (mc
.mc_slab_zone
!= 0):
722 backing_zone
= mc
.mc_slab_zone
724 if (kern
.ptrsize
== 8):
725 backing_zone
= " custom"
727 backing_zone
= " custom"
730 total
+= mc
.mc_full
.bl_total
* bktsize
734 if (ccp
.cc_objs
> 0):
736 if (ccp
.cc_pobjs
> 0):
737 total
+= ccp
.cc_pobjs
741 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
)
743 mc
= cast(mc
.mc_list
.le_next
, 'mcache *')
745 # EndMacro: mcache_stat
747 # Macro: mcache_showcache
748 @lldb_command('mcache_showcache')
749 def McacheShowCache(cmd_args
=None):
750 """Display the number of objects in cache.
753 cp
= kern
.GetValueFromAddress(cmd_args
[0], 'mcache_t *')
754 bktsize
= cp
.mc_cpu
[0].cc_bktsize
757 mcache_cache_format
= "{0:<4d} {1:>8d} {2:>8d} {3:>8d}"
758 out_string
+= "Showing cache " + str(cp
.mc_name
) + " :\n\n"
759 out_string
+= " CPU cc_objs cc_pobjs total\n"
760 out_string
+= "---- ------- -------- --------\n"
761 ncpu
= int(kern
.globals.ncpu
)
770 tot_cpu
= objs
+ pobjs
772 out_string
+= mcache_cache_format
.format(cnt
, objs
, pobjs
, tot_cpu
)
776 out_string
+= " ========\n"
777 out_string
+= " " + str(total
) + "\n\n"
778 total
+= cp
.mc_full
.bl_total
* bktsize
780 out_string
+= "Total # of full buckets (" + str(int(bktsize
)) + " objs/bkt):\t" + str(int(cp
.mc_full
.bl_total
)) + "\n"
781 out_string
+= "Total # of objects cached:\t\t" + str(total
) + "\n"
783 # EndMacro: mcache_showcache
786 @lldb_command('mbuf_wdlog')
787 def McacheShowCache(cmd_args
=None):
788 """Display the watchdog log
790 lldb_run_command('settings set max-string-summary-length 4096')
791 print('%s' % lldb_run_command('p/s mbwdog_logging').replace("\\n","\n"))
792 # EndMacro: mbuf_wdlog