| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

In This Package:

__init__.py

Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 #
00003 # Check memory usage as a function of execute number
00004 # He Miao, Jun. 2009
00005 #
00006 # How to use:
00007 #   nuwa.py MDC09a.chkIBD.AdPerformance MemoryCheck $FILELIST
00008 
00009 __all__ = ['checkMemory']
00010 from GaudiPython.GaudiAlgs import GaudiAlgo
00011 from GaudiPython import SUCCESS, FAILURE
00012 from GaudiPython import gbl
00013 import ROOT
00014 import os
00015 import commands
00016 
00017 class checkMemory(GaudiAlgo):
00018           
00019     def __init__(self,name):
00020         GaudiAlgo.__init__(self,name)
00021 
00022         return
00023 
00024     def initialize(self):
00025         print "Initializing Check Memory", self.name()
00026         status = GaudiAlgo.initialize(self)
00027         if status.isFailure(): 
00028             return status
00029 
00030         self.execNumber = 0
00031         self.virt = {}
00032         self.res = {}
00033         self.virtMax = 0
00034         self.virtMin = 999
00035         self.resMax = 0
00036         self.resMin = 999
00037 
00038         return SUCCESS
00039 
00040     def execute(self):
00041         if self.execNumber % 1 == 0:
00042             print "------- Check Memory, excute: ", self.execNumber
00043 
00044         # Use system command to record memory use
00045         ps = 'ps uh ' + str(os.getpid())
00046         line = commands.getoutput(ps)
00047         word = line.split()
00048 
00049         self.virt[self.execNumber] = float(word[4])/(1024.*1024.)
00050         self.res[self.execNumber] = float(word[5])/(1024.*1024.)
00051 
00052         # Find maximum and minimum memory use
00053         if self.virtMax < self.virt[self.execNumber]:
00054             self.virtMax = self.virt[self.execNumber]
00055         if self.virtMin > self.virt[self.execNumber]:
00056             self.virtMin = self.virt[self.execNumber]
00057 
00058         if self.resMax < self.res[self.execNumber]:
00059             self.resMax = self.res[self.execNumber]
00060         if self.resMin > self.res[self.execNumber]:
00061             self.resMin = self.res[self.execNumber]
00062 
00063         self.execNumber = self.execNumber + 1
00064 
00065         return SUCCESS
00066 
00067     def finalize(self):
00068 
00069         self.histSvc = self.svc('ITHistSvc', 'THistSvc')
00070         self.hist = {}
00071 
00072         # Define histogram for virtual and resident memory
00073         self.hist["virt"] = gbl.TH2F("virt", "Virtual Memory",
00074             self.execNumber + 1, 0., self.execNumber, 
00075             100, self.virtMin*0.95, self.virtMax*1.05)
00076         status = self.histSvc.regHist('/fileMemory/virt', 
00077             self.hist["virt"])
00078         if status.isFailure(): return status
00079 
00080         self.hist["res"] = gbl.TH2F("res", "Resident Memory",
00081             self.execNumber + 1, 0., self.execNumber, 
00082             100, self.resMin*0.95, self.resMax*1.05)
00083         status = self.histSvc.regHist('/fileMemory/res', 
00084             self.hist["res"])
00085         if status.isFailure(): return status
00086 
00087         # Fill histogram
00088         for i in self.virt:
00089             self.hist["virt"].Fill(float(i),self.virt[i])
00090         for i in self.res:
00091             self.hist["res"].Fill(float(i),self.res[i])
00092 
00093         print "Finalizing ", self.name()
00094         print "Max resident memory is %s GByte" % self.resMax
00095         print "Max virtual memory is %s GByte" % self.virtMax
00096         status = GaudiAlgo.finalize(self)
00097         return status
00098 
00099 def configure(argv=[]):
00100 
00101     import sys, getopt
00102     opts,args = getopt.getopt(argv,"o:")
00103     outFile = "memory.root"
00104     for opt,arg in opts:
00105         if opt == "-o":
00106             outFile = arg
00107 
00108     from GaudiSvc.GaudiSvcConf import THistSvc
00109 
00110     histsvc = THistSvc()
00111     histsvc.Output += ["fileMemory DATAFILE='" + outFile + "' OPT='RECREATE' TYP='ROOT' "]
00112 
00113     return
00114 
00115 def run(app):
00116     '''Configure and add this algorithm to job'''
00117 
00118     app.ExtSvc += ["THistSvc"]
00119 
00120     chMemory = checkMemory("myCheckMemory")
00121     app.addAlgorithm(chMemory)
00122     pass
00123 
| Classes | Job Modules | Data Objects | Services | Algorithms | Tools | Packages | Directories | Tracs |

Generated on Mon Apr 11 20:12:17 2011 for MemoryCheck by doxygen 1.4.7