Package Ganga :: Package Core :: Package JobRepository :: Module TimeTest
[hide private]
[frames] | no frames]

Source Code for Module Ganga.Core.JobRepository.TimeTest

  1  ##!/usr/bin/env python 
  2  ################################################################################ 
  3  # Ganga Project. http://cern.ch/ganga 
  4  # 
  5  # $Id: TimeTest.py,v 1.1 2008-07-17 16:40:50 moscicki Exp $ 
  6  ################################################################################ 
  7   
  8  ##import psyco 
  9  ##print "psyco imported", psyco 
 10  ##psyco.full() 
 11   
 12  import sys, os 
 13  import time 
 14  import tempfile 
 15   
 16  import TimeTest 
 17  _thisDir = os.path.dirname(TimeTest.__file__) 
 18  if not _thisDir: 
 19      _thisDir = os.getcwd() 
 20  _root = os.path.dirname(os.path.dirname(os.path.dirname(_thisDir))) 
 21  sys.path.append(_root) 
 22   
 23   
 24  from Ganga.GPIDev.Lib.Job.Job  import Job 
 25  #from GangaLHCb.Lib.Gaudi.Gaudi import Gaudi 
 26  from Ganga.Lib.Executable.Executable import Executable 
 27  from Ganga.Core.JobRepository.ARDA import repositoryFactory 
 28  from Ganga.GPIDev.Streamers.SimpleStreamer import SimpleJobStreamer 
 29  import Ganga.Runtime.plugins 
 30   
 31  DEBUG = False 
 32  #DEBUG = True 
 33   
 34  ################################################################################     
35 -def _startText(ff, txt):
36 ff.write(txt) 37 t1 = time.time() 38 ff.write('operation started at %s \n' % time.ctime(t1)) 39 return t1
40
41 -def _endText(ff, t1):
42 t2 = time.time() 43 ff.write('operation finished at %s \n' % time.ctime(t2)) 44 ff.write('time used: %f seconds \n' % (t2 - t1)) 45 ff.write('-s->%f<-s-\n\n\n'% (t2 - t1))
46
47 -def runTest(NJOBS, NRUN, rootDir, output_dir, rep_type):
48 if DEBUG: 49 print 'from runTest: rootDir %s, output_dir %s'%(rootDir, output_dir) 50 if rep_type == "Remote": 51 repository = repositoryFactory(repositoryType = rep_type, 52 root_dir = rootDir, 53 streamer = SimpleJobStreamer(), 54 host = 'gangamd.cern.ch', 55 port = 8822, 56 login = os.getlogin(), 57 keepalive = True) 58 elif rep_type == "Local": 59 repository = repositoryFactory(repositoryType = rep_type, 60 root_dir = rootDir, 61 streamer = SimpleJobStreamer(), 62 local_root = '/tmp') 63 else: 64 print "Wrong type of repository..." 65 print "Exiting ..." 66 return 67 nn = tempfile.mktemp(suffix = '.test') 68 nn = os.path.join(output_dir, os.path.basename(nn)) 69 ff = file(nn, 'w') 70 try: 71 jjj = [] 72 for n in range(NRUN): 73 ff.write("NUMBER of jobs in the repository %d \n" %len(jjj)) 74 jj = [] 75 for i in range(NJOBS): 76 j = Job() 77 #j.application = Gaudi() 78 j.name = "MyJob" + str(i) 79 jj.append(j) 80 81 jjj.extend(jj) 82 t1 = _startText(ff, 'registering %d jobs...' % NJOBS) 83 repository.registerJobs(jj) 84 if DEBUG: 85 print "--->command status", "OK", "\n" 86 _endText(ff, t1) 87 88 89 t1 = _startText(ff, 'deleting jobs...') 90 repository.deleteJobs(map(lambda j: j.id, jjj)) 91 if DEBUG: 92 print "--->command status", "OK", "\n" 93 _endText(ff, t1) 94 95 finally: 96 ff.close()
97 98 ################################################################################
99 -def NormPath(path):
100 if sys.platform == 'win32': 101 directory, file = os.path.split(path) 102 drive, tail = os.path.splitdrive(directory) 103 path_elem = tail.split(os.sep) 104 path = drive + os.sep 105 for i in range(len(path_elem)): 106 elem = path_elem[i] 107 if elem: 108 sub_elem = elem.split() 109 elem = sub_elem[0] 110 if len(elem) > 8 or len(sub_elem) > 1: 111 elem = elem[:6] + '~1' 112 path = os.path.join(path, elem) 113 114 path = os.path.join(path, file) 115 116 return path
117 118 ################################################################################ 119 if __name__ == '__main__': 120 NJOBS = int(raw_input('Enter a number of job to test --->')) 121 NRUN = int(raw_input('Enter a number of runs to test --->')) 122 OUTPUT = raw_input('Enter a name of output dir --->') 123 REPTYPE= raw_input('Enter type of repository (Local[1] or Remote[2]) --->') 124 if REPTYPE == '1': 125 REPTYPE = 'Local' 126 elif REPTYPE == '2': 127 REPTYPE = 'Remote' 128 else: 129 print "Unknown type of repository. Exiting" 130 sys.exit(1) 131 NUSERS = 1 132 dname = 'runs_' + str(NRUN) + '__jobs_' + str(NJOBS) 133 output_dir = os.path.join(os.getcwd(), OUTPUT, REPTYPE, dname) 134 if not os.path.exists(output_dir): 135 os.makedirs(output_dir) 136 print "output dir is ", output_dir 137 138 python_path = NormPath(sys.executable) 139 i = 0 140 while i < NUSERS: 141 rootDir = '/testdir/GangaTest/user' +str(i) 142 cmd = '"import sys\nsys.path.append(\'%s\')\nfrom TimeTest import runTest\nrunTest(%d, %d, \'%s\',\'%s\',\'%s\')"' % (_thisDir, NJOBS, NRUN, rootDir, output_dir, REPTYPE) 143 cmd = cmd[1:-1] 144 ## if sys.version_info[:2] < (2,3): 145 ## cmd = cmd[1:-1] 146 if DEBUG: 147 print cmd 148 pid = os.spawnl(os.P_NOWAIT, python_path, python_path, "-c", cmd) 149 if DEBUG: 150 print "new user process started %d" % pid 151 i+=1 152