Add logs.

This commit is contained in:
Kui LIU
2017-09-14 18:46:49 +02:00
parent a9305fcba1
commit dc12ebec24
6 changed files with 112 additions and 74 deletions
@@ -191,7 +191,7 @@ public class FixedViolationHunkParser extends FixedViolationParser {
if (fixStartLine == 0) {
// pure delete actions.
this.pureDeletions ++;
continue;
// continue;
}
for (HierarchicalActionSet hunkActionSet : hunkActionSets) {
@@ -214,6 +214,7 @@ public class FixedViolationHunkParser extends FixedViolationParser {
}
if (bugEndLine - bugStartLine > Configuration.HUNK_SIZE || fixEndLine - fixStartLine > Configuration.HUNK_SIZE) {
this.largeHunk ++;
log.error("#LargeHunk: " + revFile.getName());
continue;
}
@@ -7,6 +7,9 @@ import java.io.StringReader;
import java.util.ArrayList;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.github.gumtreediff.actions.model.Action;
import edu.lu.uni.serval.FixPatternParser.Parser;
@@ -24,6 +27,8 @@ import edu.lu.uni.serval.utils.ListSorter;
*/
public class FixedViolationParser extends Parser {
private static Logger log = LoggerFactory.getLogger(FixedViolationParser.class);
private File positionFile = null;
protected String alarmTypes = "";
protected List<Violation> uselessViolations;
@@ -50,6 +55,7 @@ public class FixedViolationParser extends Parser {
if (gumTreeResults == null) {
return null;
} else if (gumTreeResults.size() == 0){
log.error("#NoSourceCodeChange: " + revFile.getName());
return actionSets;
} else {
// Regroup GumTre results.
@@ -68,6 +74,10 @@ public class FixedViolationParser extends Parser {
ListSorter<HierarchicalActionSet> sorter = new ListSorter<>(actionSets);
actionSets = sorter.sortAscending();
if (actionSets.size() == 0) {
log.error("#NoStatementChange: " + revFile.getName());
}
return actionSets;
}
}
@@ -44,7 +44,7 @@ public class AkkaParser {
ActorSystem system = null;
ActorRef parsingActor = null;
int numberOfWorkers = 100;
int numberOfWorkers = 200;
final WorkMessage msg = new WorkMessage(0, msgFiles);
try {
log.info("Akka begins...");
@@ -1,7 +1,5 @@
package edu.lu.uni.serval.MultipleThreadsParser;
import static java.lang.System.err;
import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
@@ -78,7 +76,7 @@ public class ParseFixPatternWorker extends UntypedActor {
int testAlarms = 0;
int nullGumTreeResults = 0;
int nullMappingGumTreeResults = 0;
int noSourceCodeChagnes = 0;
int noSourceCodeChanges = 0;
int pureDeletion = 0;
int expNums = 0;
int largeHunk = 0;
@@ -91,6 +89,7 @@ public class ParseFixPatternWorker extends UntypedActor {
File positionFile = msgFile.getPositionFile();
if (revFile.getName().toLowerCase().contains("test")) {
testAlarms += countAlarms(positionFile);
log.error("#TestViolation: " + revFile.getName());
// continue;
}
// Parser parser = null;
@@ -122,8 +121,9 @@ public class ParseFixPatternWorker extends UntypedActor {
if ("".equals(editScript)) {
if (parser.resultType == 1) {
nullGumTreeResults += countAlarms(positionFile);
log.error("#NullGumTreeResult: " + revFile.getName());
} else if (parser.resultType == 2) {
noSourceCodeChagnes += countAlarms(positionFile);
noSourceCodeChanges += countAlarms(positionFile);
}
} else {
editScripts.append(editScript);
@@ -151,15 +151,18 @@ public class ParseFixPatternWorker extends UntypedActor {
}
}
} catch (TimeoutException e) {
err.println("task timed out");
// err.println("task timed out");
future.cancel(true);
expNums += countAlarms(positionFile);
log.error("#Timeout: " + revFile.getName());
} catch (InterruptedException e) {
expNums += countAlarms(positionFile);
err.println("task interrupted");
// err.println("task interrupted");
log.error("#TimeInterrupted: " + revFile.getName());
} catch (ExecutionException e) {
expNums += countAlarms(positionFile);
err.println("task aborted");
// err.println("task aborted");
log.error("#TimeAborted: " + revFile.getName());
} finally {
executor.shutdownNow();
}
@@ -181,7 +184,7 @@ public class ParseFixPatternWorker extends UntypedActor {
testingInfo.setLength(0);
}
String statistic = "testAlarms: " + testAlarms + "\nnullGumTreeResults: " + nullGumTreeResults + "\nnullMappingGumTreeResults: " + nullMappingGumTreeResults +
"\nnoSourceCodeChagnes: " + noSourceCodeChagnes + "\npureDeletion: " + pureDeletion + "\nTimeout: " + expNums +
"\nnoSourceCodeChanges: " + noSourceCodeChanges + "\npureDeletion: " + pureDeletion + "\nTimeout: " + expNums +
"\nlargeHunk: " + largeHunk + "\nnullSourceCode: " + nullSourceCode;
FileHelper.outputToFile("OUTPUT/statistic_" + id + ".list", statistic, false);
@@ -440,7 +440,7 @@ public class HunkActionFilter {
violation.getActionSets().addAll(matchedActionSets);
selectedViolations.add(violation);
} else {
log.warn("#Null-GumTree-Result: " + revFile.getName().replace("#", "/") + " : " +violation.getStartLineNum() + " : " +
log.error("#NullMatchedGumTreeResult: " + revFile.getName().replace("#", "/") + " : " +violation.getStartLineNum() + " : " +
violation.getEndLineNum() + " : " + violation.getAlarmType());
}
}
@@ -1,6 +1,7 @@
package edu.lu.uni.serval.statistics;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -51,66 +52,75 @@ public class Statistic {
statistics("../FPM_Violations/RQ1/distinct-fixed-summary-per-project-vtype.csv", "Fixed");
// fixedVSunfixed();
// String statistic = "../FPM_Violations/OUTPUT";
// List<File> files = FileHelper.getAllFiles(statistic, ".list");
//
// int testAlarms = 0;
// int nullGumTreeResults = 0;
// int nullMappingGumTreeResults = 0;
// int pureDeletion = 0;
// int timeout = 0;
// int noSourceCodeChagnes = 0;
// int largeHunk = 0;
// int nullSourceCode = 0;
// for (File file : files) {
// String content = FileHelper.readFile(file);
// BufferedReader reader = new BufferedReader(new StringReader(content));
// String line = null;
// try {
// while ((line = reader.readLine()) != null) {
// if (line.startsWith("test")) {
// testAlarms += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
// } else if (line.startsWith("nullGum")) {
// nullGumTreeResults += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
// } else if (line.startsWith("nullMap")) {
// nullMappingGumTreeResults += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
// } else if (line.startsWith("pure")) {
// pureDeletion += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
// } else if (line.startsWith("Time")) {
// timeout += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
// } else if (line.startsWith("noSourceCodeChagnes")) {
// noSourceCodeChagnes += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
// } else if (line.startsWith("largeHunk")) {
// largeHunk += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
// } else if (line.startsWith("nullSourceCode")) {
// nullSourceCode += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
// }
// }
// } catch (IOException e) {
// e.printStackTrace();
// } finally {
// try {
// reader.close();
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
// }
//
//// TestAlarms: 5175
//// nullGumTreeResults: 13449
//// nullMappingGumTreeResults: 33010
//// pureDeletion: 7598
//// Timeout: 263
//
// System.out.println("TestAlarms: " + testAlarms);
// System.out.println("nullGumTreeResults: " + nullGumTreeResults);
// System.out.println("nullMappingGumTreeResults: " + nullMappingGumTreeResults);
// System.out.println("pureDeletion: " + pureDeletion);
// System.out.println("Timeout: " + timeout);
// System.out.println("noSourceCodeChagnes: " + noSourceCodeChagnes);
// System.out.println("largeHunk: " + largeHunk);
// System.out.println("nullSourceCode: " + nullSourceCode);
String statistic = "../FPM_Violations/OUTPUT";
List<File> files = FileHelper.getAllFiles(statistic, ".list");
int testAlarms = 0;
int nullGumTreeResults = 0;
int nullMappingGumTreeResults = 0;
int pureDeletion = 0;
int timeout = 0;
int noSourceCodeChagnes = 0;
int largeHunk = 0;
int nullSourceCode = 0;
for (File file : files) {
String content = FileHelper.readFile(file);
BufferedReader reader = new BufferedReader(new StringReader(content));
String line = null;
try {
while ((line = reader.readLine()) != null) {
if (line.startsWith("test")) {
testAlarms += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
} else if (line.startsWith("nullGum")) {
nullGumTreeResults += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
} else if (line.startsWith("nullMap")) {
nullMappingGumTreeResults += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
} else if (line.startsWith("pure")) {
pureDeletion += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
} else if (line.startsWith("Time")) {
timeout += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
} else if (line.startsWith("noSourceCodeChanges")) {
noSourceCodeChagnes += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
} else if (line.startsWith("largeHunk")) {
largeHunk += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
} else if (line.startsWith("nullSourceCode")) {
nullSourceCode += Integer.parseInt(line.substring(line.lastIndexOf(":") + 1).trim());
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
// TestAlarms: 5175
// nullGumTreeResults: 13449
// nullMappingGumTreeResults: 33010
// pureDeletion: 7598
// Timeout: 263
// Statistics:
// TestAlarms: 5696
// nullGumTreeResults: 0
// nullMappingGumTreeResults: 26366
// pureDeletion: 38158
// Timeout: 6090
// noSourceCodeChange: 14442
// largeHunk: 232
// nullSourceCode: 0
System.out.println("\n\nStatistics:\nTestAlarms: " + testAlarms);
System.out.println("nullGumTreeResults: " + nullGumTreeResults);
System.out.println("nullMappingGumTreeResults: " + nullMappingGumTreeResults);
System.out.println("pureDeletion: " + pureDeletion);
System.out.println("Timeout: " + timeout);
System.out.println("noSourceCodeChange: " + noSourceCodeChagnes);
System.out.println("largeHunk: " + largeHunk);
System.out.println("nullSourceCode: " + nullSourceCode);
}
public static void statistics(String fileName, String type) throws IOException {
@@ -190,9 +200,7 @@ public class Statistic {
categoryVList.put(category, list);
}
}
for (Map.Entry<String, List<String>> entry : categoryVList.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue().size());
}
FileHelper.outputToFile("../FPM_Violations/RQ1/Widespread-per-" + type + "V-Type.csv", wbuilder, false);
// output statistics
@@ -272,6 +280,7 @@ public class Statistic {
StringBuilder ssbuilder = new StringBuilder("Type, Identifier, Quantity, Category\n");
Map<String, Integer> perTypePerProj = new HashMap<>();
Map<String, List<String>> categoryProjects = new HashMap<>();
for (int j = 0; j < sortedViolationTypes.size(); j ++) {
String violationType = sortedViolationTypes.get(j);
List<Integer> projs = new ArrayList<>();
@@ -289,6 +298,17 @@ public class Statistic {
ssbuilder.append(violationType + "," + (j + 1) + "," + value + "," + category + "\n");
projs.add(value);
if (categoryProjects.containsKey(category)) {
List<String> projects = categoryProjects.get(category);
if (!projects.contains(projectName)) {
projects.add(projectName);
}
} else {
List<String> projects = new ArrayList<>();
projects.add(projectName);
categoryProjects.put(category, projects);
}
}
}
@@ -298,6 +318,10 @@ public class Statistic {
perTypePerProj.put(violationType, projs.get(index));
}
for (Map.Entry<String, List<String>> entry : categoryVList.entrySet()) {
System.out.println(entry.getKey() + ":" + entry.getValue().size() + ":" + categoryProjects.get(entry.getKey()).size());
}
FileHelper.outputToFile("../FPM_Violations/RQ1/Distribution-per-project-per-" + type + "type2.csv", ssbuilder, false);
StringBuilder ssbuilder2 = new StringBuilder("Type, Identifier, Quantity, Category\n");
perTypePerProj = sorter.sortByValueDescending(perTypePerProj);