-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEvaluationRunner.java
More file actions
167 lines (150 loc) · 7.86 KB
/
Copy pathEvaluationRunner.java
File metadata and controls
167 lines (150 loc) · 7.86 KB
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
import java.io.*;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.*;
import java.util.stream.Collectors;
public class EvaluationRunner {
// private static final String INPUT_DIR = Paths.get("IDELinearConstantAnalysisClientSoot/src/test/resources/latest").toString();
// private static final String EXECUTABLE = Paths.get("eval_results/IDELinearConstantAnalysisClientSoot-1.0-SNAPSHOT-jar-with-dependencies.jar").toString();
private static final String INPUT_DIR = Paths.get("IDELinearConstantAnalysisClientSootUp/src/test/resources/latest").toString();
private static final String EXECUTABLE = Paths.get("eval_results/IDELinearConstantAnalysisClientSootUp-1.0-SNAPSHOT-jar-with-dependencies.jar").toString();
private static final String MAX_METHOD = "50";
private static final List<String> THREADS = List.of("1");
private static final List<String> SOLVERS = List.of("default");
private static final List<String> MANDATORY_BODY_INTERCEPTORS = List.of("jb.ls", "jb.tr");
private static final List<String> ALLOWED_CONFIGURATIONS = List.of("CHA", "RTA");
private static List<String> bodyInterceptors = new ArrayList<>();
private static List<String> specificCGAlgo = null;
private static int numberOfIterations;
public static File outputFile = new File("console_output.txt");
public static void main(String[] args) throws InterruptedException, FileNotFoundException {
Scanner scanner = new Scanner(System.in);
System.out.println("Execute all files in the directory? (y/n): ");
boolean executeAll = scanner.nextLine().equalsIgnoreCase("y");
List<String> selectedFiles;
if (executeAll) {
selectedFiles = setup();
} else {
selectedFiles = selectFiles();
}
System.out.println("Enter the number of iterations of the experiment: ");
numberOfIterations = Integer.parseInt(scanner.nextLine());
System.out.println("Do you need to use any specific CG Algorithm? (y/n): ");
if (scanner.nextLine().equalsIgnoreCase("y")) {
System.out.println("Do you need to use all the allowed configurations? (y/n): ");
if (scanner.nextLine().equalsIgnoreCase("y")) {
specificCGAlgo = new ArrayList<>(ALLOWED_CONFIGURATIONS);
} else {
System.out.println("Enter the specific CG algorithms you want to use (comma-separated): ");
specificCGAlgo = Arrays.stream(scanner.nextLine().split(","))
.map(String::trim)
.collect(Collectors.toList());
}
} else {
specificCGAlgo = new ArrayList<>(ALLOWED_CONFIGURATIONS);
}
bodyInterceptors = generatePermutations();
bodyInterceptors = List.of(bodyInterceptors.get(0));
System.out.println("Total permutations: " + bodyInterceptors.size());
ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
for (String file : selectedFiles) {
List<Future<?>> futures = new ArrayList<>();
futures.add(executor.submit(() -> {
try {
runEvaluation(file);
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}));
for (Future<?> future : futures) {
try {
future.get(20, TimeUnit.MINUTES);
} catch (TimeoutException e) {
System.out.println("Task exceeded 20 minutes and was skipped.");
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
}
}
executor.shutdown();
}
private static List<String> setup() {
File inputDir = new File(INPUT_DIR);
return Arrays.stream(inputDir.listFiles())
.filter(file -> file.getName().endsWith(".jar") && file.isFile())
.map(File::getName)
.sorted()
.collect(Collectors.toList());
}
private static List<String> selectFiles() {
Scanner scanner = new Scanner(System.in);
File inputDir = new File(INPUT_DIR);
List<File> files = Arrays.asList(Objects.requireNonNull(inputDir.listFiles()));
for (int i = 0; i < files.size(); i++) {
System.out.println((i + 1) + ". " + files.get(i).getName());
}
System.out.println("Enter the numbers of the files to execute (comma-separated): ");
return Arrays.stream(scanner.nextLine().split(","))
.map(num -> files.get(Integer.parseInt(num.trim()) - 1).getName())
.collect(Collectors.toList());
}
private static List<String> generatePermutations() {
List<String> fixedItems = new ArrayList<>(List.of("jb.ls,jb.tr", "jb.lp,jb.ule", "jb.cp", "jb.dae", "jb.ese", "jb.a", "jb.cbf"));
List<String> permutations = new ArrayList<>();
permute(fixedItems, 0, permutations);
return permutations;
}
private static void permute(List<String> arr, int index, List<String> results) {
if (index >= arr.size() - 1) {
results.add(String.join(",", arr));
return;
}
for (int i = index; i < arr.size(); i++) {
Collections.swap(arr, index, i);
permute(arr, index + 1, results);
Collections.swap(arr, index, i);
}
}
private static void runEvaluation(String jar) throws FileNotFoundException {
// Define the output file for console logs
PrintStream fileOut = new PrintStream(outputFile);
PrintWriter writer = new PrintWriter(outputFile);
// System.setOut(fileOut);
for (String t : THREADS) {
for (String s : SOLVERS) {
for (int i = 0; i < numberOfIterations; i++) {
for (String cgAlgo : specificCGAlgo) {
for (String appliedBodyInterceptor : bodyInterceptors) {
String[] command = constructCommand(jar, s, cgAlgo, t, appliedBodyInterceptor);
try {
System.out.println("Running: " + String.join(" ", command));
ProcessBuilder processBuilder = new ProcessBuilder(command);
// Append output to the file instead of overwriting
processBuilder.redirectOutput(ProcessBuilder.Redirect.appendTo(outputFile));
processBuilder.redirectError(ProcessBuilder.Redirect.appendTo(outputFile));
// processBuilder.inheritIO();
Process process = processBuilder.start();
if (!process.waitFor(20, TimeUnit.MINUTES)) {
System.out.println("Execution timed out for command: " + String.join(" ", command));
process.destroyForcibly();
}
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
}
}
private static String[] constructCommand(String jar, String solver, String cgAlgo, String thread, String bodyInterceptors) {
// return new String[]{
// "java", "-XX:+UseG1GC", "-XX:+UseAdaptiveSizePolicy", "-Xmx1024m", "-Xss1024m", "-jar",
// EXECUTABLE, jar, solver, MAX_METHOD, cgAlgo, thread, bodyInterceptors
// };
return new String[]{
"java", "-XX:+UseG1GC", "-XX:+UseAdaptiveSizePolicy", "-Xmx1024m", "-Xss1024m", "-jar",
EXECUTABLE, jar, solver, MAX_METHOD, cgAlgo, thread
};
}
}