CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_4_5_patch3/src/Validation/Performance/scripts/cmsScimarkStop.py

Go to the documentation of this file.
00001 #! /usr/bin/env python
00002 #Script to
00003 #1-check for cmsScimarkLaunch (infinite loop) scripts
00004 #2-kill them
00005 #3-report their results using cmsScimarkParser.py
00006 
00007 import subprocess,os,sys
00008 
00009 def main():
00010     #Use ps -ef to look for cmsScimarkLaunch processes
00011     ps_stdouterr=subprocess.Popen("ps -efww|grep cmsScimarkLaunch|grep -v grep|grep -v 'sh -c'",shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout
00012     if ps_stdouterr:
00013         ps_lines=ps_stdouterr.readlines()
00014         #print ps_lines
00015     if ps_lines:
00016         for line in ps_lines:
00017             tokens=line.split()
00018             #Look up the PID
00019             PID=tokens[1]
00020             #Look up the cpu core
00021             core=tokens[9]
00022             print "Found process:\n%s"%line[:-1] #to eliminate the extra \n
00023             #Kill the PID
00024             print "Killing process with PID %s"%PID
00025             kill_stdouterr=subprocess.Popen("kill %s"%PID,shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read() 
00026             print kill_stdouterr
00027             #Harvest the cmsScimark scores
00028             #Look for the cmsScimark log:
00029             if os.path.exists("cmsScimark_%s.log"%core): 
00030                 #Create the results dir
00031                 mkdir_stdouterr=subprocess.Popen("mkdir cmsScimarkResults_cpu%s"%core,shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read()
00032                 print mkdir_stdouterr
00033                 #Execute the harvesting scrip cmsScimarkParser.py (it is in the release)
00034                 harvest_stdouterr=subprocess.Popen("cmsScimarkParser.py -i cmsScimark_%s.log -o cmsScimarkResults_cpu%s"%(core,core),shell=True,stdout=subprocess.PIPE, stderr=subprocess.STDOUT).stdout.read()
00035                 print harvest_stdouterr
00036             else:
00037                 print "No cmsScimark_%s.log file was found for cpu%s, log might be in another directory!"%(core,core)
00038     else:
00039         print "No cmsScimarkLaunch processes found in the ps -ef output"
00040     return 0
00041 
00042 if __name__ == "__main__":
00043     sys.exit(main())