kmem 544 B

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