5 check db has all needed host information
12 from sqlite3
import IntegrityError, OperationalError
16 hostname=os.getenv(
'HOSTNAME')
19 hout=os.popen(
'lshosts '+hostname)
22 res2=[l.split()
for l
in res.strip().
split(
'\n')]
23 res3=[ l[:8]+[
' '.
join(l[8:])]
for l
in res2 ]
34 self.
cnx = sqlite3.connect(self.
fname)
45 header= [ s[0]
for s
in self.
cur.description ]
46 format=
' '.
join([
'%25s' for s
in self.
cur.description])
47 print format%tuple(header)
48 for res
in self.
cur.fetchall():
52 def insert(self,tname='t_run',hargs=[],args=[]):
53 "create prepared statement and execute"
55 vals=
','.
join((
'?',)*len(args))
56 cmd=
"insert into %s (%s) values (%s)"%(tname,keys,vals)
63 hostInfo={
'HOST_NAME':
'lxplus443',
64 'RESOURCES':
'(intel plus quadcore wan)',
77 atlasArea=os.getenv(
'AtlasArea')
78 dummy,branch,proj,rel=atlasArea.rsplit(
'/',3)
81 subcwd=os.getenv(
'LS_SUBCWD')
82 dummy1,cmt,dummy2,package,job=subcwd.rsplit(
'/',4)
84 rdate,rtime=dt.datetime.now().strftime(
'%Y-%m-%d %H:%M:%S').
split()
87 hostInfo=dict(zip(*hostInfo))
89 machine=hostInfo[
'HOST_NAME']
90 KSI2K_fac=
float(hostInfo[
'cpuf'])
91 hargs=[
'branch',
'rel',
'cmt',
'rdate',
'rtime',
'machine',
'KSI2K_fac',
'package',
'job']
92 args=[locals()[x]
for x
in hargs]
93 id=self.
insert(
't_run',hargs,args)
98 "add file entry to db and return id"
100 if fl.dbid
is not None:
104 cmd=
'select id from t_files where fl_name=?'
106 res=self.
cur.fetchone()
108 print 'WARNING',fl.fl,
'not found'
110 id=self.
insert(
't_files',[
'fl_name'],[fl.fl])
118 if self.
parser.filelist.has_key(fn.fl_id):
119 fl=self.
parser.filelist[fn.fl_id]
123 cmd=
'select id from t_functions where fn_name=? and fid=? and issue=?'
124 self.
_execute(cmd,(fn.fn,fid,fn.issue))
125 res=self.
cur.fetchone()
128 hargs=[
'fn_name',
'fid',
'issue',
'lib']
129 args=[fn.fn,fid,fn.issue,fn.lib]
130 id = self.
insert(
't_functions',hargs,args)
137 for fn
in parser.functions.values():
146 for fn
in parser.functions.values():
148 print 'ERROR fn=',fn.fn,
'not in db yet'
151 hargs=[
'rid',
'fid',
'selfcounts',
'totalcounts']
152 args=[rid,fn.dbid,fn.selfcost,fn.totalcost]
155 self.
insert(
't_counts',hargs,args)
156 except IntegrityError
as detail:
157 print 'IntegrityError',detail
163 for i,counts
in fn.calls.iteritems():
165 cfn=self.
parser.functions[i]
167 print 'ERROR cfn=',cfn.fn,
'not in db yet'
169 hargs=[
'rid',
'fid',
'cfunid',
'counts']
170 args=[rid,fn.dbid,cfn.dbid,counts]
172 self.
insert(
't_links',hargs,args)
173 except IntegrityError
as detail:
174 print 'IntegrityError',detail
182 print 'some ERROR occured rolling back'
186 if __name__==
"__main__":
193 db=
DataBase(
'/afs/cern.ch/atlas/groups/Simulation/rtt/rttProfile.sqlite')
197 cmd=
"select distinct machine from t_run"
199 res = db.cur.fetchall()
204 db._execute(
"select * from t_hosts");
206 except OperationalError
as detail:
208 print "table t_hosts not found: try create one"
210 cmd=
"create table t_hosts (id integer primary key autoincrement, hostname varchar(32), os_type varchar(32), model varchar(32), cpuf float, ncpus integer , maxmem varchar(32), maxswp varchar(32), server varchar(6), resources text)"
215 print 'check',hostname
219 cmd=
'select id from t_hosts where hostname=?'
220 db._execute(cmd,(hostname,))
221 res=db.cur.fetchone()
224 print hostname,
"not found, adding it now"
226 hargs=[
'hostname',
'os_type',
'model',
'cpuf',
'ncpus',
'maxmem',
'maxswp',
'server',
'resources']
227 bargs=[
'HOST_NAME',
'type',
'model',
'cpuf',
'ncpus',
'maxmem',
'maxswp',
'server',
'RESOURCES']
229 hostInfo=dict(zip(*hostInfo))
230 hostInfo[
'maxmem']=
int(hostInfo[
'maxmem'].strip(
'M'))
231 hostInfo[
'maxswp']=
int(hostInfo[
'maxswp'].strip(
'M'))
232 args=[hostInfo[h]
for h
in bargs]
234 db.insert(
't_hosts',hargs,args)