package jeiel.experiment; import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.concurrent.Callable; import org.apache.commons.math.linear.ArrayRealVector; import org.apache.commons.math.linear.BlockRealMatrix; import org.apache.commons.math.linear.DefaultRealMatrixChangingVisitor; import org.apache.commons.math.linear.DefaultRealMatrixPreservingVisitor; import org.apache.commons.math.linear.RealMatrixChangingVisitor; import org.apache.commons.math.linear.RealMatrixPreservingVisitor; import org.apache.commons.math.linear.RealVector; import Sequenic.T2.InterfaceMap0; import Sequenic.T2.SelectiveParallelExecutor; import Sequenic.T2.StreamTraces; import Sequenic.T2.TrFile; import Sequenic.T2.Coverage.BasicPath; import Sequenic.T2.Msg.T2Exception; import Sequenic.T2.Obj.Show_Test2.ObjectToShow; import Sequenic.T2.Seq.Trace; import Sequenic.T2.StreamTraces.TraceFilter; import Sequenic.T2ext.Instrumenter.CFG; import Sequenic.T2ext.Instrumenter.CFGBunchFile; import Sequenic.T2ext.Instrumenter.ClassInstrumenter; import Sequenic.T2ext.Maintenance.UniqueCoverageReducer; import Sequenic.T2ext.Selection.RegressionTestSelector; import Sequenic.T2ext.Selection.SelectiveRunner; import Sequenic.T2ext.SelectionExperiment.MutationsExperiment.MyBaseDomain; public final class MakeTraceFiles { /** * @param args */ public static void main(String[] args) { try { // for(String d : new File("experiment/versions/v_instr/").list()) // if(d.length()==2) // instrumentDir("experiment/versions/v_instr/"+d+"/"); //instrumentDir("experiment/versions/current_classpath/"); //instrumentW(); // runSelectedParallel(false); runSelectedParallel(true); // makeSelectors(); for(int i = 0; i<5;i++) { // generateTraces(i, true); // reduce(i); // runAll(i); // StreamTraces stream = new StreamTraces(TraceFilter.trueFilter, red_traces+"nocompS"+(i+1)+".tr", // Collections.singleton(red_traces+"newestS"+(i+1)+".tr")); // while(stream.hasNext()) // stream.next(); // stream.close(); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static final String traces = "experiment/traces/"; private static final String cov_traces = "experiment/traces/cov/"; private static final String red_traces = "experiment/traces/red/"; private static final String[] subject = new String[] { "org.apache.commons.math.linear.BlockRealMatrix --pubonly --silent --ownclassonly --nullprob=-0.1" +" --xmeth=createMatrix --timeout=1600000 --imap="+LocalInterfaceMap.class.getName() +" --bdomain=" + MatrixBaseDomain.class.getName() ,"org.apache.commons.math.distribution.NormalDistributionImpl --pubonly --timeout=600000" ,"java_1_4.util.MyArrayList --pubonly --searchmode=100 --timeout=1000000 --bdomain=" + MyBaseDomain.class.getName() ,"Examples.Show --timeout=1000000 --exclfield --elemty="+ObjectToShow.class.getName() ,"Examples.BinarySearchTree --timeout=1000000" }; private static final String[] classNames = new String[] { "org/apache/commons/math/linear/BlockRealMatrix", "org/apache/commons/math/distribution/NormalDistributionImpl", "java_1_4/util/MyArrayList", "Examples/Show", "Examples/BinarySearchTree", "Examples/BinarySearchTree$BinaryNode", }; private static void generateTraces(int subj, boolean coverage) throws IOException, T2Exception { //Vary the length of the traces and the number of traces. for(int nr=10000;nr>1000;nr/=10) for(int lenexec=16;lenexec>=2;lenexec/=2) { String trFileName = "S"+(subj+1)+ "_L"+lenexec + "_N" +(nr<1000? nr+".tr" : (nr/1000)+"K.tr"); String t2args = " --nmax="+(nr*lenexec*4) //max nr of trace steps +" --lenexec="+(lenexec+1) //nr of steps per trace +" --savegoodtr="+(nr*100) //save this many traces +" --savefile="+traces+trFileName //file name ; //System.out.println(trFileName); if(!new File(traces+trFileName).exists()) Sequenic.T2.Main.main(subject[subj]+t2args); else { int[] lengths = new int[20]; for(Trace t: TrFile.load(traces+trFileName).traces) { lengths[t.trace.size()]++; lengths[19]++; } System.out.println(trFileName + ": "+Arrays.toString(lengths)); } System.gc(); if(coverage && !new File(cov_traces+trFileName).exists()) { TrFile trFile = TrFile.load(traces+trFileName); SelectiveRunner runner = new SelectiveRunner(trFile); int total = runner.runAll(); trFile.save(cov_traces+trFileName); System.out.println("Updated "+total+" traces in "+trFileName+" with coverage."); } System.gc(); } } public static class MatrixBaseDomain extends Sequenic.T2.BaseDomainSmall { public MatrixBaseDomain() { super() ; for(int i=0;i al = new ArrayList(); for(String f : new File(cov_traces).list()) { if(f.startsWith(s)) al.add(cov_traces+f); } UniqueCoverageReducer red = new UniqueCoverageReducer(280000); System.out.println("Merging "+al.size() +" files, subj " + subject[i++].substring(0, 42)); StreamTraces stream = new StreamTraces(red, red_traces+s+".tr", al); HashSet allPaths = new HashSet(); double len = 0; double pps = 0; while(stream.hasNext()) { Trace t = stream.next(); allPaths.addAll(t.coverage()); len += t.trace.size(); pps += t.coverage().size(); } stream.close(); assert stream.totalWritten()==red.accepted(); assert stream.totalRead()==(red.accepted()+red.rejected()); System.out.format("Total: %d, Kept: %d%n",stream.totalRead(),stream.totalWritten()); int red_size = stream.totalWritten(); System.out.format("#PP: %d, avg PP/trace: %.3f, avg trace len: %.3f %n%n", allPaths.size(), (pps/red_size), (len/red_size)); } private static void runAll(int i) throws IOException, ClassNotFoundException, T2Exception { System.out.println("Starting replay all for "+subject[i].substring(0, 42)); String fname = red_traces+"S"+(i+1)+".tr"; long start = System.currentTimeMillis(); // ISelector sel = getSelector(i, "experiment/versions/orig_instr/", "experiment/versions/current_classpath/"); StreamTraces stream = new StreamTraces(TraceFilter.trueFilter,red_traces+"newS"+(i+1)+".tr",Collections.singleton(fname)); // while(stream.hasNext()) // { // Trace t = stream.next(); // if(t.isObsolete()) // System.out.println(Sequenic.T2.Obj.Show.show(t,1,10)); // } SelectiveRunner runner = new SelectiveRunner(stream.trFile()); runner.runAll(stream); // runner.runSelected(sel, stream); stream.close(); start = System.currentTimeMillis() - start; System.out.println("Stream traces: "+start+"ms"); } private static TraceFilter getSelector(int i, String oldDir, String newDir) { List older = CFGBunchFile.load(oldDir+classNames[i]+".cfgs").cfgs; List newer = CFGBunchFile.load(newDir+classNames[i]+".cfgs").cfgs; if(i==4) { older.addAll(CFGBunchFile.load(oldDir+classNames[i+1]+".cfgs").cfgs); newer.addAll(CFGBunchFile.load(newDir+classNames[i+1]+".cfgs").cfgs); } // HashMap map = new HashMap(); // for(CFG g : older) // { // if(map.containsKey(g.getMethodName())) // System.out.format("Duplicate, method %s in classes%n %s orig: %s%n %s orig: %s%n", // g.getMethodName(),g.getC(),g.getOriginalMethodName(), // map.get(g.getMethodName()).getC(), // map.get(g.getMethodName()).getOriginalMethodName()); // else // map.put(g.getMethodName(), g); // } // System.out.format("#cfgs: old=%d new=%d set=%d%n",older.size(),newer.size(),map.size()); return new RegressionTestSelector(older,newer,RegressionTestSelector.RothermelHarrold).cachedJustSelect(); } private static void runSelected() throws IOException, ClassNotFoundException, T2Exception, InterruptedException { System.out.println("class, v, sel(ms),run(ms),#sel"); final String oldCFGSdir = "experiment/versions/v_instr/00/"; final SelectiveParallelExecutor extor = new SelectiveParallelExecutor(); for(int i = 0;i<5;i++) { final String fname = red_traces+"newestS"+(i+1)+".tr"; extor.execute(fname, TraceFilter.trueFilter);//warmup // for(int x=0;x<3;x++) { System.gc(); long start = System.currentTimeMillis(); final int selNr = extor.execute(fname, TraceFilter.trueFilter); long endRun = System.currentTimeMillis(); System.out.format("%s, %s, %d,%d,%d%n",classNames[i], "replay-all", 0,(endRun-start),selNr); } // for(int x=0;x<3;x++) { System.gc(); long start = System.currentTimeMillis(); final int selNr = extor.execute(fname, TraceFilter.falseFilter); long endRun = System.currentTimeMillis(); System.out.format("%s, %s, %d,%d,%d%n",classNames[i], "replay-none", 0,(endRun-start),selNr); } for(String d : new File("experiment/versions/w/").list()) { if(d.length()!=2 || d!=null) continue; final String newCFGSdir = "experiment/versions/w/"+d+"/"; getSelector(i, oldCFGSdir, newCFGSdir);//warm up selector System.gc(); long start = System.currentTimeMillis(); TraceFilter filter = getSelector(i, oldCFGSdir, newCFGSdir); long endSelector = System.currentTimeMillis(); final int selNr = extor.execute(fname, filter); long endRun = System.currentTimeMillis(); System.out.format("%s, %s, %d,%d,%d%n",classNames[i], d, (endSelector-start),(endRun-endSelector),selNr); } } extor.close(); } private static void runSelectedParallel(final boolean execute) throws Exception { System.out.println("Execute: "+execute); System.out.println("class, v, run(ms),#sel"); final String oldCFGSdir = "experiment/versions/w/00/"; final SelectiveParallelExecutor extor = //new SelectiveSequentialExecutor(); new SelectiveParallelExecutor(); RegressionTestSelector.callableTraceFilter(oldCFGSdir, oldCFGSdir, RegressionTestSelector.RothermelHarrold, classNames).call(); //warmup for(int i = 4;i>=3;i--) { final String fname = red_traces+"newestS"+(i+1)+".tr"; extor.execute(fname, TraceFilter.trueCallable,execute);//warmup for(int x=0;x<10;x++) { System.gc(); long start = System.currentTimeMillis(); final int selNr = extor.execute(fname, TraceFilter.trueCallable,execute); long endRun = System.currentTimeMillis(); System.out.format("%s, %s, %d,%d%n",classNames[i], "replay-all", (endRun-start),selNr); } for(int x=0;x<10;x++) { System.gc(); long start = System.currentTimeMillis(); final int selNr = extor.execute(fname, TraceFilter.falseCallable,execute); long endRun = System.currentTimeMillis(); System.out.format("%s, %s, %d,%d%n",classNames[i], "replay-none",(endRun-start),selNr); } for(String d : new File("experiment/versions/w/").list()) { if(d.length()!=2) continue; final Callable filter = RegressionTestSelector.callableTraceFilter( oldCFGSdir, "experiment/versions/w/"+d+"/", RegressionTestSelector.RothermelHarrold, Arrays.copyOfRange(classNames, i, i==4? i+2 : i+1)); System.gc(); long start = System.currentTimeMillis(); final int selNr = extor.execute(fname, filter,execute); long endRun = System.currentTimeMillis(); System.out.format("%s, %s, %d,%d%n",classNames[i], d, (endRun-start),selNr); } } extor.close(); } private static void runSelectedW() throws InterruptedException, ClassNotFoundException, IOException { System.out.println("class, v, sel(ms),run(ms),#sel"); final String oldCFGSdir = "experiment/versions/v_instr/00/"; final SelectiveParallelExecutor extor = new SelectiveParallelExecutor(); for(int i = 4;i>=0;i--) { final String fname = red_traces+"newestS"+(i+1)+".tr"; { System.gc(); long start = System.currentTimeMillis(); final int selNr = extor.execute(fname, TraceFilter.trueFilter); long endRun = System.currentTimeMillis(); System.out.format("%s, %s, %d,%d,%d%n",classNames[i], "replay-all", 0,(endRun-start),selNr); } for(String d : new File("experiment/versions/w").list()) { if(d.equals("00") || d.length()!=2 || !d.startsWith("5")) continue; final String newCFGSdir = "experiment/versions/w/"+d+"/"; System.gc(); long start = System.currentTimeMillis(); TraceFilter filter = getSelector(i, oldCFGSdir, newCFGSdir); long endSelector = System.currentTimeMillis(); final int selNr = extor.execute(fname, filter); long endRun = System.currentTimeMillis(); System.out.format("%s, %s, %d,%d,%d%n",classNames[i], d, (endSelector-start),(endRun-endSelector),selNr); } } extor.close(); } private static void instrumentW() throws IOException { for(String className : classNames) for(int i = 1; i <=3; i++) { { String s = "experiment/versions/w/5"+i+"/"+className; File f = new File(s+".cfgs"); s = s + ".class"; if(f.exists()) { f.delete(); f = new File(s); f.delete(); new File(s+".original").renameTo(f); } ClassInstrumenter.allMethods(s, true); } } } private static void makeSelectors() { for(int i : new int[] { RegressionTestSelector.RothermelHarrold, RegressionTestSelector.RothermelHarrold, RegressionTestSelector.RothermelHarrold, RegressionTestSelector.RothermelHarrold, RegressionTestSelector.RothermelHarrold, RegressionTestSelector.BallPartial, RegressionTestSelector.BallPartial, RegressionTestSelector.BallPartial, RegressionTestSelector.BallPartial, RegressionTestSelector.BallPartial, RegressionTestSelector.BallValid, RegressionTestSelector.BallValid, RegressionTestSelector.BallValid, RegressionTestSelector.BallValid, RegressionTestSelector.BallValid}) { long start = System.nanoTime(); ArrayList oldCfgs = new ArrayList(100); ArrayList newCfgs = new ArrayList(100); for(String c : classNames) { oldCfgs.addAll(CFGBunchFile.load("experiment/versions/w/00/"+c+".cfgs").cfgs); newCfgs.addAll(CFGBunchFile.load("experiment/versions/w/53/"+c+".cfgs").cfgs); } long endLoaded = System.nanoTime(); TraceFilter filter = new RegressionTestSelector(oldCfgs, newCfgs, i).cachedJustSelect(); long endSelector = System.nanoTime(); System.out.format("%d, %d, %d %n", i,(endLoaded-start)/1000, (endSelector-endLoaded)/1000); } } }