ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/CRAB/python/parseCrabFjr.py
(Generate patch)

Comparing COMP/CRAB/python/parseCrabFjr.py (file contents):
Revision 1.1 by gutsche, Mon Oct 9 23:30:23 2006 UTC vs.
Revision 1.7.4.1 by afanfani, Mon Apr 7 18:13:47 2008 UTC

# Line 2 | Line 2
2  
3   import sys, getopt, string
4  
5 < from FwkJobRep.ReportParser import readJobReport
5 > from ProdCommon.FwkJobRep.ReportParser import readJobReport
6 > from DashboardAPI import apmonSend, apmonFree
7 >
8  
9   def main(argv) :
10      """
11      parseCrabFjr
12  
13 <    parse CRAB FrameworkJobReport on WN and return parameters to WN wrapper script
14 <
15 <    prints information separated by semi-colon in fixed order:
14 <
15 <    1. ExitStatus (0 or ExitStatus from CMSSW)
13 >    - parse CRAB FrameworkJobReport on WN: { 'protocol' : { 'action' : [attempted,succedeed,total-size,total-time,min-time,max-time] , ... } , ... }
14 >    - report parameters to DashBoard using DashBoardApi.py: for all 'read' actions of all protocols, report MBPS
15 >    - return ExitStatus and dump of DashBoard report separated by semi-colon to WN wrapper script
16  
17      required parameters:
18      --input            :       input FJR xml file
19 +    --MonitorID        :       DashBoard MonitorID
20 +    --MonitorJobID     :       DashBoard MonitorJobID
21  
22      optional parameters:
23      --help             :       help
# Line 25 | Line 27 | def main(argv) :
27  
28      # defaults
29      input = ''
30 +    MonitorID = ''
31 +    MonitorJobID = ''
32      debug = 0
33  
34      try:
35 <        opts, args = getopt.getopt(argv, "", ["input=", "debug", "help"])
35 >        opts, args = getopt.getopt(argv, "", ["input=", "MonitorID=", "MonitorJobID=", "debug", "help"])
36      except getopt.GetoptError:
37          print main.__doc__
38          sys.exit(2)
# Line 40 | Line 44 | def main(argv) :
44              sys.exit()
45          elif opt == "--input" :
46              input = arg
47 +        elif opt == "--MonitorID" :
48 +            MonitorID = arg
49 +        elif opt == "--MonitorJobID" :
50 +            MonitorJobID = arg
51          elif opt == "--debug" :
52              debug = 1
53              
54 <    if input == '':
54 >    if input == '' or MonitorID == '' or MonitorJobID == '':
55          print main.__doc__
56          sys.exit()
57  
58      # load FwkJobRep
59      jobReport = readJobReport(input)[0]
60  
61 <    report = []
61 >    exit_status = ''
62      
63 <    # get ExitStatus of last error
64 <    if len(jobReport.errors) != 0 :
65 <        report.append(str(jobReport.errors[-1]['ExitStatus']))
66 <    else :
67 <        report.append(str(0))
63 >    ##### temporary fix for FJR incomplete ####
64 >    fjr = open (input)
65 >    len_fjr = len(fjr.readlines())
66 >    if (len_fjr <= 6):
67 >       ### 50115 - cmsRun did not produce a valid/readable job report at runtime
68 >       exit_status = str(50115)
69 >    else:
70 >        # get ExitStatus of last error
71 >        if len(jobReport.errors) != 0 :
72 >            exit_status = str(jobReport.errors[-1]['ExitStatus'])
73 >        else :
74 >            exit_status = str(0)
75  
76      # get i/o statistics
77      storageStatistics = str(jobReport.storageStatistics)
78  
79 <    print ';'.join(report)
79 >    # dashboard report dictionary
80 >    dashboard_report = {}
81 >
82 >    # check if storageStatistics is valid
83 >    if storageStatistics.find('Storage statistics:') != -1 :
84 >        # report form: { 'protocol' : { 'action' : [attempted,succedeed,total-size,total-time,min-time,max-time] , ... } , ... }
85 >        report = {}
86 >        data = storageStatistics.split('Storage statistics:')[1]
87 >        data_fields = data.split(';')
88 >        for data_field in data_fields:
89 >            # parse: format protocol/action = attepted/succedeed/total-size/total-time/min-time/max-time
90 >            if data_field == ' ' or not data_field or data_field == '':
91 >               continue
92 >            key = data_field.split('=')[0].strip()
93 >            item = data_field.split('=')[1].strip()
94 >            protocol = str(key.split('/')[0].strip())
95 >            action = str(key.split('/')[1].strip())
96 >            item_array = item.split('/')
97 >            attempted = str(item_array[0].strip())
98 >            succeeded = str(item_array[1].strip())
99 >            total_size = str(item_array[2].strip().split('MB')[0])
100 >            total_time = str(item_array[3].strip().split('ms')[0])
101 >            min_time = str(item_array[4].strip().split('ms')[0])
102 >            max_time = str(item_array[5].strip().split('ms')[0])
103 >            # add to report
104 >            if protocol in report.keys() :
105 >                if action in report[protocol].keys() :
106 >                    print 'protocol/action:',protocol,'/',action,'listed twice in report, taking the first'
107 >                else :
108 >                    report[protocol][action] = [attempted,succeeded,total_size,total_time,min_time,max_time]
109 >            else :
110 >                report[protocol] = {action : [attempted,succeeded,total_size,total_time,min_time,max_time] }
111 >
112 >        if debug :
113 >            for protocol in report.keys() :
114 >                print 'protocol:',protocol
115 >                for action in report[protocol].keys() :
116 >                    print 'action:',action,'measurement:',report[protocol][action]
117 >
118 >        # extract information to be sent to DashBoard
119 >        # per protocol and for action=read, calculate MBPS
120 >        # dashboard key is io_action
121 >        dashboard_report['MonitorID'] = MonitorID
122 >        dashboard_report['MonitorJobID'] = MonitorJobID
123 >        for protocol in report.keys() :
124 >            for action in report[protocol].keys() :
125 >                try: size = float(report[protocol][action][2])
126 >                except: size = 'NULL'
127 >                try: time = float(report[protocol][action][3])/1000
128 >                except: time = 'NULL'
129 >                dashboard_report['io_'+protocol+'_'+action] = str(size)+'_'+str(time)
130 >
131 >        if debug :
132 >            ordered = dashboard_report.keys()
133 >            ordered.sort()
134 >            for key in ordered:
135 >                print key,'=',dashboard_report[key]
136 >
137 >        # send to DashBoard
138 >        apmonSend(MonitorID, MonitorJobID, dashboard_report)
139 >        apmonFree()
140 >
141 >    # prepare exit string
142 >    exit_string = str(exit_status)
143 >    for key in dashboard_report.keys() :
144 >        exit_string += ';' + str(key) + '=' + str(dashboard_report[key])
145 >
146      
147  
148 +    return exit_string
149 +
150  
151   if __name__ == '__main__' :
152 <    main(sys.argv[1:])
152 >    exit_status = main(sys.argv[1:])
153 >    # output for wrapper script
154 >    print exit_status
155  
156      

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines