CMS 3D CMS Logo

Functions | Variables

cmsPerfServer Namespace Reference

Functions

def _main
def getCPSkeyword
def optionparse
def readlog
def request_benchmark
def runserv

Variables

string _CASTOR_DIR = "/castor/cern.ch/cms/store/relval/performance/"
dictionary _DEFAULTS
 _logreturn = False
tuple _outputdir = os.getcwd()
tuple _PROG_NAME = os.path.basename(sys.argv[0])
int _reqnumber = 0
string CandlesString = ""

Function Documentation

def cmsPerfServer::_main ( ) [private]

Definition at line 282 of file cmsPerfServer.py.

00283            :
00284     print _DEFAULTS
00285     (port, outputdir) = optionparse()
00286     server_thread = threading.Thread(target = runserv(port))
00287     server_thread.setDaemon(True) # Allow process to finish if this is the only remaining thread
00288     server_thread.start()

def cmsPerfServer::getCPSkeyword (   key,
  dict 
)

Definition at line 148 of file cmsPerfServer.py.

00149                            :
00150     if dict.has_key(key):
00151         return dict[key]
00152     else:
00153         return _DEFAULTS[key]
00154 

def cmsPerfServer::optionparse ( )

Definition at line 50 of file cmsPerfServer.py.

00051                  :
00052     global _outputdir
00053     parser = opt.OptionParser(usage=("""%s [Options]""" % _PROG_NAME))
00054 
00055     parser.add_option('-p',
00056                       '--port',
00057                       type="int",
00058                       dest='port',
00059                       default=8000, #Setting the default port to be 8000
00060                       help='Run server on a particular port',
00061                       metavar='<PORT>',
00062                       )
00063     
00064     parser.add_option('-o',
00065                       '--output',
00066                       type="string",
00067                       dest='outputdir',
00068                       default="",
00069                       help='The output directory for all the cmsPerfSuite runs',
00070                       metavar='<DIR>',
00071                       )
00072 
00073     (options, args) = parser.parse_args()
00074 
00075     if not options.outputdir == "":
00076         options.outputdir = os.path.abspath(options.outputdir)
00077         if not os.path.exists(options.outputdir):
00078             parser.error("the specified output directory %s does not exist" % options.outputdir)
00079             sys.exit()
00080         #This seems misleading naming _DEFAULTS, while we are re-initializing its keys to different values as we go...
00081         _DEFAULTS["perfsuitedir"] = options.outputdir
00082 
00083     #resetting global variable _outputdir too... do we really need this variable?
00084     _outputdir = options.outputdir
00085 
00086     return (options.port,options.outputdir)
00087 
00088 #class ClientThread(threading.Thread):
00089     # Overloading the constructor to accept cmsPerfSuite parameters
00090     

def cmsPerfServer::readlog (   logfile)

Definition at line 139 of file cmsPerfServer.py.

00140                     :
00141     astr = ""    
00142     try:
00143         for line in open(logfile,"r"):
00144             astr += line
00145     except (OSError, IOError) , detail:
00146         print detail
00147     return astr

def cmsPerfServer::request_benchmark (   cmds)

Definition at line 155 of file cmsPerfServer.py.

00156                            :
00157     #This is the function with which the server listens on the given port
00158     #cmds is a list of dictionaries: each dictionary is a set of cmsPerfSuite commands to run.
00159     #Most common use will be only 1 dictionary, but for testing with reproducibility and statistical errors
00160     #one can easily think of sending the same command 10 times for example and then compare the outputs
00161     global _outputdir, _reqnumber
00162     print "Commands received running perfsuite for these jobs:"
00163     print cmds
00164     sys.stdout.flush()
00165     try:
00166         # input is a list of dictionaries each defining the
00167         #   keywords to cmsperfsuite
00168         outs = []
00169         cmd_num = 0
00170         exists = True
00171         #Funky way to make sure we create a directory request_n with n = serial request number (if the server is running for a while
00172         #and the client submits more than one request
00173         #This should never happen since _reqnumber is a global variable on the server side...
00174         while exists:
00175             topdir = os.path.join(_outputdir,"request_" + str(_reqnumber))
00176             exists = os.path.exists(topdir)
00177             _reqnumber += 1
00178         os.mkdir(topdir)
00179         #Going through each command dictionary in the cmds list (usually only 1 such dictionary):
00180         for cmd in cmds:
00181             curperfdir = os.path.abspath(os.path.join(topdir,str(cmd_num)))
00182             if not os.path.exists(curperfdir):
00183                 os.mkdir(curperfdir)
00184             logfile = os.path.join(curperfdir, "cmsPerfSuite.log")
00185             if os.path.exists(logfile):
00186                 logfile = logfile + str(cmd_num)
00187             print cmd
00188             if cmd.has_key('cpus'):
00189                 if cmd['cpus'] == "All":
00190                     print "Running performance suite on all CPUS!\n"
00191                     cmd['cpus']=""
00192                     for cpu in range(cmsCpuInfo.get_NumOfCores()):
00193                         cmd["cpus"]=cmd["cpus"]+str(cpu)+","
00194                     cmd["cpus"]=cmd["cpus"][:-1] #eliminate the last comma for cleanliness 
00195                     print "I.e. on cpus %s\n"%cmd["cpus"]
00196                 
00197             #Not sure this is the most elegant solution... we keep cloning dictionaries...
00198             cmdwdefs = {}
00199             cmdwdefs["castordir"       ] = getCPSkeyword("castordir"       , cmd)
00200             cmdwdefs["perfsuitedir"    ] = curperfdir                      
00201             cmdwdefs["TimeSizeEvents"  ] = getCPSkeyword("TimeSizeEvents"  , cmd)
00202             cmdwdefs["TimeSizeCandles" ] = getCPSkeyword("TimeSizeCandles"  , cmd)
00203             cmdwdefs["TimeSizePUCandles" ] = getCPSkeyword("TimeSizePUCandles"  , cmd)
00204             cmdwdefs["IgProfEvents"    ] = getCPSkeyword("IgProfEvents"    , cmd)
00205             cmdwdefs["IgProfCandles"   ] = getCPSkeyword("IgProfCandles"    , cmd)
00206             cmdwdefs["IgProfPUCandles"   ] = getCPSkeyword("IgProfPUCandles"    , cmd)
00207             cmdwdefs["CallgrindEvents" ] = getCPSkeyword("CallgrindEvents"  , cmd)
00208             cmdwdefs["CallgrindCandles"] = getCPSkeyword("CallgrindCandles"  , cmd)
00209             cmdwdefs["CallgrindPUCandles"] = getCPSkeyword("CallgrindPUCandles"  , cmd)
00210             cmdwdefs["MemcheckEvents"  ] = getCPSkeyword("MemcheckEvents"  , cmd)
00211             cmdwdefs["MemcheckCandles" ] = getCPSkeyword("MemcheckCandles"  , cmd)
00212             cmdwdefs["MemcheckPUCandles" ] = getCPSkeyword("MemcheckPUCandles"  , cmd)
00213             cmdwdefs["cmsScimark"      ] = getCPSkeyword("cmsScimark"      , cmd)
00214             cmdwdefs["cmsScimarkLarge" ] = getCPSkeyword("cmsScimarkLarge" , cmd)
00215             cmdwdefs["cmsdriverOptions"] = getCPSkeyword("cmsdriverOptions", cmd)
00216             cmdwdefs["stepOptions"     ] = getCPSkeyword("stepOptions"     , cmd)
00217             cmdwdefs["quicktest"       ] = getCPSkeyword("quicktest"       , cmd)
00218             cmdwdefs["profilers"       ] = getCPSkeyword("profilers"       , cmd)
00219             cmdwdefs["cpus"            ] = getCPSkeyword("cpus"            , cmd)
00220             cmdwdefs["cores"           ] = getCPSkeyword("cores"           , cmd)
00221             cmdwdefs["prevrel"         ] = getCPSkeyword("prevrel"         , cmd)
00222 #            cmdwdefs["candles"         ] = getCPSkeyword("candles"         , cmd)                                    
00223 #            cmdwdefs["isAllCandles"    ] = len(Candles) == len(cmdwdefs["candles"]) #Dangerous: in the _DEFAULTS version this is a boolean!
00224             cmdwdefs["bypasshlt"       ] = getCPSkeyword("bypasshlt"       , cmd)
00225             cmdwdefs["runonspare"      ] = getCPSkeyword("runonspare"      , cmd)
00226             cmdwdefs["logfile"         ] = logfile
00227             logh = open(logfile,"w")
00228             logh.write("This perfsuite run was configured with the following options:\n")
00229             #logh.write(str(cmdwdefs) + "\n")
00230             for key in cmdwdefs.keys():
00231                 logh.write(key + "\t" +str(cmdwdefs[key])+"\n")
00232             logh.close()
00233             print "Calling cmsPerfSuite.main() function\n"
00234             cpsInputArgs=[
00235                       #"-a",cmdwdefs["castordir"],
00236                       "-t",cmdwdefs["TimeSizeEvents"  ],
00237                       "--RunTimeSize",cmdwdefs["TimeSizeCandles"],
00238                       "-o",cmdwdefs["perfsuitedir"    ],
00239                       #"-i",cmdwdefs["IgProfEvents"    ],
00240                       #"--RunIgProf",cmdwdefs["RunIgProf"    ],
00241                       #"-c",cmdwdefs["CallgrindEvents"  ],
00242                       #"--RunCallgrind",cmdwdefs["RunCallgrind"  ],
00243                       #"-m",cmdwdefs["MemcheckEvents"],
00244                       #"--RunMemcheck",cmdwdefs["RunMemcheck"],
00245                       "--cmsScimark",cmdwdefs["cmsScimark"      ],
00246                       "--cmsScimarkLarge",cmdwdefs["cmsScimarkLarge" ],
00247                       "--cmsdriver",cmdwdefs["cmsdriverOptions"],
00248                       "--step",cmdwdefs["stepOptions"     ],
00249                       #"--quicktest",cmdwdefs["quicktest"       ],
00250                       #"--profile",cmdwdefs["profilers"       ],
00251                       "--cpu",cmdwdefs["cpus"            ],
00252                       "--cores",cmdwdefs["cores"           ],
00253                       #"--prevrel",cmdwdefs["prevrel"         ],
00254  #                     "--candle",cmdwdefs["candles"         ],
00255                       #"--bypass-hlt",cmdwdefs["bypasshlt"       ],
00256                       "--notrunspare"#,cmdwdefs["runonspare"      ]#,
00257                       #"--logfile",cmdwdefs["logfile"         ]
00258                       ]
00259             print cpsInputArgs
00260             cps.main(cpsInputArgs)
00261             print "Running of the Performance Suite is done!"          
00262             #logreturn is false... so this does not get executed
00263             #Maybe we can replace this so that we can have more verbose logging of the server activity
00264             if _logreturn:
00265                 outs.append(readlog(logfile))
00266             else:
00267                 outs.append((cmdwdefs,cph.harvest(curperfdir)))
00268             #incrementing the variable for the command number:
00269             cmd_num += 1
00270 
00271             
00272         return outs #Not sure what James intended to return here... the contents of all logfiles in a list of logfiles?
00273     except exceptions.Exception, detail:
00274         # wrap the entire function in try except so we can log the error at client and server
00275         logh = open(os.path.join(os.getcwd(),"error.log"),"a")
00276         logh.write(str(detail) + "\n")
00277         logh.flush()
00278         logh.close()
00279         print detail
00280         sys.stdout.flush()
00281         raise

def cmsPerfServer::runserv (   port)

Definition at line 91 of file cmsPerfServer.py.

00092                  :
00093     # Remember that localhost is the loopback network: it does not provide
00094     # or require any connection to the outside world. As such it is useful
00095     # for testing purposes. If you want your server to be seen on other
00096     # machines, you must use your real network address in stead of
00097     # 'localhost'.
00098     server = None
00099     try:
00100         server = SimpleXMLRPCServer.SimpleXMLRPCServer((socket.gethostname(),port))
00101         server.register_function(request_benchmark)
00102     except socket.error, detail:
00103         print "ERROR: Could not initialise server:", detail
00104         sys.stdout.flush()        
00105         sys.exit()
00106 
00107     print "Running server on port %s... " % port
00108     sys.stdout.flush()    
00109     while True:
00110         try:
00111             server.handle_request()
00112             sys.stdout.flush()
00113         except (KeyboardInterrupt, SystemExit):
00114             #cleanup
00115             server.server_close()            
00116             raise
00117         except:
00118             #cleanup
00119             server.server_close()
00120             raise
00121     server.server_close()        
00122 
00123 #Not sure about this unused function:
00124 #Probably left over from first server implementation tests
00125 #def runcmd(cmd):
00126 #    process  = os.popen(cmd)
00127 #    cmdout   = process.read()
00128 #    exitstat = process.close()
00129 #
00130 #    if True:
00131 #        print cmd
00132 #        print cmdout
00133 #
00134 #    if not exitstat == None:
00135 #        sig     = exitstat >> 16    # Get the top 16 bits
00136 #        xstatus = exitstat & 0xffff # Mask out all bits except the bottom 16
00137 #        raise
00138 #    return cmdout


Variable Documentation

string cmsPerfServer::_CASTOR_DIR = "/castor/cern.ch/cms/store/relval/performance/"

Definition at line 20 of file cmsPerfServer.py.

Initial value:
00001 {"castordir"        : _CASTOR_DIR,
00002                "perfsuitedir"     : os.getcwd(),
00003                "TimeSizeEvents"   : 100        ,
00004                "TimeSizeCandles"      : "",
00005                "TimeSizePUCandles"      : "",
00006                "IgProfEvents"     : 0          ,
00007                "IgProfCandles"        : ""       ,
00008                "IgProfPUCandles"        : ""       ,
00009                "CallgrindEvents"  : 0          ,
00010                "CallgrindCandles"     : ""       ,
00011                "CallgrindPUCandles"     : ""       ,
00012                "MemcheckEvents"   : 0          ,
00013                "MemcheckCandles"      : ""          ,
00014                "MemcheckPUCandles"      : ""          ,
00015                "cmsScimark"       : 10         ,
00016                "cmsScimarkLarge"  : 10         ,
00017                "cmsdriverOptions" : cmsRelValCmd.get_cmsDriverOptions(), #Get these options automatically now!
00018                "stepOptions"      : ""         ,
00019                "quicktest"        : False      ,
00020                "profilers"        : ""         ,
00021                "cpus"             : "1"        ,
00022                "cores"            : cmsCpuInfo.get_NumOfCores(), #Get this option automatically
00023                "prevrel"          : ""         ,
00024                "isAllCandles"     : True       ,
00025                #"candles"          : CandlesString[1:]    ,
00026                "bypasshlt"        : False      ,
00027                "runonspare"       : True       ,
00028                "logfile"          : os.path.join(os.getcwd(),"cmsPerfSuite.log")}

Definition at line 21 of file cmsPerfServer.py.

Definition at line 18 of file cmsPerfServer.py.

tuple cmsPerfServer::_outputdir = os.getcwd()

Definition at line 16 of file cmsPerfServer.py.

tuple cmsPerfServer::_PROG_NAME = os.path.basename(sys.argv[0])

Definition at line 19 of file cmsPerfServer.py.

Definition at line 17 of file cmsPerfServer.py.

Definition at line 12 of file cmsPerfServer.py.