| 1 | #!/usr/bin/env python
 | 
|---|
| 2 | #----------------------------------#
 | 
|---|
| 3 | # -- Author: V. Garonne
 | 
|---|
| 4 | # -- Mail: garonne@lal.in2p3.fr
 | 
|---|
| 5 | # -- Date: 08/25/2006 
 | 
|---|
| 6 | # -- Name: generateGantt
 | 
|---|
| 7 | # -- Description: script to generate 
 | 
|---|
| 8 | # -- the gantt chart from a input file
 | 
|---|
| 9 | # -- It uses Paw.
 | 
|---|
| 10 | #----------------------------------#
 | 
|---|
| 11 | 
 | 
|---|
| 12 | import os
 | 
|---|
| 13 | import sys
 | 
|---|
| 14 | import time
 | 
|---|
| 15 | import string
 | 
|---|
| 16 | import commands
 | 
|---|
| 17 | 
 | 
|---|
| 18 | def usage ():
 | 
|---|
| 19 |     print 'Usage : > generateGannt <input file>'
 | 
|---|
| 20 | 
 | 
|---|
| 21 | if __name__ == '__main__':
 | 
|---|
| 22 |     if len(sys.argv) != 2:
 | 
|---|
| 23 |         usage ()
 | 
|---|
| 24 |         sys.exit(-1)
 | 
|---|
| 25 |     
 | 
|---|
| 26 |     # First read the file    
 | 
|---|
| 27 |     file  = sys.argv[1]
 | 
|---|
| 28 |     f     = open (file)
 | 
|---|
| 29 |     lines = f.readlines()
 | 
|---|
| 30 |     f.close ()
 | 
|---|
| 31 |     
 | 
|---|
| 32 |     # Instanciate constants
 | 
|---|
| 33 |     total = len(lines)
 | 
|---|
| 34 |     min   = time.time()
 | 
|---|
| 35 |     max   = 0.0
 | 
|---|
| 36 |     for line in lines:
 | 
|---|
| 37 |         package, start, end = string.split(line)
 | 
|---|
| 38 |         #print float(end)-float(start)
 | 
|---|
| 39 |         if float(start)< min:
 | 
|---|
| 40 |             min = float(start) 
 | 
|---|
| 41 |         if float(end)> max:
 | 
|---|
| 42 |             max = float(end)
 | 
|---|
| 43 | 
 | 
|---|
| 44 |     # then compute for each package its line
 | 
|---|
| 45 |     packages = {}
 | 
|---|
| 46 |     for line in lines:
 | 
|---|
| 47 |         package, start, end = string.split(line)
 | 
|---|
| 48 |         packages[package] = {'start': float(start)-min , 'end':float(end)-min}
 | 
|---|
| 49 | 
 | 
|---|
| 50 |     deb = 0.0
 | 
|---|
| 51 |     index = 0
 | 
|---|
| 52 |     step = 0.01
 | 
|---|
| 53 |     i = float(max)-float(min)
 | 
|---|
| 54 |     done  = list()
 | 
|---|
| 55 |     start = list() 
 | 
|---|
| 56 |     while i>0:
 | 
|---|
| 57 |       for package in packages:        
 | 
|---|
| 58 |             if not package in done:
 | 
|---|
| 59 |                 if packages[package]['end']>i:
 | 
|---|
| 60 |                     index = index + 1
 | 
|---|
| 61 |                     packages[package]['index']= index
 | 
|---|
| 62 |                     done.append(package)
 | 
|---|
| 63 |                     #print i,index, package
 | 
|---|
| 64 |             if not package in start:
 | 
|---|
| 65 |                 if packages[package]['start']> i:        
 | 
|---|
| 66 |                     index = index - 1                    
 | 
|---|
| 67 |                     start.append(package)
 | 
|---|
| 68 |                     #print i, 'start', package, packages[package]['start'], packages[package]['end'], packages[package]['end']-packages[package]['start']
 | 
|---|
| 69 |       i = i-step
 | 
|---|
| 70 | 
 | 
|---|
| 71 |     y = 0
 | 
|---|
| 72 |     for package in packages:
 | 
|---|
| 73 |         print package
 | 
|---|
| 74 |         if packages[package]['index'] > y:
 | 
|---|
| 75 |             y = packages[package]['index']
 | 
|---|
| 76 | 
 | 
|---|
| 77 |     f = open ("gantt.dat", "w+")     
 | 
|---|
| 78 |     for index in xrange(total+1):
 | 
|---|
| 79 |        for package in packages:
 | 
|---|
| 80 |             if packages[package]['index'] == index:
 | 
|---|
| 81 |                 line = str(packages[package]['index'])+'\t'+str(packages[package]['start'])+'\t'+ str(packages[package]['end'])+'\n'
 | 
|---|
| 82 |                 f.write  (line)
 | 
|---|
| 83 |     f.close  ()    
 | 
|---|
| 84 |         
 | 
|---|
| 85 | #    f = open ("gantt.dat", "w+")    
 | 
|---|
| 86 | #    index = 1
 | 
|---|
| 87 | #    for line in lines:
 | 
|---|
| 88 | #        package, start, end = string.split(line)
 | 
|---|
| 89 | #        f.write  (str(index)+ ' ' + str(float(start)-min)+ ' ' + str(float(end)-min) + '\n')        
 | 
|---|
| 90 | #        index = index + 1        
 | 
|---|
| 91 | #    f.close  ()
 | 
|---|
| 92 |     
 | 
|---|
| 93 |     content= '''    
 | 
|---|
| 94 |         ops
 | 
|---|
| 95 |         opt nsta
 | 
|---|
| 96 |         Total = %s
 | 
|---|
| 97 |         v/cre y([Total])  r
 | 
|---|
| 98 |         v/cre x1([Total]) r
 | 
|---|
| 99 |         v/cre x2([Total]) r
 | 
|---|
| 100 |         v/read y,x1,x2  gantt.dat
 | 
|---|
| 101 | 
 | 
|---|
| 102 |         deb = 0.0
 | 
|---|
| 103 |         max    = %s 
 | 
|---|
| 104 |         totaly = %s
 | 
|---|
| 105 |         set NDVY [Totaly].15
 | 
|---|
| 106 |         NULL [deb] [max] 1 [Totaly] 
 | 
|---|
| 107 |         SET BORD 1
 | 
|---|
| 108 |         SET FAIS 1        
 | 
|---|
| 109 |         SET PLCI 2
 | 
|---|
| 110 |         SET FACI 3
 | 
|---|
| 111 |         *HISTOGRAM/CREATE/2DHISTO 1 'Gannt chart' 0 10000 [max] 0 0 [Total]
 | 
|---|
| 112 |         SET BORD 1
 | 
|---|
| 113 |         SET FAIS 1        
 | 
|---|
| 114 |         SET PLCI 2
 | 
|---|
| 115 |         SET FACI 3
 | 
|---|
| 116 |         
 | 
|---|
| 117 |         DO i= 1,[Total]  
 | 
|---|
| 118 |             y2 = y([i])+0.5
 | 
|---|
| 119 |             GRAPHICS/PRIMITIVES/BOX x1([i]) x2([i]) y([i]) [y2] 
 | 
|---|
| 120 |         ENDDO
 | 
|---|
| 121 |         GRAPHICS/HPLOT/ATITLE 'Time(s)' 'Total number of parallel execution' ! 220
 | 
|---|
| 122 |         cps
 | 
|---|
| 123 |         '''%(str(total), str(float(max)-float(min)), str(y))
 | 
|---|
| 124 |     f = open ("gantt.kumac", "w+")
 | 
|---|
| 125 |     f.write  (content)
 | 
|---|
| 126 |     f.close  ()
 | 
|---|
| 127 | 
 | 
|---|
| 128 |     f = open ("exec.kumac", "w+")
 | 
|---|
| 129 |     f.write  ("\n\n gantt.kumac")
 | 
|---|
| 130 |     f.close  ()
 | 
|---|
| 131 | 
 | 
|---|
| 132 |     status, output = commands.getstatusoutput ("paw<exec.kumac")    
 | 
|---|
| 133 | #--------- EoF --------# | 
|---|