Attachment 'maxmem-pipe2.py'

Download

   1 #!/usr/bin/python
   2 
   3 import string
   4 import re
   5 import sys
   6 
   7 pidre = re.compile("^([0-9]*)")
   8 brkre = re.compile("^[0-9 ]*brk.*= ([0-9a-fx]*)")
   9 # munmap (0x40017000, 118685)
  10 # mmap (NULL, 1174524, 
  11 # mremap (void  *old_address,  size_t old_size , size_t new_size
  12 mmapre = re.compile("^[0-9 ]*[mo][ml][ad][^\(]*\([^,]*, ([0-9a-fx]*)")
  13 munmapre = re.compile("^[0-9 ]*munmap[^\(]*\([^,]*, ([0-9a-fx]*)")
  14 mremapre = re.compile("^[0-9 ]*mremap[^\(]*\([^,]*, ([0-9a-fx]*), ([0-9a-fx]*)")
  15 
  16 mmapmax = dict()
  17 mmap = dict()
  18 brkmin = dict()
  19 brkmax = dict()
  20 
  21 for line in sys.stdin:
  22 	mo = pidre.search(line)
  23 	pid = int(mo.group(1))
  24 	mmapmax.setdefault(pid, 0)
  25 	mmap.setdefault(pid, 0)
  26 	mo = brkre.search(line)
  27 	if mo:
  28 		brkval = int(mo.group(1), 16)
  29 		brkmin.setdefault(pid, brkval)
  30 		brkmax.setdefault(pid, brkval)
  31 		if brkval < brkmin[pid]:
  32 			brkmin[pid] = brkval
  33 		if brkval > brkmax[pid]:
  34 			brkmax[pid] = brkval
  35 	else:
  36 		mo = mmapre.search(line)
  37 		if mo:
  38 			mmapval = int(mo.group(1))
  39 			mmap[pid] += mmapval
  40 		else:
  41 			mo = munmapre.search(line)
  42 			if mo:
  43 				munmapval = int(mo.group(1))
  44 				mmap[pid] -= munmapval
  45 			else:
  46 				mo = mremapre.search(line)
  47 				if mo:
  48 					mremappval = int(mo.group(1))
  49 					mremapnval = int(mo.group(2))
  50 					mmap[pid] += mremapnval - mremappval
  51 		if mmap[pid] > mmapmax[pid]:
  52 			mmapmax[pid] = mmap[pid]
  53 
  54 ovrallmmap = 0
  55 for pid, val in mmapmax.iteritems():
  56 #	print "max mmap usage of pid %u is %u kB" % (pid, val/1024)
  57 	if val > ovrallmmap:
  58 		ovrallmmap = val
  59 
  60 ovrallbrk = 0
  61 for pid, val in brkmax.iteritems():
  62 	use = val - brkmin[pid]
  63 #	print "max brk usage of pid %u is %u kB" % (pid, use/1024)
  64 	if use > ovrallbrk:
  65 		ovrallbrk = use
  66 
  67 #print "mmapmax: %u kB, brkmin: 0x%x, brkmax: 0x%x" % (mmapmax/1024, brkmin, brkmax)
  68 #print "total: %u kB" % ((mmapmax + (brkmax-brkmin))/1024)
  69 
  70 print "total: %u kB" % ((ovrallmmap + ovrallbrk)/1024)

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.

You are not allowed to attach a file to this page.