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