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