forked from kadirayk/SparseIDEClient
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
370 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,4 +23,6 @@ | |
hs_err_pid* | ||
/.idea | ||
*.iml | ||
/target | ||
/target | ||
/input | ||
/results |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package eval; | ||
|
||
public class EvalHelper { | ||
|
||
private static int threadCount = -1; | ||
private static int maxMethod = -1; | ||
private static long totalDuration = 0; | ||
private static long totalPropagationCount = 0; | ||
private static int actualMethodCount = 0; | ||
|
||
|
||
public static int getThreadCount() { | ||
return threadCount; | ||
} | ||
|
||
public static void setThreadCount(int threadCount) { | ||
EvalHelper.threadCount = threadCount; | ||
} | ||
|
||
public static long getTotalDuration() { | ||
return totalDuration; | ||
} | ||
|
||
public static void setTotalDuration(long totalDuration) { | ||
EvalHelper.totalDuration = totalDuration; | ||
} | ||
|
||
public static long getTotalPropagationCount() { | ||
return totalPropagationCount; | ||
} | ||
|
||
public static void setTotalPropagationCount(long totalPropagationCount) { | ||
EvalHelper.totalPropagationCount = totalPropagationCount; | ||
} | ||
|
||
public static int getActualMethodCount() { | ||
return actualMethodCount; | ||
} | ||
|
||
public static void setActualMethodCount(int actualMethodCount) { | ||
EvalHelper.actualMethodCount = actualMethodCount; | ||
} | ||
|
||
public static int getMaxMethod() { | ||
return maxMethod; | ||
} | ||
|
||
public static void setMaxMethod(int maxMethod) { | ||
EvalHelper.maxMethod = maxMethod; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
package eval; | ||
|
||
import heros.sparse.SparseCFGCache; | ||
import heros.sparse.SparseCFGQueryStat; | ||
|
||
import java.io.File; | ||
import java.io.FileWriter; | ||
import java.io.IOException; | ||
import java.util.List; | ||
|
||
public class EvalPrinter { | ||
private static final String OUT_PUT_DIR = "./results"; | ||
private static final String FILE = "sparseide_eval.csv"; | ||
|
||
private final String targetProgram; | ||
private final String solver; | ||
private int threadCount = 0; | ||
private long totalDuration = 0; | ||
private long totalPropagationCount = 0; | ||
private int methodCount = 0; | ||
private long sparseCFGBuildtime = 0; | ||
private long scfgBuildCount = 0; | ||
private float initalStmtCount = 0; | ||
private float finalStmtCount = 0; | ||
|
||
|
||
public EvalPrinter(String targetProgram, String solver) { | ||
this.targetProgram = targetProgram; | ||
this.solver = solver; | ||
this.threadCount = EvalHelper.getThreadCount(); | ||
this.totalDuration = EvalHelper.getTotalDuration(); | ||
this.totalPropagationCount = EvalHelper.getTotalPropagationCount(); | ||
this.methodCount = EvalHelper.getActualMethodCount(); | ||
if(solver.equalsIgnoreCase("sparse")){ | ||
handleSparseQueryStats(); | ||
} | ||
} | ||
|
||
private void handleSparseQueryStats() { | ||
List<SparseCFGQueryStat> queryStats = SparseCFGCache.getQueryStats(); | ||
for (SparseCFGQueryStat queryStat : queryStats) { | ||
if(!queryStat.isRetrievedFromCache()){ | ||
sparseCFGBuildtime += queryStat.getDuration().toMillis(); | ||
//if (queryStat.getInitialStmtCount() > 0 && queryStat.getFinalStmtCount() > 0) { // check for cache retrieve | ||
initalStmtCount += queryStat.getInitialStmtCount(); | ||
finalStmtCount += queryStat.getFinalStmtCount(); | ||
scfgBuildCount++; | ||
//} | ||
} | ||
} | ||
} | ||
|
||
public void generate() { | ||
File dir = new File(OUT_PUT_DIR); | ||
if (!dir.exists()) { | ||
dir.mkdir(); | ||
} | ||
File file = new File(OUT_PUT_DIR + File.separator + FILE); | ||
if(!file.exists()){ | ||
try (FileWriter writer = new FileWriter(file)) { | ||
StringBuilder str = new StringBuilder(); | ||
str.append("jar"); | ||
str.append(","); | ||
str.append("solver"); | ||
str.append(","); | ||
str.append("thread"); | ||
str.append(","); | ||
str.append("runtime"); | ||
str.append(","); | ||
str.append("prop"); | ||
str.append(","); | ||
str.append("method"); | ||
str.append(","); | ||
str.append("SCFGConst"); | ||
str.append(","); | ||
str.append("SCFGCount"); | ||
str.append(","); | ||
str.append("DoS"); | ||
str.append(System.lineSeparator()); | ||
writer.write(str.toString()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
try (FileWriter writer = new FileWriter(file, true)) { | ||
StringBuilder str = new StringBuilder(); | ||
str.append(targetProgram); | ||
str.append(","); | ||
str.append(solver); | ||
str.append(","); | ||
str.append(threadCount); | ||
str.append(","); | ||
str.append(totalDuration); | ||
str.append(","); | ||
str.append(totalPropagationCount); | ||
str.append(","); | ||
str.append(methodCount); | ||
str.append(","); | ||
str.append(sparseCFGBuildtime); | ||
str.append(","); | ||
str.append(scfgBuildCount); | ||
str.append(","); | ||
str.append(degreeOfSparsification()); | ||
str.append(System.lineSeparator()); | ||
writer.write(str.toString()); | ||
} catch (IOException e) { | ||
e.printStackTrace(); | ||
} | ||
} | ||
|
||
private String degreeOfSparsification(){ | ||
if(finalStmtCount!=0){ | ||
return String.format("%.2f",(initalStmtCount-finalStmtCount)/initalStmtCount); | ||
} | ||
return "0"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package eval; | ||
|
||
import com.google.common.base.Stopwatch; | ||
|
||
import java.io.File; | ||
import java.text.MessageFormat; | ||
import java.time.Duration; | ||
|
||
public class Main { | ||
|
||
public static void main(String[] args){ | ||
String jarPath = args[0]; // path to input jar | ||
String solver = args[1]; // solver: default or sparse | ||
int maxMethods = Integer.parseInt(args[2]); // max number of methods to analyze | ||
int numThreads = Runtime.getRuntime().availableProcessors(); // thread count | ||
if(args.length>3){ | ||
numThreads = Integer.parseInt(args[3]); // thread count | ||
} | ||
|
||
|
||
String msg = MessageFormat.format("Running {0} - {1} solver - {2} threads", getJarName(jarPath), solver, numThreads); | ||
System.out.println(msg); | ||
EvalHelper.setMaxMethod(10); | ||
EvalHelper.setThreadCount(numThreads); | ||
|
||
SetUp setUp = new SetUp(); | ||
Stopwatch stopwatch = Stopwatch.createStarted(); | ||
if(solver.equalsIgnoreCase("default")){ | ||
setUp.executeStaticAnalysis(jarPath); | ||
EvalHelper.setTotalPropagationCount(setUp.defaultPropCount); // clean later | ||
}else if (solver.equalsIgnoreCase("sparse")){ | ||
setUp.executeSparseStaticAnalysis(jarPath); | ||
EvalHelper.setTotalPropagationCount(setUp.sparsePropCount); | ||
} | ||
Duration elapsed = stopwatch.elapsed(); | ||
EvalHelper.setTotalDuration(elapsed.toMillis()); | ||
new EvalPrinter(getJarName(jarPath), solver).generate(); | ||
} | ||
|
||
private static String getJarName(String fullpath){ | ||
int start = fullpath.lastIndexOf(File.separator); | ||
int endDot = fullpath.lastIndexOf("."); | ||
int endDash = fullpath.lastIndexOf("-"); | ||
int latest = endDot<endDash ? endDash : endDot; | ||
return fullpath.substring(start + 1, latest); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.