bdump revision 1.1
11.1Sgwr# Count the number of buffers in the buffer cache for which
21.1Sgwr# bp->b_flags & $bufcount_match is non-0.
31.1Sgwr#
41.1Sgwr#	@(#)bdump	8.1 (Berkeley) 6/10/93
51.1Sgwr
61.1Sgwrset $bufcount_match=0x020000
71.1Sgwrdefine bufcount
81.1Sgwr
91.1Sgwr	set $i = 0
101.1Sgwr	set $num = 0
111.1Sgwr
121.1Sgwr	while ($i < 512)
131.1Sgwr
141.1Sgwr		set $bp = bufhash[$i].b_forw
151.1Sgwr		while ($bp != bufhash[$i].b_back)
161.1Sgwr			if ($bp->b_flags & $bufcount_match)
171.1Sgwr				set $num++
181.1Sgwr			end
191.1Sgwr			set $bp = $bp->b_forw
201.1Sgwr		end
211.1Sgwr		# printf "bucket: %d cumulative %d\n", $i, $num
221.1Sgwr		set $i++
231.1Sgwr	end
241.1Sgwr	printf "Number of buffers with flags & %x in hash table: %d\n", $bufcount_match, $num
251.1Sgwrend
261.1Sgwr
271.1Sgwr# Dump the entire buffer cache.
281.1Sgwr
291.1Sgwrdefine bufdump
301.1Sgwr
311.1Sgwr	set $i = 0
321.1Sgwr	set $num = 0
331.1Sgwr
341.1Sgwr	while ($i < 512)
351.1Sgwr
361.1Sgwr		set $bp = bufhash[$i].b_forw
371.1Sgwr		while ($bp != bufhash[$i].b_back)
381.1Sgwr			printf "bp=0x%x flags=0x%x vp=0x%x lblkno=0x%x blkno=0x%x\n", $bp, $bp->b_flags, $bp->b_vp, $bp->b_lblkno, $bp->b_blkno
391.1Sgwr			set $num++
401.1Sgwr			set $bp = $bp->b_forw
411.1Sgwr		end
421.1Sgwr		set $i++
431.1Sgwr	end
441.1Sgwr	printf "Number of buffers in hash table: %d\n", $num
451.1Sgwrend
461.1Sgwr
471.1Sgwr# Dump the buffers in a particular hashbucket.
481.1Sgwr# usage: dumpbucket bucketnumber
491.1Sgwrdefine dumpbucket
501.1Sgwr
511.1Sgwr	set $num = 0
521.1Sgwr	set $bp = bufhash[$arg0].b_forw
531.1Sgwr	while ($bp != bufhash[$arg0].b_back)
541.1Sgwr		printf "bp=0x%x flags=0x%x vp=0x%x lblkno=0x%x blkno=0x%x\n", $bp, $bp->b_flags, $bp->b_vp, $bp->b_lblkno, $bp->b_blkno
551.1Sgwr		set $num++
561.1Sgwr		set $bp = $bp->b_forw
571.1Sgwr	end
581.1Sgwr	printf "Number of buffers in bucket %d: %d\n", $arg0, $num
591.1Sgwrend
601.1Sgwr
611.1Sgwr# Dump the buffers on the empty and age queues
621.1Sgwr
631.1Sgwrdefine bdumpnew
641.1Sgwr
651.1Sgwr	set $i = 0
661.1Sgwr	set $num = 0
671.1Sgwr
681.1Sgwr	while ($i < 4)
691.1Sgwr
701.1Sgwr		printf "Queue %d\n", $i
711.1Sgwr		set $bp = (struct buf *)bufqueues[$i].qe_next
721.1Sgwr		while ($bp)
731.1Sgwr			printf "bp=0x%x flags=0x%x vp=0x%x lbn=%d size=0x%x\n", $bp, $bp->b_flags, $bp->b_vp, $bp->b_lblkno, $bp->b_bufsize
741.1Sgwr			set $num++
751.1Sgwr			set $bp = (struct buf *)$bp->b_freelist.qe_next
761.1Sgwr		end
771.1Sgwr		set $i++
781.1Sgwr	end
791.1Sgwr	printf "Number of buffers in free lists: %d\n", $num
801.1Sgwrend
811.1Sgwr
821.1Sgwrdefine dumpchain
831.1Sgwr
841.1Sgwr	set $bp = (struct buf *)$arg0
851.1Sgwr	while ($bp)
861.1Sgwr		printf "bp=0x%x flags=0x%x bn=0x%x lbn=%d count=%d size=%d\n", $bp, $bp->b_flags, $bp->b_blkno, $bp->b_lblkno, $bp->b_bcount, $bp->b_bufsize
871.1Sgwr		set $bp = (struct buf *)$bp->b_vnbufs.qe_next
881.1Sgwr	end
891.1Sgwrend
901.1Sgwr
911.1Sgwrdefine dumpq
921.1Sgwr
931.1Sgwr	set $num = 0
941.1Sgwr
951.1Sgwr	printf "Queue %d\n", $arg0
961.1Sgwr	set $bp = (struct buf *)bufqueues[$arg0].qe_next
971.1Sgwr	while ($bp)
981.1Sgwr		printf "bp=0x%x flags=0x%x vp=0x%x lbn=%d size=0x%x\n", $bp, $bp->b_flags, $bp->b_vp, $bp->b_lblkno, $bp->b_bufsize
991.1Sgwr		set $num++
1001.1Sgwr		set $bp = (struct buf *)$bp->b_freelist.qe_next
1011.1Sgwr	end
1021.1Sgwr	printf "Number of buffers on queue %d: %d\n", $arg0, $num
1031.1Sgwrend
104