forked from labri-progress/api-evolution-data-corpus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbenchmark.sh
executable file
·177 lines (138 loc) · 5.23 KB
/
benchmark.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
#!/bin/bash
DATASETS_DIR="datasets"
RESULTS_DIR="results"
BUILD_SCRIPT="build.sh"
GROUND_TRUTH_SCRIPT="ground_truth.sh"
GROUND_TRUTH_CSV_FILE="ground_truth.csv"
BENCHMARK_CSV_FILE="benchmark.csv"
PRECISIONS_CSV_FILE="precisions.csv"
RECALLS_CSV_FILE="recalls.csv"
## return "1" if incompatibility was detected in the row
## detected incompatibility is found by grep pattern matching
function incompatibilityDetected() {
if grep -q "$2" "$1" ; then echo 1
else echo 0 ; fi
}
# Check necessary tools are installed
tools=("ant" "mvn" "pip3" "python3")
for tool in "${tools[@]}"; do
if ! command -v "$tool" &> /dev/null; then
echo "$tool is not installed. Please install it."
exit 1
fi
done
pip3 install -r requirements.txt
[ -d "$RESULTS_DIR" ] || mkdir "$RESULTS_DIR"
for bench_dir in "$DATASETS_DIR"/* ; do
bench_name="${bench_dir##*/}"
if [ "$bench_name" == "japicmp" ] || [ "$bench_name" == "revapi" ] || [ "$bench_name" == "jezek_dietrich" ] ; then
continue
fi
echo "Current Benchmark: $bench_name"
cd "$bench_dir" || return
echo "Running build script..."
sh "$BUILD_SCRIPT"
echo "Running ground truth script..."
sh "$GROUND_TRUTH_SCRIPT"
cd ../..
bench_results_dir="$RESULTS_DIR/$bench_name"
dataset_dir="$DATASETS_DIR/$bench_name"
echo "Running tools..."
sh tools/run.sh "$dataset_dir" "$bench_results_dir"
echo "Analyzing results..."
tool_reports=()
for d in "$bench_results_dir/reports"/* ; do
filename=$(basename "$d")
tool_reports+=("$filename")
done
ground_truth_csv_path="$dataset_dir/output/$GROUND_TRUTH_CSV_FILE"
benchmark_csv_path="$bench_results_dir/$BENCHMARK_CSV_FILE"
echo "change,source,binary" > "$benchmark_csv_path"
cp "$ground_truth_csv_path" "$benchmark_csv_path"
# Read the benchmark CSV file
source_array=()
binary_array=()
while IFS=, read -r change source binary; do
if [ "$change" = "change" ]; then
continue
fi
source_array+=("$source")
binary_array+=("$binary")
done < "$benchmark_csv_path"
# Calculating the number of BCs (allRelevant)
breaking_array=()
allRelevant=0
for ((i = 0; i < ${#source_array[@]}; i++)); do
# A change is breaking if source == 0 or binary == 0
if [ "${source_array[i]}" = "0" ] || [ "${binary_array[i]}" = "0" ]; then
breaking_array+=("0")
allRelevant=$((allRelevant + 1))
else
breaking_array+=("1")
fi
done
echo "Number of breaking changes: $allRelevant"
# Compute stats for each tool
benchmark_tmp_csv_path="$bench_results_dir/$BENCHMARK_CSV_FILE.tmp"
precisionsArray=()
recallsArray=()
for filename in "${tool_reports[@]}"; do
rm -f "$benchmark_tmp_csv_path"
report_path="$bench_results_dir/reports/$filename"
toolName=$(echo "$filename" | cut -f 1 -d '.')
allRetrieved=0
relevantRetrieved=0
index=0
toolValues=()
while read -r line; do
change=$(echo "$line" | cut -d, -f1)
if [ "$change" = "change" ]; then
value="$toolName"
else
value=$(incompatibilityDetected "$report_path" "$change")
allRetrieved=$((allRetrieved + value))
toolValues+=("$value")
if [ "${binary_array[index]}" -eq 0 ] || [ "${source_array[index]}" -eq 0 ]; then
relevantRetrieved=$((relevantRetrieved + value))
fi
index=$((index + 1))
fi
echo "${line},${value}" >> "$benchmark_tmp_csv_path"
done < "$benchmark_csv_path"
if [ "$allRetrieved" -ne 0 ]; then
precision=$(echo "scale=4; $relevantRetrieved / $allRetrieved * 100 " | bc)
else
precision=0.00
fi
if [ "$allRelevant" -ne 0 ]; then
recall=$(echo "scale=4; $relevantRetrieved / $allRelevant * 100 " | bc)
else
recall=0.00
fi
echo "Precision for $toolName: $precision"
echo "Recall for $toolName: $recall"
recallsArray+=("$recall")
precisionsArray+=("$precision")
cp "$benchmark_tmp_csv_path" "$benchmark_csv_path"
done
precisionsArrayLine="Precision,,"
for precision in "${precisionsArray[@]}"; do
precisionsArrayLine+=",$precision"
done
echo "$precisionsArrayLine" >> "$benchmark_csv_path"
recallsArrayLine="Recall,,"
for recall in "${recallsArray[@]}"; do
recallsArrayLine+=",$recall"
done
echo "$recallsArrayLine" >> "$benchmark_csv_path"
# Clean up
rm "$benchmark_tmp_csv_path"
# Save the precisions and recalls arrays to separate CSV files
precisions_csv_path="$bench_results_dir/$PRECISIONS_CSV_FILE"
recalls_csv_path="$bench_results_dir/$RECALLS_CSV_FILE"
echo "tool,precision" > "$precisions_csv_path"
paste -d ',' <(printf "%s\n" "${tool_reports[@]}") <(printf "%s\n" "${precisionsArray[@]}") >> "$precisions_csv_path"
echo "tool,recall" > "$recalls_csv_path"
paste -d ',' <(printf "%s\n" "${tool_reports[@]}") <(printf "%s\n" "${recallsArray[@]}") >> "$recalls_csv_path"
python3 plot.py "$bench_results_dir"
done