Plan 9 from Bell Labs’s /usr/web/sources/patch/applied/leak-extension/leak.backup

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.


#!/bin/rc

rfork e

flagfmt='b,s,f binary,r res,x width'
args='name | pid list'
if(! ifs=() eval `{aux/getflags $*} || ~ $#* 0){
	aux/usage
	exit usage
}

if(~ $#flags 1 && ~ $#flagb 1){
	echo 'cannot use both -b and -s' >[1=2]
	exit usage
}

leakflags=()
if(~ $#flags 1)
	leakflags=($leakflags -s)
if(~ $#flagf 1)
	leakflags=($leakflags -f $flagf)

acidleakflags=()
if(~ $#flagb 1)
	acidleakflags=($acidleakflags -b)
if(~ $#flagr 1)
	acidleakflags=($acidleakflags -r $flagr)
if(~ $#flagx 1)
	acidleakflags=($acidleakflags -x $flagx)

if(! test -d /proc/$1) {
	# x=`{psu | awk '$NF=="'$1'" {print $2}'}
	x=`{psu | grep ' '$1'$' | sed 's/^[^ ]+ +([0-9]+).*/\1/'}
	if(~ $#x 0) {
		echo 'no processes named '$1 >[1=2]
		exit usage
	}
	echo leak $leakflags $acidleakflags $x
	exit
}

pidlist=`{echo $"* | tr ' ' ,}

echo 'leakdump({'$pidlist'})' | 
	acid -lpool -lleak $1 $flagf | 
	aux/acidleak $acidleakflags $flagf |
	{
		if(~ $#flags 1)
			awk '{print $4}' |
				sort | uniq -c | sort -nr |
				sed 's! *(.*) (0x.*)!src(\2); // \1!'
		if not
			cat
	}

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.