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