1- #!/usr/bin/python
2- # Copyright 2021 Hewlett Packard Enterprise Development LP
3- #
4- # Permission is hereby granted, free of charge, to any person obtaining a
5- # copy of this software and associated documentation files (the "Software"),
6- # to deal in the Software without restriction, including without limitation
7- # the rights to use, copy, modify, merge, publish, distribute, sublicense,
8- # and/or sell copies of the Software, and to permit persons to whom the
9- # Software is furnished to do so, subject to the following conditions:
10- #
11- # The above copyright notice and this permission notice shall be included in
12- # all copies or substantial portions of the Software.
13- #
14- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17- #
18- # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
19- # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20- # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21- # USE OR OTHER DEALINGS IN THE SOFTWARE.
22-
1+ #!/usr/bin/python3
232
243# This is a re-writing of post_proc.sh into Python. Feel free to
254# provide feedback on how to make it better - either better
@@ -113,7 +92,7 @@ def find_vrules(source):
11392 return vrules ,float (start_time ),float (end_time ),interval_times
11493
11594def open_rrd (basename ,start_time ,end_time ,max_interval ):
116- # print "Opening %s.rrd with start time %d and end time %d" % (basename,int(start_time),int(end_time))
95+ # print( "Opening %s.rrd with start time %d and end time %d" % (basename,int(start_time),int(end_time) ))
11796
11897 data_sources = [ 'DS:mbps:GAUGE:%d:U:U' % max_interval ]
11998 rra = [ 'RRA:AVERAGE:0.5:1:%d' % ((int (end_time ) - int (start_time )) + 1 ) ]
@@ -126,7 +105,7 @@ def open_rrd(basename,start_time,end_time,max_interval):
126105 return basename + ".rrd"
127106
128107def update_heartbeat (basename ,heartbeat ):
129- # print "Updating heartbeat with %d" % heartbeat
108+ # print( "Updating heartbeat with %d" % heartbeat)
130109 rrdtool .tune (basename + ".rrd" ,
131110 '--heartbeat' , 'mbps:%d' % heartbeat )
132111
@@ -140,13 +119,13 @@ def add_to_ksink(basename,start_time,end_time,ksink):
140119 'AVERAGE' ,
141120 '--start' , str (int (start_time )),
142121 '--end' , str (int (end_time )))
143- # print "First %d last %d step %d results %d" % (first, last, step, len(results))
122+ # print( "First %d last %d step %d results %d" % (first, last, step, len(results) ))
144123 for key ,result in enumerate (results ,first ):
145124 if result [0 ] and key in ksink :
146125 ksink [key ] += float (result [0 ])
147126 else :
148127 if result [0 ]:
149- print "Key %d not in ksink" % key
128+ print ( "Key %d not in ksink" % key )
150129
151130def process_result (basename , raw_results , end_time , ksink ):
152131 first_result = True
@@ -161,7 +140,7 @@ def process_result(basename, raw_results, end_time, ksink):
161140
162141
163142 for raw_result in raw_results :
164- # print "Checking result %s" % raw_result
143+ # print( "Checking result %s" % raw_result)
165144 if "Interim result:" in raw_result :
166145 # human format
167146 fields = raw_result .split ()
@@ -201,55 +180,55 @@ def process_result(basename, raw_results, end_time, ksink):
201180 have_result = True
202181 else :
203182 have_result = False
204-
183+
205184 if first_result and have_result :
206185 # we could use the overal start time, but using the first
207186 # timestamp for this instance may save us some space in
208187 # the rrdfile. we do though want to subtract the
209188 # interim_interval from that timestamp to give us some
210189 # wriggle-room - particularly if the interval happens to
211190 # end precisely on a step boundary...
212- # print "First entry for %s is %f at time %f" % (basename, interim_result,interim_end)
191+ # print( "First entry for %s is %f at time %f" % (basename, interim_result,interim_end) )
213192 open_rrd (basename ,
214193 interim_end - interim_interval ,
215194 end_time ,
216195 max_interval )
217196 first_timestamp = interim_end
218197 first_result = False
219-
198+
220199 if int (math .ceil (interim_interval )) > max_interval :
221200 max_interval = int (math .ceil (interim_interval ))
222201 update_heartbeat (basename ,max_interval )
223-
202+
224203 # perhaps one of these days, once we know that the rrdtool
225204 # bits can handle it, we will build a big list of results and
226205 # feed them en mass. until then we will dribble them one at a
227206 # time
228207 if have_result :
229- #print "updating rrd with %s at %s" % (interim_result, interim_end)
208+ #print( "updating rrd with %s at %s" % (interim_result, interim_end) )
230209 try :
231210 update_rrd (basename ,interim_result ,interim_end )
232211 except Exception as e :
233- print "Update to %s with %s at %s failed with %s" % (basename ,interim_result ,interim_end ,e )
212+ print ( "Update to %s with %s at %s failed with %s" % (basename ,interim_result ,interim_end ,e ) )
234213 have_result = False
235214 had_results = True
236215
237216 if had_results :
238217 last_timestamp = interim_end
239- # print "First timestamp for this instance %f last %f" % (first_timestamp,last_timestamp)
218+ # print( "First timestamp for this instance %f last %f" % (first_timestamp,last_timestamp) )
240219 return first_timestamp , last_timestamp
241220 else :
242221 return 0 , 0
243222
244223def process_result_files (prefix ,start_time ,end_time ,ksink ):
245- print "Prefix is %s" % prefix
224+ print ( "Prefix is %s" % prefix )
246225 min_timestamp = 9999999999.9
247226 results_list = glob .glob (prefix + "*.out" )
248227
249228 for result_file in results_list :
250229 basename = result_file .replace (".out" ,"" )
251230 raw_results = open (result_file ,"r" )
252- # print "Processing file %s" % basename
231+ # print( "Processing file %s" % basename)
253232 first_timestamp , last_timestamp = process_result (basename ,
254233 raw_results ,
255234 end_time ,
@@ -261,27 +240,27 @@ def process_result_files(prefix,start_time,end_time,ksink):
261240 # OK, now we get the massaged results
262241 add_to_ksink (basename ,first_timestamp ,last_timestamp ,ksink )
263242
264- # print "For %s min_timestamp is %s" % (prefix, min_timestamp)
243+ # print( "For %s min_timestamp is %s" % (prefix, min_timestamp) )
265244 return min_timestamp
266245
267246def generate_overall (prefix ,start_time ,end_time ,ksink ):
268247 overall = prefix + "_overall"
269248 open_rrd (overall ,start_time - 1 ,end_time ,1 )
270249
271- # print "Starting time %s ending time %s" % (start_time,end_time)
250+ # print( "Starting time %s ending time %s" % (start_time,end_time) )
272251 # one cannot rely on the enumeration of a dictionary being in key
273252 # order and I do not know how to sort one, so we will simply walk
274253 # the possible keys based on the start_time and end_time and if we
275254 # find that key in the kitchen sink, we will use the value to
276255 # update the overall rrd.
277256 prevkey = - 1
278- for key in xrange (int (start_time ),int (end_time )+ 1 ):
257+ for key in range (int (start_time ),int (end_time )+ 1 ):
279258 if key in ksink :
280259 try :
281260 update_rrd (overall ,ksink [key ],key )
282261 prevkey = key
283262 except Exception as e :
284- print "Update to %s failed for %d, previous %d %s" % (overall , key , prevkey , e )
263+ print ( "Update to %s failed for %d, previous %d %s" % (overall , key , prevkey , e ) )
285264
286265def overall_min_max_avg (prefix ,start_time ,end_time ,intervals ):
287266
@@ -327,13 +306,13 @@ def overall_min_max_avg(prefix,start_time,end_time,intervals):
327306 'PRINT:avg:"%6.2lf"' ,
328307 'PRINT:min:"%6.2lf"' ,
329308 'PRINT:max:"%6.2lf"' )[2 ]
330- # print "from %d to %d iavg, imin, imax are %s" % (start,end,result)
309+ # print( "from %d to %d iavg, imin, imax are %s" % (start,end,result) )
331310 iavg = float (result [0 ].strip ('"' ))
332311 imin = float (result [1 ].strip ('"' ))
333312 imax = float (result [2 ].strip ('"' ))
334313 results_list .append ((iavg , imin , imax , start , end ))
335314
336- for time in xrange (start ,end + 1 ):
315+ for time in range (start ,end + 1 ):
337316 rrdtool .update (prefix + "_intervals.rrd" ,
338317 '%d:%f:%f:%f' % (time , iavg , imin , imax ))
339318 if iavg > max_average :
@@ -372,8 +351,8 @@ def graph_overall(prefix,start_time,end_time,vrules,peak_interval_id=None,peak_a
372351
373352 units , multiplier , direction = units_et_al_by_prefix (prefix )
374353
375- # print units,multiplier,direction
376- # print "Vrules",vrules
354+ # print( units,multiplier,direction)
355+ # print( "Vrules",vrules)
377356
378357 interval_specs = []
379358 if peak_interval_id :
@@ -440,7 +419,7 @@ def setup_parser() :
440419 help = "Generate graphs of individual tests" )
441420 parser .add_argument ("-I" , "--intervals" , action = 'store_true' ,
442421 default = False ,
443- help = "Emit the results for all intervals, not just peak" )
422+ help = "Emit the results for all intervals, not just peak" )
444423 parser .add_argument ("-a" , "--annotation" ,default = None ,
445424 help = "Annotation to add to chart titles" )
446425 parser .add_argument ("-t" , "--title" , default = None ,
@@ -458,23 +437,23 @@ def setup_parser() :
458437 prefix = filename .replace (".log" ,"" )
459438 source = open (filename ,"r" )
460439 vrules ,start_time ,end_time ,intervals = find_vrules (source )
461- #print vrules
440+ #print( vrules)
462441
463442 # at one point for some reason I thought one could not add to a
464443 # dict on the fly, which of course I now know is silly, but for
465444 # the time being I will preallocate the entire dict in one fell
466445 # swoop until I can modify add_to_ksink() accordingly
467446 length = int (end_time + 1 ) - int (start_time )
468- ksink = dict (zip (xrange (int (start_time ),
447+ ksink = dict (zip (range (int (start_time ),
469448 int (end_time )+ 1 ),
470449 [0.0 ] * length ))
471450
472451 min_timestamp = process_result_files (prefix ,start_time ,end_time ,ksink )
473452 if min_timestamp == 9999999999.9 :
474- print "There were no valid results for this prefix!"
453+ print ( "There were no valid results for this prefix!" )
475454 exit ()
476455
477- # print "Min timestamp for %s is %s start time is %s end_time is %s" % (prefix,min_timestamp,start_time,end_time)
456+ # print( "Min timestamp for %s is %s start time is %s end_time is %s" % (prefix,min_timestamp,start_time,end_time) )
478457 generate_overall (prefix ,min_timestamp - 2 ,end_time ,ksink )
479458 peak_interval_id , min_graph_interval , results_list = overall_min_max_avg (prefix ,min_timestamp ,end_time ,intervals )
480459 peak_average = results_list [0 ][0 ]
@@ -490,14 +469,14 @@ def setup_parser() :
490469 graph_individual (prefix , min_timestamp , end_time , vrules ,
491470 major_interval = min_graph_interval ,
492471 annotation = args .annotation ,override = args .title )
493-
472+
494473 units , multiplier , direction = units_et_al_by_prefix (prefix )
495- print "Average of peak interval is %.3f %s from %d to %d" % (results_list [0 ][0 ] * float (multiplier ), units , peak_start , peak_end )
496- print "Minimum of peak interval is %.3f %s from %d to %d" % (peak_minimum * float (multiplier ), units , peak_start , peak_end )
497- print "Maximum of peak interval is %.3f %s from %d to %d" % (peak_maximum * float (multiplier ), units , peak_start , peak_end )
474+ print ( "Average of peak interval is %.3f %s from %d to %d" % (results_list [0 ][0 ] * float (multiplier ), units , peak_start , peak_end ) )
475+ print ( "Minimum of peak interval is %.3f %s from %d to %d" % (peak_minimum * float (multiplier ), units , peak_start , peak_end ) )
476+ print ( "Maximum of peak interval is %.3f %s from %d to %d" % (peak_maximum * float (multiplier ), units , peak_start , peak_end ) )
498477
499478 if args .intervals :
500479 for id , interval in enumerate (results_list [1 :]):
501- print "Average of interval %d is %.3f %s from %d to %d" % (id , interval [0 ] * float (multiplier ), units , interval [3 ], interval [4 ])
502- print "Minimum of interval %d is %.3f %s from %d to %d" % (id , interval [1 ] * float (multiplier ), units , interval [3 ], interval [4 ])
503- print "Maximum of interval %d is %.3f %s from %d to %d" % (id , interval [2 ] * float (multiplier ), units , interval [3 ], interval [4 ])
480+ print ( "Average of interval %d is %.3f %s from %d to %d" % (id , interval [0 ] * float (multiplier ), units , interval [3 ], interval [4 ]) )
481+ print ( "Minimum of interval %d is %.3f %s from %d to %d" % (id , interval [1 ] * float (multiplier ), units , interval [3 ], interval [4 ]) )
482+ print ( "Maximum of interval %d is %.3f %s from %d to %d" % (id , interval [2 ] * float (multiplier ), units , interval [3 ], interval [4 ]) )
0 commit comments