17 def load(self, bench_filename):
22 filtered_input_data = filter(
23 lambda experiment: experiment[
"succeeded"]
is True,
29 key=
lambda experiment: experiment[
"results"][
"query_id"],
34 return self.
data[0][
"results"][attribute]
50 for query
in query_names:
51 for experiment
in self.
data:
52 assert attribute
in experiment[
"results"], (
53 attribute +
" is not a valid attribute."
55 if query == experiment[
"results"][
"query_id"]:
56 result.append(experiment[
"results"][attribute])
62 for experiment
in self.
data:
63 result.append(experiment[
"results"][
"query_id"])
69 assert isinstance(ref, BenchmarkLoader)
70 assert isinstance(sample, BenchmarkLoader)
89 self.__missing_queries_sample.append(query)
90 self.__label_name_ref.remove(query)
93 self.__missing_queries_ref.append(query)
94 self.__label_name_sample.remove(query)
98 print(
" " + h, end=
"")
105 print(
"Differences outside of %2.0f%%: " % (epsilon * 100), end=
"")
107 for i
in range(len(speedup)):
108 if abs(speedup[i] - 1.0) > epsilon:
112 "\n%s: reference = %.2f ms, sample = %.2f ms, speedup = %.2fx"
122 print(
": None", end=
"")
124 print(
"\n*** Missing queries from reference: ", end=
"")
126 print(query +
" ", end=
"")
128 print(
"\n*** Missing queries from sample: ", end=
"")
130 print(query +
" ", end=
"")
132 "\n======================================================================="
138 zipped = list(zip(x, y))
140 result.append(q[0] / q[1])
146 This class is just used to print out the benchmark results into the terminal.
147 By default, it is used for cross comparison of the results between a reference
148 branch (ref) and a sample branch (sample); for a particular attribute, all elements
149 within each branch are shown as well as the speedup (sample / ref).
151 If cross_comparison is disabled, then it just shows the result for the ref branch.
159 cross_comparison=
True,
160 num_items_per_line=5,
163 assert isinstance(ref, BenchmarkLoader)
165 assert isinstance(sample, BenchmarkLoader)
167 ref.getRunTableName(),
194 self.__missing_queries_sample.append(query)
195 self.__label_name_ref.remove(query)
198 self.__missing_queries_ref.append(query)
199 self.__label_name_sample.remove(query)
204 print(pattern, end=
"")
219 if isinstance(array[i], float):
220 print(
"%10.2f" % (array[i]), end=
"")
221 elif isinstance(array[i], str):
222 print(
"%10s" % (array[i]), end=
"")
231 print(
"%10s" %
"Queries", end=
"")
234 print(
"%10s" %
"Reference", end=
"")
237 print(
"%10s" %
"Sample", end=
"")
239 print(
"%10s" %
"Speedup", end=
"")
252 opts, args = getopt.getopt(
264 except getopt.GetOptError:
266 "python3 analyze-benchmark.py -s <sample dir> -r <reference dir> -e <epsilon> -a <attribute> -p"
270 dir_artifact_sample =
""
271 dir_artifact_ref =
""
274 "query_exec_trimmed_avg"
279 for opt, arg
in opts:
280 if opt
in (
"-h",
"--help"):
283 -s/--sample:\t\t\t directory of the results for the benchmarked sample branch
284 -r/--reference:\t\t\t directory of the results for the benchmarked reference branch
285 -e/--epsilon:\t\t\t ratio tolerance for reporting results outside this range
286 -a/--attribute:\t\t\t attribute to be used for benchmark comparison (default: query_total_avg)
287 -p/--print:\t\t\t\t print all the results
292 if opt
in (
"-s",
"--sample"):
293 dir_artifact_sample = arg
294 assert os.path.isdir(dir_artifact_sample)
295 elif opt
in (
"-r",
"--reference"):
296 dir_artifact_ref = arg
297 assert os.path.isdir(dir_artifact_ref)
298 elif opt
in (
"-e",
"--epsilon"):
300 elif opt
in (
"-a",
"--attribute"):
301 query_attribute = arg
302 elif opt
in (
"-p",
"--print"):
305 assert dir_artifact_ref !=
""
306 assert dir_artifact_sample !=
""
309 GPU_list_ref = listdir(dir_artifact_ref)
310 GPU_list_sample = listdir(dir_artifact_sample)
312 for gpu
in GPU_list_ref:
313 dir_name_ref = dir_artifact_ref +
"/" + gpu +
"/Benchmarks"
314 filename_list_ref = listdir(dir_name_ref)
319 if gpu
in GPU_list_sample:
320 dir_name_sample = dir_artifact_sample +
"/" + gpu +
"/Benchmarks"
321 filename_list_sample = listdir(dir_name_sample)
322 dir_name_sample +=
"/"
325 dir_name_sample, filename_list_sample
328 for index
in range(len(filename_list_ref)):
329 refBench.load(filename_list_ref[index])
330 if filename_list_ref[index]
in filename_list_sample:
331 sampleBench.load(filename_list_ref[index])
334 "\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
336 print(
"++++ " + sampleBench.getGpuName())
339 + refBench.getFrontAttribute(
"run_label")
341 + refBench.getFrontAttribute(
"run_version")
345 + sampleBench.getFrontAttribute(
"run_label")
347 + sampleBench.getFrontAttribute(
"run_version")
350 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
355 refBench, sampleBench, query_attribute
357 analyzer.findAnomaliesRatio(epsilon)
360 refBench, sampleBench, query_attribute
362 printer.printAttribute()
365 "No sample results for table "
366 + refBench.getRunTableName()
370 "======================================================================="
375 "\n+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
377 print(
"++++ No sample results for GPU " + gpu +
" were found.")
379 "+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n"
383 if __name__ ==
"__main__":
def collectMissingQueries
int open(const char *path, int flags, int mode)
def collectMissingQueries
def getRefElementsPerLine
def getExistingDataRunLabel