Commit ed8056cf authored by ISWB Prasetya's avatar ISWB Prasetya
Browse files

analytics for G2 should be mostly done now.

parent 632508d0
......@@ -184,8 +184,9 @@ public class G2 {
* generated coverage is deemed to be not enough. If may be
* picked out and its saved suite refined.
* The whole process will keep going, until it runs out time budget.
* @throws IOException
*/
protected void generateAndRefine() throws TimeBudgetException, InterruptedException {
protected void generateAndRefine() throws TimeBudgetException, InterruptedException, IOException {
if (worklist.isEmpty()) {
t3log.info("" + g2sg.scope.CUT.getName() + " induces no target, so NO TEST SUITE is generated.") ;
......@@ -208,6 +209,8 @@ public class G2 {
int prefixStagnationCount = 0 ;
int stagnationLimit = 3 ;
int topIterationCount = 0 ; // counting target-refinement
record_and_report_WorkListStatistics(topIterationCount) ; // this will initialize analystics
record_and_report_prefixStatistics(prefixRefinementCount,0) ; // initialize too
boolean generateMorePrefix = worklist.hasADTtarget() ;
while (!worklist.isEmpty()) {
if (generateMorePrefix && prefixStagnationCount < stagnationLimit) {
......@@ -234,41 +237,8 @@ public class G2 {
}
}
if (g2sg.currentPrefixes != null) {
// generating some analytics data
String savedir = "/Users/iswbprasetya/tmp/t3" ;
DataTable dt_prefixcov = new DataTable(1,DataTable.DOUBLE) ;
dt_prefixcov.addHeaderRow("cov") ;
dt_prefixcov.addRow(g2sg.currentPrefixes.coverage) ;
String dt_prefixcov_fname = savedir + "/" + g2sg.scope.CUT.getName()
+ "_prefixcov_"
+ prefixRefinementCount + ".txt" ;
try { dt_prefixcov.save(dt_prefixcov_fname);}
catch(Exception e) { }
DataTable dt_tobj = new DataTable(2,DataTable.DOUBLE) ;
dt_tobj.addHeaderRow("depth","diversitySum");
for(ObjStructure o : g2sg.currentPrefixes.tobjs) {
if (o == null) dt_tobj.addRow(0d,0d) ;
else dt_tobj.addRow((double) o.depth,o.diversitySum);
}
String dt_tobj_fname = savedir + "/" + g2sg.scope.CUT.getName()
+ "_tobj_diversity_"
+ prefixRefinementCount + ".txt" ;
try { dt_tobj.save(dt_tobj_fname);}
catch(Exception e) { }
t3log.info("=== Generating/refining prefixes of "
+ g2sg.scope.CUT.getName()
+ ". Generation: " + prefixRefinementCount
+ ", adding: " + numOfAddedPrefixes
+ ", tot-size: " + g2sg.getPrefixes().suite.size()
+ ", cov: " + g2sg.currentPrefixes.coverage
+ ", #tobjs: " + g2sg.currentPrefixes.tobjs.size()
);
if (g2sg.currentPrefixes != null) {
record_and_report_prefixStatistics(prefixRefinementCount,numOfAddedPrefixes) ;
}
}
// pick a target and refine:
......@@ -296,31 +266,117 @@ public class G2 {
t3log.info("Refinement for " + target.getName() + " has STAGNATED; it will not be further refined.");
topIterationCount++ ;
// Reporting some statistics
String s = "Worklist iteration " + topIterationCount + "\n";
double totTargetConv = 0d ;
for(SingleTarget ST : worklist.allTargets) {
int size = 0 ;
double tcov = ST.getLastTargetCov() ;
totTargetConv += tcov ;
if (ST.suite != null) size = ST.suite.suite.size() ;
s += " " + ST.getName() + "_" + ST.getNumOfParams()
+ ", generation:" + ST.numberOfIterations()
+ ", seqs-tried:" + ST.totNumberOfTriedSequences
+ ", size:" + size
+ ", cov:" + tcov + "\n" ;
}
totTargetConv = totTargetConv / (double) worklist.allTargets.size();
s += "Tot. target coverage:" + totTargetConv ;
t3log.info(s);
record_and_report_WorkListStatistics(topIterationCount) ;
remaining = timebudgetTracker.check() ;
}
Analytics.save(config.dirToSaveSuites,null,null);
}
private String worklistStats_tablename() {
return "" + "wlist_" + g2sg.scope.CUT.getName() ;
}
private String worklistTotCovStats_tablename() {
return "" + "wlistTotcov_" + g2sg.scope.CUT.getName() ;
}
private String prefixesDiversityStats_tablename() {
return "" + "prefixesDiversity_" + g2sg.scope.CUT.getName() ;
}
private String prefixCovStats_tablename() {
return "" + "prefixesCov_" + g2sg.scope.CUT.getName() ;
}
void record_and_report_WorkListStatistics(int topIterationCount) {
if(topIterationCount <= 0) {
// when called first time, create the tables
Analytics.registerDataTable(worklistStats_tablename(),DataTable.DOUBLE,
"iteration",
"target",
"generation",
"triedseqs",
"suitesize",
"cov");
Analytics.registerDataTable(worklistTotCovStats_tablename(), DataTable.DOUBLE,
"iteration",
"totTriedseqs",
"totSuitesize",
"totcov");
return ;
}
String s = "Worklist iteration " + topIterationCount + "\n";
int totTriedSeqs = 0 ;
int totSuiteSize = 0 ;
double totTargetCov = 0d ;
for(SingleTarget ST : worklist.allTargets) {
double tcov = ST.getLastTargetCov() ;
totTargetCov += tcov ;
totTriedSeqs += ST.totNumberOfTriedSequences ;
int size = 0 ;
if (ST.suite != null) size = ST.suite.suite.size() ;
totSuiteSize += size ;
s += " " + ST.getName() + "_" + ST.getNumOfParams()
+ ", generation:" + ST.numberOfIterations()
+ ", seqs-tried:" + ST.totNumberOfTriedSequences
+ ", size:" + size
+ ", cov:" + tcov + "\n" ;
}
totTargetCov = totTargetCov / (double) worklist.allTargets.size();
Analytics.addRow(worklistTotCovStats_tablename(),
(double) topIterationCount,
(double) totTriedSeqs,
(double) totSuiteSize,
totTargetCov) ;
s += "Tot. tried sequences:" + totTriedSeqs + "\n";
s += "Tot. suite size:" + totSuiteSize + "\n";
s += "Tot. target coverage:" + totTargetCov ;
t3log.info(s);
}
void record_and_report_prefixStatistics(int prefixRefinementCount, int added) {
if(prefixRefinementCount <= 0) {
Analytics.registerDataTable(prefixCovStats_tablename(), DataTable.DOUBLE,
"iteration",
"added",
"totSize",
"classcov");
return ;
}
int size = g2sg.currentPrefixes.size() ;
double cov = g2sg.currentPrefixes.coverage ;
//int Ntobjs = g2sg.currentPrefixes.tobjs.size() ;
Analytics.addRow(prefixCovStats_tablename(),
(double) prefixRefinementCount,
(double) added,
(double) size,
cov);
if (added>0) {
String tablename = prefixesDiversityStats_tablename() + "_iter_" + prefixRefinementCount ;
Analytics.registerDataTable(tablename, DataTable.DOUBLE,
"depth",
"diversitySum");
for(ObjStructure o : g2sg.currentPrefixes.tobjs) {
if (o == null) Analytics.addRow(tablename,0d,0d) ;
else Analytics.addRow(tablename,(double) o.depth,o.diversitySum);
}
}
t3log.info("=== Generating/refining prefixes of "
+ g2sg.scope.CUT.getName()
+ ". Generation: " + prefixRefinementCount
+ ", adding: " + added
+ ", tot-size: " + size
+ ", cov: " + cov
//+ ", #tobjs: " + Ntobjs
);
}
/**
......@@ -478,6 +534,7 @@ public class G2 {
g2s[i].generateAndRefine() ;
}
catch (TimeBudgetException te) { }
catch (IOException e) { }
}
}
}
\ No newline at end of file
......@@ -42,6 +42,8 @@ public class SingleTarget {
public Object target; // a Method or a Constructor ;
public boolean isADT; // when true, target is a target for ADT testing
public SUITE suite = null; // best suite we have so far for the target
public int ID = 0 ;
// maximum number this suite can be refined
protected int maxNumberOfRefinement ;
......@@ -113,6 +115,11 @@ public class SingleTarget {
if (target instanceof Method) return ((Method) target).getName() ;
return ((Constructor) target).getName() ;
}
public String getUniqueName() {
return "" + getName() + "_" + getNumOfParams()
+ "_id" + ID ;
}
private static int power(int e, int k) {
int r = 1 ;
......
......@@ -22,7 +22,7 @@ public class Test_G2_CustomPrimValGen {
static void genWithG2() throws Exception {
G2Config config = config() ;
config.customPrimitivesGenerator = OneOfVal_(777f,707f) ;
config.usePrimitiveGenerator(OneOfVal_(777f,707f)) ;
G2.generateSuites("Sequenic.T3.Examples.Triangle1",config,60000) ;
}
......
......@@ -83,6 +83,7 @@ public class Worklist {
*/
public void addTarget(SingleTarget target) {
target.ID = allTargets.size() ;
allTargets.add(target) ;
waiting.add(target) ;
}
......
......@@ -38,10 +38,14 @@ public class Analytics {
public static void save(String dirpath, String prefix, String suffix) throws IOException {
for (Entry<String,DataTable> E : mydata.entrySet()) {
String prefix_ = "" ;
if (prefix != null) prefix_ = prefix + "_" ;
String suffix_ = "" ;
if (suffix != null) suffix_ = "_" + suffix ;
String fname = dirpath
+ "/" + prefix + "_"
+ E.getKey() + "_"
+ suffix + ".txt" ;
+ "/" + prefix_
+ E.getKey()
+ suffix_ + ".txt" ;
E.getValue().save(fname);
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment