tux-memory-map.sh 1.17 KB
Newer Older
Nico Schottelius's avatar
Nico Schottelius committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
#!/bin/sh

pid=$$

file=/proc/$pid/maps

awk '
      function todec(str)
      {
         hstr = "1234567890abdcef";
         res  = 0;
         n    = split(str, digit, "");

         for(i=1; i<=n; i++) {
            num = index(hstr, digit[i])-1;
            res = res + (num*16^(n-i));
         }
         return res;
      }
      # hex numbers are big, do substract of small numbers!
      function hexsub(a, b)
      {
         hstr = "0123456789abdcef";
         an = split(a, aa, "");
         bn = split(b, ba, "");

         max = an > bn ? an : bn;
         i = 1;
         res = 0;

         while(i <= max) {
            if(an < i) aa[i] = 0;
            else if(bn < i) ba[i] = 0;

            da = index(hstr, aa[i]) -1;
            db = index(hstr, ba[i]) -1;

            diff = (da - db) * 16^i;
            res = res + diff;
         }
      }

   {
      memory=$1;
      file=$6;
      ele = split(memory, memreg, "-");
      start =memreg[1];
      end  = memreg[2];
      start_dec = todec(start);
      end_dec   = todec(end);
      len  = end_dec - start_dec;

      print len "\t" start_dec " " end_dec " "  memory ": " file
   }
   ' < "$file"
   #' < "$file" | sort -g