5
5
6
6
7
7
def load_input_JSON (filename ):
8
- file = open (filename ,"r" )
9
- stats = json .load (file )
10
- file .close ()
8
+ with open (filename ,"r" ) as file :
9
+ stats = json .load (file )
11
10
return stats
12
11
13
12
14
13
def build_data_file (stats ,output_file_name ):
15
- file = open (output_file_name ,"w" )
16
- num_functions = 0
17
- num_locations = 0
18
- time = 0.0
19
- num_functions_per_second = 0
20
- num_locations_per_second = 0
21
- for file_stats in stats ["table-files" ]:
22
- for fn_stats in file_stats ["functions" ]:
23
- delta_time = fn_stats ["LVSA-duration" ] + fn_stats ["TA-duration" ]
24
- #if delta_time > 1.0:
25
- # print("TIME[" + str(delta_time) + "]: " + fn_stats["function-name"])
26
- # continue
27
- time = time + delta_time
28
- num_functions = num_functions + 1
29
- num_locations = num_locations + fn_stats ["num-locations" ]
30
- if time > 0.0001 :
31
- num_functions_per_second = num_functions / time
32
- num_locations_per_second = num_locations / time
33
- file .write (str (time ) + " " + \
34
- str (num_functions ) + " " + \
35
- str (num_locations ) + " " + \
36
- str (num_functions_per_second ) + " " + \
37
- str (num_locations_per_second ) + "\n " )
38
- file .close ()
39
-
14
+ with open (output_file_name ,"w" ) as file :
15
+ num_functions = 0
16
+ num_locations = 0
17
+ time = 0.0
18
+ num_functions_per_second = 0
19
+ num_locations_per_second = 0
20
+ for file_stats in stats ["table-files" ]:
21
+ for fn_stats in file_stats ["functions" ]:
22
+ delta_time = fn_stats ["LVSA-duration" ] + fn_stats ["TA-duration" ]
23
+ #if delta_time > 1.0:
24
+ # print("TIME[" + str(delta_time) + "]: " + fn_stats["function-name"])
25
+ # continue
26
+ time = time + delta_time
27
+ num_functions = num_functions + 1
28
+ num_locations = num_locations + fn_stats ["num-locations" ]
29
+ if time > 0.0001 :
30
+ num_functions_per_second = num_functions / time
31
+ num_locations_per_second = num_locations / time
32
+ file .write (str (time ) + " " + \
33
+ str (num_functions ) + " " + \
34
+ str (num_locations ) + " " + \
35
+ str (num_functions_per_second ) + " " + \
36
+ str (num_locations_per_second ) + "\n " )
37
+
40
38
41
39
def build_functions_speed_plot_file (plot_file_name ,data_file_name ):
42
- file = open (plot_file_name ,"w" )
43
- file .write (
44
- "set title \" Number of analysed functions per second.\" \n "
45
- "set terminal svg font 'Liberation,10' size 550,480\n "
46
- "set output './" + os .path .splitext (os .path .basename (plot_file_name ))[0 ] + ".svg'\n "
47
- "set xtic rotate\n "
48
- "set ytic auto\n "
49
- "set xlabel \" Time (sec)\" \n "
50
- "set ylabel \" Speed (funcs/sec)\" \n "
51
- "set grid\n "
52
- "set style data lines\n "
53
- "unset key\n "
54
- "plot \" ./" + os .path .basename (data_file_name ) + "\" using 1:4 lt -1 lw 2\n "
55
- )
56
- file .close ()
40
+ with open (plot_file_name ,"w" ) as file :
41
+ file .write (
42
+ "set title \" Number of analysed functions per second.\" \n "
43
+ "set terminal svg font 'Liberation,10' size 550,480\n "
44
+ "set output './" + os .path .splitext (os .path .basename (plot_file_name ))[0 ] + ".svg'\n "
45
+ "set xtic rotate\n "
46
+ "set ytic auto\n "
47
+ "set xlabel \" Time (sec)\" \n "
48
+ "set ylabel \" Speed (funcs/sec)\" \n "
49
+ "set grid\n "
50
+ "set style data lines\n "
51
+ "unset key\n "
52
+ "plot \" ./" + os .path .basename (data_file_name ) + "\" using 1:4 lt -1 lw 2\n "
53
+ )
57
54
58
55
59
56
def build_locations_speed_plot_file (plot_file_name ,data_file_name ):
60
- file = open (plot_file_name ,"w" )
61
- file .write (
62
- "set title \" Number of analysed lines per second.\" \n "
63
- "set terminal svg font 'Liberation,10' size 550,480\n "
64
- "set output './" + os .path .splitext (os .path .basename (plot_file_name ))[0 ] + ".svg'\n "
65
- "set xtic rotate\n "
66
- "set ytic auto\n "
67
- "set xlabel \" Time (sec)\" \n "
68
- "set ylabel \" Speed (lines/sec)\" \n "
69
- "set style data lines\n "
70
- "set grid\n "
71
- "unset key\n "
72
- "plot \" ./" + os .path .basename (data_file_name ) + "\" using 1:5 lt -1 lw 2\n "
73
- )
74
- file .close ()
57
+ with open (plot_file_name ,"w" ) as file :
58
+ file .write (
59
+ "set title \" Number of analysed lines per second.\" \n "
60
+ "set terminal svg font 'Liberation,10' size 550,480\n "
61
+ "set output './" + os .path .splitext (os .path .basename (plot_file_name ))[0 ] + ".svg'\n "
62
+ "set xtic rotate\n "
63
+ "set ytic auto\n "
64
+ "set xlabel \" Time (sec)\" \n "
65
+ "set ylabel \" Speed (lines/sec)\" \n "
66
+ "set style data lines\n "
67
+ "set grid\n "
68
+ "unset key\n "
69
+ "plot \" ./" + os .path .basename (data_file_name ) + "\" using 1:5 lt -1 lw 2\n "
70
+ )
75
71
76
72
77
73
def build_functions_progress_plot_file (plot_file_name ,data_file_name ):
78
- file = open (plot_file_name ,"w" )
79
- file .write (
80
- "set title \" Number of analysed functions in time.\" \n "
81
- "set terminal svg font 'Liberation,10' size 550,480\n "
82
- "set output './" + os .path .splitext (os .path .basename (plot_file_name ))[0 ] + ".svg'\n "
83
- "set xtic rotate\n "
84
- "set ytic auto\n "
85
- "set xlabel \" Time (sec)\" \n "
86
- "set ylabel \" Functions (#)\" \n "
87
- "set style data lines\n "
88
- "set grid\n "
89
- "unset key\n "
90
- "plot \" ./" + os .path .basename (data_file_name ) + "\" using 1:2 lt -1 lw 2\n "
91
- )
92
- file .close ()
93
-
74
+ with open (plot_file_name ,"w" ) as file :
75
+ file .write (
76
+ "set title \" Number of analysed functions in time.\" \n "
77
+ "set terminal svg font 'Liberation,10' size 550,480\n "
78
+ "set output './" + os .path .splitext (os .path .basename (plot_file_name ))[0 ] + ".svg'\n "
79
+ "set xtic rotate\n "
80
+ "set ytic auto\n "
81
+ "set xlabel \" Time (sec)\" \n "
82
+ "set ylabel \" Functions (#)\" \n "
83
+ "set style data lines\n "
84
+ "set grid\n "
85
+ "unset key\n "
86
+ "plot \" ./" + os .path .basename (data_file_name ) + "\" using 1:2 lt -1 lw 2\n "
87
+ )
88
+
94
89
95
90
def build_locations_progress_plot_file (plot_file_name ,data_file_name ):
96
- file = open (plot_file_name ,"w" )
97
- file .write (
98
- "set title \" Number of analysed lines in time.\" \n "
99
- "set terminal svg font 'Liberation,10' size 550,480\n "
100
- "set output './" + os .path .splitext (os .path .basename (plot_file_name ))[0 ] + ".svg'\n "
101
- "set xtic rotate\n "
102
- "set ytic auto\n "
103
- "set xlabel \" Time (sec)\" \n "
104
- "set ylabel \" Lines (#)\" \n "
105
- "set style data lines\n "
106
- "set grid\n "
107
- "unset key\n "
108
- "plot \" ./" + os .path .basename (data_file_name ) + "\" using 1:3 lt -1 lw 2\n "
109
- )
110
- file .close ()
91
+ with open (plot_file_name ,"w" ) as file :
92
+ file .write (
93
+ "set title \" Number of analysed lines in time.\" \n "
94
+ "set terminal svg font 'Liberation,10' size 550,480\n "
95
+ "set output './" + os .path .splitext (os .path .basename (plot_file_name ))[0 ] + ".svg'\n "
96
+ "set xtic rotate\n "
97
+ "set ytic auto\n "
98
+ "set xlabel \" Time (sec)\" \n "
99
+ "set ylabel \" Lines (#)\" \n "
100
+ "set style data lines\n "
101
+ "set grid\n "
102
+ "unset key\n "
103
+ "plot \" ./" + os .path .basename (data_file_name ) + "\" using 1:3 lt -1 lw 2\n "
104
+ )
111
105
112
106
113
107
def build_general_stats_text_file (stats ,output_file_path_name ):
@@ -122,19 +116,18 @@ def build_general_stats_text_file(stats,output_file_path_name):
122
116
num_files = len (stats ["table-files" ])
123
117
program_building_duration = stats ["table-phases" ]["goto-program-building" ]
124
118
125
- file = open (output_file_path_name ,"w" )
126
- file .write ("number of files = " + str (num_files ) + "\n " )
127
- file .write ("number of functions = " + str (num_functions ) + "\n " )
128
- file .write ("number of locations = " + str (num_locations ) + "\n " )
129
- file .write ("program parsing duration = " + str (program_building_duration ) + "\n " )
130
- if num_files > 0 : file .write ("average parsing duration per file = " + str (program_building_duration / num_files ) + "\n " )
131
- if num_functions > 0 : file .write ("average parsing duration per function = " + str (program_building_duration / num_functions ) + "\n " )
132
- if num_locations > 0 : file .write ("average parsing duration per location = " + str (program_building_duration / num_locations ) + "\n " )
133
- file .write ("analysis duration = " + str (analysis_duration ) + "\n " )
134
- if num_files > 0 : file .write ("average analysis duration per file = " + str (analysis_duration / num_files ) + "\n " )
135
- if num_functions > 0 : file .write ("average analysis duration per function = " + str (analysis_duration / num_functions ) + "\n " )
136
- if num_locations > 0 : file .write ("average analysis duration per location = " + str (analysis_duration / num_locations ) + "\n " )
137
- file .close ()
119
+ with open (output_file_path_name ,"w" ) as file :
120
+ file .write ("number of files = " + str (num_files ) + "\n " )
121
+ file .write ("number of functions = " + str (num_functions ) + "\n " )
122
+ file .write ("number of locations = " + str (num_locations ) + "\n " )
123
+ file .write ("program parsing duration = " + str (program_building_duration ) + "\n " )
124
+ if num_files > 0 : file .write ("average parsing duration per file = " + str (program_building_duration / num_files ) + "\n " )
125
+ if num_functions > 0 : file .write ("average parsing duration per function = " + str (program_building_duration / num_functions ) + "\n " )
126
+ if num_locations > 0 : file .write ("average parsing duration per location = " + str (program_building_duration / num_locations ) + "\n " )
127
+ file .write ("analysis duration = " + str (analysis_duration ) + "\n " )
128
+ if num_files > 0 : file .write ("average analysis duration per file = " + str (analysis_duration / num_files ) + "\n " )
129
+ if num_functions > 0 : file .write ("average analysis duration per function = " + str (analysis_duration / num_functions ) + "\n " )
130
+ if num_locations > 0 : file .write ("average analysis duration per location = " + str (analysis_duration / num_locations ) + "\n " )
138
131
139
132
140
133
def make_plots (input_json ,output_dir ,do_build_svg ):
0 commit comments