@@ -57,3 +57,37 @@ def log_time(event, command, duration=0):
57
57
58
58
f .write ("{}\n " .format (json .dumps (log_event )))
59
59
f .close ()
60
+
61
+
62
+ def log_analyzer ():
63
+ """
64
+ Analyze .build_script_log and provide a summary of the time execution.
65
+ """
66
+ build_script_log_path = log_time_path ()
67
+ print ("--- Build Script Analyzer ---" )
68
+ build_events = []
69
+ total_duration = 0
70
+ if os .path .exists (build_script_log_path ):
71
+ print ("Build Script Log: {}" .format (build_script_log_path ))
72
+ with open (build_script_log_path ) as f :
73
+ for event in f :
74
+ build_event = json .loads (event )
75
+ build_event ["duration" ] = float (build_event ["duration" ])
76
+ total_duration += build_event ["duration" ]
77
+ build_events .append (build_event )
78
+ finish_events = [x for x in build_events if x ["event" ] == "end" ]
79
+ finish_events .sort (key = lambda x : x ["duration" ], reverse = True )
80
+
81
+ print ("Build Percentage \t Build Duration (sec) \t Build Phase" )
82
+ print ("================ \t ==================== \t ===========" )
83
+ event_row = '{:<17.1%} \t {:<21} \t {}'
84
+ for build_event in finish_events :
85
+ duration_percentage = \
86
+ (float (build_event ["duration" ]) / float (total_duration ))
87
+ print (event_row .format (duration_percentage ,
88
+ build_event ["duration" ],
89
+ build_event ["command" ]))
90
+ print ("Total Duration: {}" .format (total_duration ))
91
+ else :
92
+ print ("Skip build script analyzer" )
93
+ print (".build_script_log file not found at {}" .format (build_script_log_path ))
0 commit comments