umem 547 B

123456789101112131415161718192021222324252627282930313233
  1. #!/bin/rc
  2. # umem pid [binary] - print summary of allocate blocks in a running process
  3. rfork e
  4. if(! ~ $#* 1 2){
  5. echo 'usage: umem pid [binary]' >[1=2]
  6. exit usage
  7. }
  8. p=$1
  9. binary=()
  10. if(~ $#* 2)
  11. binary=$2
  12. echo 'blocksummary()' | acid -lpool -lleak $p $binary | awk '
  13. $1 == "block" {
  14. addr=$6
  15. size=$3
  16. alloc=$4
  17. total[alloc] += size
  18. count[alloc]++
  19. }
  20. $1 == "summary" {
  21. alloc=$2
  22. cnt=$3
  23. size=$4
  24. total[alloc] += size
  25. count[alloc] += cnt
  26. }
  27. END{
  28. for(i in count)
  29. printf("%6d %11d %s\n", count[i], total[i], i);
  30. }
  31. ' | sort -nr