Changeset 1974


Ignore:
Timestamp:
Oct 25, 2005, 1:15:05 PM (19 years ago)
Author:
duncan
Message:

adding memory stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • inundation/fit_interpolate/benchmark_least_squares.py

    r1972 r1974  
    2424from Numeric import allclose, array, transpose
    2525import os
    26 
    27 def report_memory(i):
    28     pid = os.getpid()
    29     a2 = os.popen('ps -p %d -o rss,sz' % pid).readlines()
    30     print i, '  ', a2[1],
    31     return int(a2[1].split()[1])
    32 
    33 
    34 def showmem(): os.system("ps axm | head -1 ; ps axm | grep py | grep -v grep")
    35 
    36 def mem_usage(pid):
     26import sys
     27
     28def mem_usage():
    3729    '''
    3830    returns the rss.
    3931
     32  RSS  The total amount of physical memory used by  the  task,  in  kilo-
     33            bytes,  is  shown  here.  For ELF processes used library pages are
     34            counted here, for a.out processes not.
     35           
    4036    Only works on nix systems.
    4137    '''
    4238    import string
    43     p=os.popen('ps uwp %s'%pid)
     39    p=os.popen('ps uwp %s'%os.getpid())
    4440    lines=p.readlines()
    4541    #print "lines", lines
    4642    status=p.close()
    47     if status or len(lines)!=2:
     43    if status or len(lines)!=2 or sys.platform == 'win32':
    4844        return None
    4945    return int(string.split(lines[1])[4])
     
    212208if __name__ == "__main__":
    213209    import os
    214     #val = report_memory(1)
    215     show_me = 'ps v %d' % os.getpid()
    216     os.system(show_me)
    217210    suite = unittest.makeSuite(Test_Least_Squares,'test')
    218211    runner = unittest.TextTestRunner(verbosity=1)
    219     #runner.run(suite)
    220     os.system(show_me)
    221     #end = report_memory(2)
    222     val = mem_usage(os.getpid())
    223     print 'val', val
     212    runner.run(suite)
     213    val = mem_usage()
     214    print 'RSS', val
Note: See TracChangeset for help on using the changeset viewer.