Skip to content

Commit 97fe79c

Browse files
committed
Updates requested in PR diffblue#50: using start_time instead of prof = { "duration": time.time() }.
1 parent 2103e2a commit 97fe79c

File tree

3 files changed

+46
-30
lines changed

3 files changed

+46
-30
lines changed

security-scanner/analyser.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ def run_security_analyser(
3838
results_dir,
3939
temp_root_dir
4040
):
41-
prof = { "duration": time.time() }
41+
prof = {}
42+
prof_start_time = time.time()
43+
4244
if not os.path.exists(results_dir):
4345
os.makedirs(results_dir)
4446

@@ -93,15 +95,16 @@ def run_security_analyser(
9395
+ "'./" + os.path.relpath(root_jar,results_dir) + "' "
9496
"--security-scanner '" + os.path.relpath(root_config_json_fname,results_dir) + "' "
9597
)
96-
prof["calling_goto_analyser"] = { "duration": time.time() }
98+
prof["calling_goto_analyser"] = {}
99+
prof_calling_goto_analyser_start_time = time.time()
97100
print("Invoking 'security-analyser' ...")
98101
if verbosity >= 9:
99102
print("CWD: " + results_dir)
100103
print("CMD: " + command)
101104
os.system(command)
102-
prof["calling_goto_analyser"]["duration"] = time.time() - prof["calling_goto_analyser"]["duration"]
105+
prof["calling_goto_analyser"]["duration"] = time.time() - prof_calling_goto_analyser_start_time
103106
os.chdir(old_cwd)
104-
prof["duration"] = time.time() - prof["duration"]
107+
prof["duration"] = time.time() - prof_start_time
105108

106109
return prof
107110

@@ -112,13 +115,14 @@ def run_program_slicing(
112115
timeout,
113116
verbosity
114117
):
115-
prof = { "duration": time.time() }
118+
prof = {}
119+
prof_start_time = time.time()
116120

117121
# TODO: once the slicer in "goto-instrument" tool is available, then provide proper implementation here!
118122
# Until then we assume the slicing removes nothing from the instrumented program.
119123
shutil.copyfile(json_cfg_fname, os.path.join(os.path.dirname(json_cfg_fname),"sliced_goto_programs.json"))
120124

121-
prof["duration"] = time.time() - prof["duration"]
125+
prof["duration"] = time.time() - prof_start_time
122126
return prof
123127

124128

@@ -157,7 +161,8 @@ def run_search_for_error_traces(
157161
timeout,
158162
verbosity
159163
):
160-
prof = { "duration": time.time() }
164+
prof = {}
165+
prof_start_time = time.time()
161166
if not os.path.exists(results_dir):
162167
os.makedirs(results_dir)
163168

@@ -176,13 +181,14 @@ def run_search_for_error_traces(
176181
"--verbosity " + str(1) + " "
177182
"> \"cbmc_results.json\""
178183
)
179-
prof["calling_cbmc"] = { "duration": time.time() }
184+
prof["calling_cbmc"] = {}
185+
prof_calling_cbmc_start_time = time.time()
180186
print("Invoking 'cbmc' ...")
181187
if verbosity >= 9:
182188
print("CWD: " + results_dir)
183189
print("CMD: " + command)
184190
os.system(command)
185-
prof["calling_cbmc"]["duration"] = time.time() - prof["calling_cbmc"]["duration"]
191+
prof["calling_cbmc"]["duration"] = time.time() - prof_calling_cbmc_start_time
186192
os.chdir(old_cwd)
187193

188194
with open(os.path.join(results_dir,"cbmc_results.json")) as data_file:
@@ -203,7 +209,7 @@ def run_search_for_error_traces(
203209
with open(os.path.join(results_dir, "error_traces.json"), "w") as traces_file:
204210
traces_file.write(json.dumps(traces_list, sort_keys=True, indent=4))
205211

206-
prof["duration"] = time.time() - prof["duration"]
212+
prof["duration"] = time.time() - prof_start_time
207213
return prof
208214

209215

security-scanner/mkbench.py

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,18 @@ def __get_my_dir(): return os.path.dirname(os.path.realpath(__file__))
99

1010

1111
def collect_java_files(app_build_dir,extension_text,output_list):
12-
prof = { "duration": time.time() }
12+
prof = {}
13+
prof_start_time = time.time()
1314
for root, dirnames, filenames in os.walk(app_build_dir):
1415
for filename in fnmatch.filter(filenames, "*." + extension_text):
1516
output_list.append(os.path.abspath(os.path.join(root,filename)))
16-
prof["duration"] = time.time() - prof["duration"]
17+
prof["duration"] = time.time() - prof_start_time
1718
return prof
1819

1920

2021
def unpack_java_package(pathname,unpack_dir):
21-
prof = { "duration": time.time() }
22+
prof = {}
23+
prof_start_time = time.time()
2224
if not os.path.exists(unpack_dir):
2325
os.makedirs(unpack_dir)
2426
old_cwd = os.getcwd()
@@ -29,12 +31,13 @@ def unpack_java_package(pathname,unpack_dir):
2931
pathname
3032
)
3133
os.chdir(old_cwd)
32-
prof["duration"] = time.time() - prof["duration"]
34+
prof["duration"] = time.time() - prof_start_time
3335
return prof
3436

3537

3638
def pack_classes_to_jar(classes_dir,dst_file):
37-
prof = { "duration": time.time() }
39+
prof = {}
40+
prof_start_time = time.time()
3841
if not os.path.exists(os.path.dirname(dst_file)):
3942
os.makedirs(os.path.dirname(dst_file))
4043
old_cwd = os.getcwd()
@@ -44,7 +47,7 @@ def pack_classes_to_jar(classes_dir,dst_file):
4447
+ dst_file + "\" ."
4548
)
4649
os.chdir(old_cwd)
47-
prof["duration"] = time.time() - prof["duration"]
50+
prof["duration"] = time.time() - prof_start_time
4851
return prof
4952

5053

@@ -100,11 +103,13 @@ def is_class_modeled(pathname):
100103

101104

102105
def install_class_file(pathname,output_dir,class_temp_dir):
103-
prof = { "duration": time.time() }
106+
prof = {}
107+
prof_start_time = time.time()
104108
print(" " + pathname)
105-
prof["fullname"] = { "duration": time.time() }
109+
prof["fullname"] = {}
110+
prof_fullname_start_time = time.time()
106111
packages_classname = compute_fullname_of_class(pathname,class_temp_dir)
107-
prof["fullname"]["duration"] = time.time() - prof["fullname"]["duration"]
112+
prof["fullname"]["duration"] = time.time() - prof_fullname_start_time
108113
if packages_classname is None:
109114
print("FAIL: Cannot read full class name (including packages) of the class file: " + pathname)
110115
prof["duration"] = time.time() - prof["duration"]
@@ -120,12 +125,13 @@ def install_class_file(pathname,output_dir,class_temp_dir):
120125
else:
121126
shutil.copyfile(pathname,class_pathname)
122127

123-
prof["duration"] = time.time() - prof["duration"]
128+
prof["duration"] = time.time() - prof_start_time
124129
return prof
125130

126131

127132
def install_jar_file(pathname,output_dir,temp_dir,class_temp_dir):
128-
prof = { "duration": time.time() }
133+
prof = {}
134+
prof_start_time = time.time()
129135

130136
prof["unpack"] = unpack_java_package(pathname,temp_dir)
131137

@@ -140,12 +146,13 @@ def install_jar_file(pathname,output_dir,temp_dir,class_temp_dir):
140146
prof["install"]["duration"] += prof_install["duration"]
141147
prof["install"]["fullname"]["duration"] += prof_install["fullname"]["duration"]
142148

143-
prof["duration"] = time.time() - prof["duration"]
149+
prof["duration"] = time.time() - prof_start_time
144150
return prof
145151

146152

147153
def install_war_file(pathname,output_dir,temp_dir,class_temp_dir):
148-
prof = { "duration": time.time() }
154+
prof = {}
155+
prof_start_time = time.time()
149156

150157
war_temp_dir = os.path.join(temp_dir,"WAR")
151158
prof["unpack"] = unpack_java_package(pathname,war_temp_dir)
@@ -176,12 +183,13 @@ def install_war_file(pathname,output_dir,temp_dir,class_temp_dir):
176183
prof["install"]["duration"] += prof_install["install"]["duration"]
177184
prof["install"]["fullname"]["duration"] += prof_install["install"]["fullname"]["duration"]
178185

179-
prof["duration"] = time.time() - prof["duration"]
186+
prof["duration"] = time.time() - prof_start_time
180187
return prof
181188

182189

183190
def build_classes_configuration(app_binary_dir,output_dir,temp_dir):
184-
prof = { "duration": time.time() }
191+
prof = {}
192+
prof_start_time = time.time()
185193

186194
prof["unpack"] = {"duration": 0.0}
187195
prof["collect"] = {"duration": 0.0}
@@ -229,5 +237,5 @@ def build_classes_configuration(app_binary_dir,output_dir,temp_dir):
229237
prof["install"]["duration"] += prof_install["install"]["duration"]
230238
prof["install"]["fullname"]["duration"] += prof_install["install"]["fullname"]["duration"]
231239

232-
prof["duration"] = time.time() - prof["duration"]
240+
prof["duration"] = time.time() - prof_start_time
233241
return prof

security-scanner/run.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ def __parse_cmd_line():
6363
def evaluate(cmdline):
6464
print("Starting analysis of Java web application '" + cmdline.name + "'.")
6565

66-
prof = { "duration": time.time(), "analysis_per_root_fn": [], "benchmark_name": cmdline.name }
66+
prof = { "analysis_per_root_fn": [], "benchmark_name": cmdline.name }
67+
prof_start_time = time.time()
6768

6869
if cmdline.rebuild:
6970
print("First performing cleanup.")
@@ -117,7 +118,8 @@ def evaluate(cmdline):
117118
)
118119

119120
print("Building performance plots.")
120-
prof_plots = {"duration": time.time()}
121+
prof_plots = {}
122+
prof_plots_start_time = time.time()
121123

122124
stats_json_fname = os.path.abspath(os.path.join(cmdline.results_dir,"statistics/JSON/statistics.json"))
123125
stats_plots_dir = os.path.abspath(os.path.join(cmdline.results_dir,"statistics/plots"))
@@ -127,13 +129,13 @@ def evaluate(cmdline):
127129

128130
mkplot.make_plots(stats_json_fname,stats_plots_dir,True)
129131

130-
prof_plots["duration"] = time.time() - prof_plots["duration"]
132+
prof_plots["duration"] = time.time() - prof_plots_start_time
131133
prof["plots_build"] = prof_plots
132134

133135
overall_perf_fname = os.path.abspath(os.path.join(cmdline.results_dir,"overall_performance.json"))
134136
print("Saving performance data in JSON format to: " + overall_perf_fname)
135137

136-
prof["duration"] = time.time() - prof["duration"]
138+
prof["duration"] = time.time() - prof_start_time
137139

138140
with open(overall_perf_fname,"w") as overall_perf_file:
139141
overall_perf_file.write(json.dumps(prof,sort_keys=True,indent=4))

0 commit comments

Comments
 (0)