source: branches/testScripts/NBcbcRunTimes.py @ 819

Last change on this file since 819 was 819, checked in by jpfasano, 14 years ago

Committing new file.
This is playing around with capturing Cbc runtimes and writing to a database

  • Property svn:executable set to *
File size: 5.3 KB
Line 
1import re
2import os
3import sys
4import platform
5import MySQLdb
6
7import NBsvnCommand
8import NBlogMessages
9
10def getTestCaseRunTimes(cbcStdout):
11  retVal = {}
12  # Look for pattern
13  #   processing mps file: p0201 (31 out of 44)
14  # cbc_clp 13.75 = 13.75 ; okay - took 17.83 seconds.
15  r1=r'(cbc_clp (.+) = (.+) ; okay - took (\d*\.\d*) seconds.)'
16 
17  r2=r'(.+ processing mps file: (.+) \((\d*) out of (\d*)\))'
18  r='('+r1+'|'+r2+')'
19  reResult=re.findall(r,cbcStdout)
20
21  for i in range(len(reResult)):
22    if reResult[i][0].find("  processing mps file:") : continue
23    # reResult[i] contains "  processing mps file:"
24    if reResult[i][8] != '44' : continue
25    tcName=reResult[i][6]
26    tcRuntime=reResult[i+1][4]
27    retVal[tcName]=tcRuntime
28   
29  return retVal
30
31def getCbcStdout(cbcStdoutFileName):
32  retVal='file not read'
33  if os.path.isfile(cbcStdoutFileName) :
34    cbcStdoutFilePtr = open(cbcStdoutFileName,'r')
35    retVal = cbcStdoutFilePtr.read()
36    cbcStdoutFilePtr.close()
37  return retVal
38#===========================================================================
39def updateMachineTables(db) : 
40  cursor = db.cursor()
41 
42  # Get Info about machine and put into database
43  machineHw=platform.machine()
44  machineOS=platform.system()
45  machineName=platform.node()
46  svnRevNum = NBsvnCommand.svnRevision('.')
47
48  # Does this machine already exist in database?
49  x=cursor.execute("""SELECT machineId from machine WHERE hostName='%s' and machineOS='%s' and machineHardware='%s'"""%
50                 (machineName,machineOS,machineHw) )
51  row = cursor.fetchone()
52  if row!=None :
53    retVal=row[0]
54    cursor.close()
55    return retVal
56 
57  x=cursor.execute("Insert INTO machine (hostName,machineOS,machineHardware) VALUES (%s,%s,%s)",
58                 (machineName,machineOS,machineHw) ) 
59  retVal = db.insert_id()
60  cursor.close()
61
62  return retVal
63#==================================================================================
64
65def updateBuildTables(db,svnSrcDir,buildDir) : 
66  cursor = db.cursor()
67 
68  # Get Info about build and put into database
69  os.chdir(svnSrcDir) 
70  svnRevNum = NBsvnCommand.svnRevision('.')
71  svnUrl = NBsvnCommand.svnUrl('.')
72  execFilename=os.path.join(buildDir,"Cbc","src","cbc")
73  execModTimeEpoch=os.path.getmtime(execFilename)
74  execModTime=str(datetime.datetime.fromtimestamp(execModTimeEpoch))
75
76  # Does this build already exist in database?
77  x=cursor.execute("""SELECT buildId from build WHERE svnRevision='%s' and svnUrl='%s' and executableTimeStamp='%s'"""%
78                 (str(svnRevNum),svnUrl,execModTime) )
79  row = cursor.fetchone()
80  if row!=None :
81    retVal=row[0]
82    cursor.close()
83    return retVal
84 
85  x=cursor.execute("Insert INTO build (svnRevision,svnUrl,executableTimeStamp) VALUES (%s,%s,%s)",
86                 (str(svnRevNum),svnUrl,execModTime) ) 
87  retVal = db.insert_id()
88
89  # Insert build attributes in database
90  externalsRevisionNum = {}
91  NBsvnCommand.svnRevisions('.',externalsRevisionNum)
92  x=cursor.execute("Insert INTO buildAttr"+
93                   "(buildId,buildAttrName,buildAttrValue) VALUES (%s,'svnExternals',%s)",
94                 (str(retVal),str(externalsRevisionNum)) )
95
96  #TODO: add configuration parms and gcc version (perhaps compiler name too)
97  cursor.close()
98  return retVal
99
100
101
102 
103
104def updateDb(dbPwDir,svnSrcDir,buildDir,cbcStdout) :
105
106  # Get access info: host, userid, pw
107  dbAccessInfoFile = os.path.join(dbPwDir,'dbAccessInfo.txt')
108  if os.path.isfile(dbAccessInfoFile) :
109    dbAccessInfoFilePtr = open(dbAccessInfoFile,'r')
110    for dbAccessInfoRecord in dbAccessInfoFilePtr.readlines():
111      dbAccessInfo=dbAccessInfoRecord.split(":")
112      if len(dbAccessInfo)!=4 : continue
113      if dbAccessInfo[0].strip()=="DbAccessInfo" : break
114    if dbAccessInfo[0].strip()!="DbAccessInfo" :
115      NBlogMessages.writeMessage("Expected record not found in "+dbAccessInfoFile )
116      sys.exit(1)
117    dbAccessInfoFilePtr.close() 
118    dbServer=dbAccessInfo[1].strip()
119    dbUserid=dbAccessInfo[2].strip()
120    dbPw=dbAccessInfo[3].strip()
121  else :
122    NBlogMessages.writeMessage( "Failure reading " + dbAccessInfoFile )
123    sys.exit(1)
124
125  # Open date base connection
126  db = MySQLdb.connect(host=dbServer,user=dbUserid,passwd=dbPw,db='coin')
127
128 
129  # Get Info about machine and put into database
130  machineId=updateMachineTables(db)
131
132  # Get Info about build and put into database
133  buildId=updateBuildTables(db,svnSrcDir,buildDir)
134
135  x=getTestCaseRunTimes(cbcStdout)
136  cursor = db.cursor() 
137  for t in x:
138    # execute SQL statement
139    cursor.execute("INSERT INTO cbcUnitTest (mpsName,time,buildId,machineId) VALUES (%s,%s,%s,%s)",
140                  (t, x[t],str(buildId),str(machineId)))
141
142##  cursor.execute("SELECT mpsName, time from cbcUnitTest")
143##  while (1):
144##    row=cursor.fetchone()
145##    if row==None: break
146##    print "%s %s" % (row[0],row[1])
147##  print "Number of rows returned: %d" % cursor.rowcount
148
149  cursor.close()
150  db.commit()
151  db.close()
152
153
154x=getCbcStdout('/home/jp/COIN/Cbc/trunkNoThirdParty/Cbc/src/NBstdout-.-cbcunitTestdirMiplib--home-jp-COIN-Data-miplib3miplib')
155updateDb("/home/jp/testScripts","/home/jp/COIN/Cbc/trunk","/home/jp/COIN/Cbc/trunkNoThirdParty",x)
156
157# http://pleac.sourceforge.net/pleac_python/datesandtimes.html
158
Note: See TracBrowser for help on using the repository browser.