Skip to content

Commit 5d072d5

Browse files
committed
Times and space usage improvement
1 parent 8c301fe commit 5d072d5

File tree

1 file changed

+39
-2
lines changed

1 file changed

+39
-2
lines changed

src/uniandes/tsdl/mutapk/processors/MutationsProcessor.java

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,14 @@ public void process(List<MutationLocation> locations, String extraPath, String a
5050
String newMutationPath = null;
5151
BufferedWriter writer = new BufferedWriter(
5252
new FileWriter(getMutantsRootFolder() + File.separator + getAppName() + "-mutants.log"));
53+
BufferedWriter wwriter = new BufferedWriter(
54+
new FileWriter(getMutantsRootFolder() + File.separator + getAppName() + "-times.csv"));
55+
wwriter.write("mutantIndex;mutantType;mutationTime;buildingTime");
56+
wwriter.newLine();
57+
wwriter.flush();
5358
for (MutationLocation mutationLocation : locations) {
5459
try {
60+
Long mutationIni = System.currentTimeMillis();
5561
setupMutantFolder(mutantIndex);
5662
System.out.println("Mutant: " + mutantIndex + " - Type: " + mutationLocation.getType());
5763
operator = factory.getOperator(mutationLocation.getType().getId());
@@ -64,9 +70,20 @@ public void process(List<MutationLocation> locations, String extraPath, String a
6470
// System.out.println(newMutationPath);
6571
mutationLocation.setFilePath(newMutationPath);
6672
operator.performMutation(mutationLocation, writer, mutantIndex);
67-
73+
Long mutationEnd = System.currentTimeMillis();
6874
APKToolWrapper.buildAPK(mutantRootFolder, extraPath, apkName, mutantIndex);
69-
75+
File mutatedFile = new File(newMutationPath);
76+
String fileName = (new File(newMutationPath)).getName();
77+
File mutantRootFolderDir = new File(mutantRootFolder+fileName);
78+
FileUtils.copyFile(mutatedFile, mutantRootFolderDir);
79+
File srcFolder = new File(mutantFolder);
80+
FileUtils.deleteDirectory(srcFolder);
81+
Long buildEnd = System.currentTimeMillis();
82+
Long mutationTime = mutationEnd-mutationIni;
83+
Long buildingTime = buildEnd - mutationEnd;
84+
wwriter.write(mutantIndex+";"+mutationLocation.getType().getId()+";"+mutationTime+";"+buildingTime);
85+
wwriter.newLine();
86+
wwriter.flush();
7087
} catch (Exception e) {
7188
Logger.getLogger(MutationsProcessor.class.getName())
7289
.warning("- Error generating mutant " + mutantIndex);
@@ -75,13 +92,19 @@ public void process(List<MutationLocation> locations, String extraPath, String a
7592
mutantIndex++;
7693
}
7794
writer.close();
95+
wwriter.close();
7896
}
7997

8098
public void processMultithreaded(List<MutationLocation> locations, final String extraPath, final String apkName)
8199
throws IOException {
82100

83101
final BufferedWriter writer = new BufferedWriter(
84102
new FileWriter(getMutantsRootFolder() + File.separator + getAppName() + "-mutants.log"));
103+
final BufferedWriter wwriter = new BufferedWriter(
104+
new FileWriter(getMutantsRootFolder() + File.separator + getAppName() + "-times.csv"));
105+
wwriter.write("mutantIndex;mutantType;copyingTime;mutationTime;buildingTime");
106+
wwriter.newLine();
107+
wwriter.flush();
85108
final ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors());
86109
final List<Future<String>> results = new LinkedList<Future<String>>();
87110

@@ -91,13 +114,20 @@ public void processMultithreaded(List<MutationLocation> locations, final String
91114
for (final MutationLocation mutationLocation : locations) {
92115
mutantIndex++;
93116
final int currentMutationIndex = mutantIndex;
117+
Long copyingIni = System.currentTimeMillis();
94118
System.out.println("Mutant: " + currentMutationIndex + " - " + mutationLocation.getType().getName());
95119
setupMutantFolder(currentMutationIndex);
120+
Long copyingEnd = System.currentTimeMillis();
121+
Long copyingTime = copyingEnd - copyingIni;
122+
wwriter.write(currentMutationIndex+";"+mutationLocation.getType().getId()+";"+copyingTime+";0;0");
123+
wwriter.newLine();
124+
wwriter.flush();
96125
results.add(executor.submit(new Callable<String>() {
97126

98127
public String call() {
99128
try {
100129
// Select operator
130+
Long mutationIni = System.currentTimeMillis();
101131
MutationOperatorFactory factory = MutationOperatorFactory.getInstance();
102132
MutationOperator operator = factory.getOperator(mutationLocation.getType().getId());
103133

@@ -110,7 +140,14 @@ public String call() {
110140

111141
// Perform mutation
112142
operator.performMutation(mutationLocation, writer, currentMutationIndex);
143+
Long mutationEnd = System.currentTimeMillis();
113144
APKToolWrapper.buildAPK(mutantRootFolder, extraPath, apkName, currentMutationIndex);
145+
Long buildEnd = System.currentTimeMillis();
146+
Long mutationTime = mutationEnd-mutationIni;
147+
Long buildingTime = buildEnd - mutationEnd;
148+
wwriter.write(currentMutationIndex+";"+mutationLocation.getType().getId()+";0;"+mutationTime+";"+buildingTime);
149+
wwriter.newLine();
150+
wwriter.flush();
114151
// writer.close();
115152

116153
} catch (Exception e) {

0 commit comments

Comments
 (0)