casa
$Rev:20696$
|
00001 #finished 7-10 00002 from pylab import * 00003 import string 00004 import commands 00005 import sys 00006 from time import * 00007 from os import * 00008 00009 ioff() #turn interactive plotting mode off 00010 mem1=list() 00011 m=0 00012 procnam="valgrind" 00013 procnam=sys.argv[1] 00014 00015 def getmem(procName='') : 00016 cmd='top -n 1 -b -i | grep ' + procName 00017 a=commands.getoutput(cmd) 00018 if(len(a)==0) : 00019 return -1.0,-1.0 00020 memstr0=string.atof(string.split(string.split(a)[4],'m')[0])*1024.0*1024.0 00021 if(len(string.split(string.split(a)[5],'m')) > 1) : 00022 memstr1=string.atof(string.split(string.split(a)[5],'m')[0])*1024.0*1024.0 00023 elif(len(string.split(string.split(a)[5],'g')) > 1) : 00024 memstr1=string.atof(string.split(string.split(a)[5],'g')[0])*1024.0*1024.0*1024.0 00025 elif(len(string.split(string.split(a)[5],'k')) > 1) : 00026 memstr1=string.atof(string.split(string.split(a)[5],'g')[0])*1024.0 00027 else: 00028 memstr1=string.atof(string.split(a)[5]) 00029 return memstr0, memstr1 00030 00031 mylabel="memory footprint of "+procnam 00032 t1=time() 00033 y1=0.5 00034 y2=0.5 00035 00036 t=[0] 00037 y11=[0] 00038 y22=[0] 00039 00040 i=0 00041 00042 #while (1) : 00043 #while i<100: 00044 while i< 10000: 00045 y1,y2=getmem(procnam) 00046 if (y1 > 0.0): 00047 sleep(2.0) 00048 t.append(time()-t1) 00049 if( y1 > 2.5e9): y1=2.5e9 00050 if(y2 > 2.5e9): y2=2.5e9 00051 y11.append(y1) 00052 y22.append(y2) 00053 else: 00054 print 'no ', procnam 00055 #sleep(10.0) 00056 sleep(3.0) 00057 i+=1 00058 print i 00059 plot(t,y11,lw=2) 00060 plot(t,y22,lw=2) 00061 if max(y11)>=max(y22): axis([0.9*min(t),1.1*max(t),0.9*min(y11),1.1*max(y11)]) 00062 else: axis([0.9*min(t),1.1*max(t),0.9*min(y22),1.1*max(y22)]) 00063 00064 xlabel('time (sec)') 00065 ylabel('memory footprint') #note virtual vs. resident 00066 legend(('virtual','resident')) 00067 title('memory usage of '+procnam) 00068 00069 #s="test-plot.ps" change to PNG for web browser compatibility 00070 #s="test-plot.png" 00071 00072 #set up special images directory? 00073 s='IMAGES' 00074 if access(s,F_OK) is False: 00075 print s+' directory DNE, so am making one!' 00076 mkdir(s) 00077 else: print s+' directory exists; will add to it!' 00078 00079 #label image according to time created 00080 t=gmtime( time() ) 00081 s+=('/%s-%s-%s-%s-%s.png') %(t[0],t[1],t[2],t[3],t[4]) 00082 print 'fin-ished!\nfile written to %s'%(s) 00083 savefig(s); 00084 show() #not really necessary