Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add code for incremental storage #229

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ target
/bin/
/.project
/.classpath
/.metadata
/.metadata
neo4j/
16 changes: 16 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
version: '3'
services:
neo4j:
container_name: neo4j
image: neo4j:4.3.3
restart: unless-stopped
ports:
- 7474:7474
- 7687:7687
volumes:
- ./neo4j/data:/neo4j-data
- ./neo4j/import:/import
- ./neo4j/plugins:/plugins
user: "${UID}:${GID}"
volumes:
neo4j:
56 changes: 31 additions & 25 deletions microbat/.classpath
Original file line number Diff line number Diff line change
@@ -1,25 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main"/>
<classpathentry excluding="resources/" kind="src" path="src/test"/>
<classpathentry kind="src" path="src/evaluation"/>
<classpathentry kind="src" path="src/behavior"/>
<classpathentry exported="true" kind="lib" path="lib/mysql-connector-java-5.1.44-bin.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-util-6.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-tree-6.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-6.0.jar" sourcepath="lib/asm_src.zip"/>
<classpathentry exported="true" kind="lib" path="lib/bcel-6.0.jar" sourcepath="lib/bcel-6.0-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/soot-trunk.jar" sourcepath="lib/sootclasses-trunk-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/poi-ooxml-schemas-3.11-20141221.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xmlbeans-2.6.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/poi-ooxml-3.11-20141221.jar"/>
<classpathentry exported="true" kind="lib" path="lib/poi-3.11-20141221.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.ibm.wala.core-1.3.9-SNAPSHOT.jar" sourcepath="lib/com.ibm.wala.core-1.3.9-SNAPSHOT-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.ibm.wala.shrike-1.3.9-SNAPSHOT.jar" sourcepath="lib/com.ibm.wala.shrike-1.3.9-SNAPSHOT-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.ibm.wala.util-1.3.9-SNAPSHOT.jar" sourcepath="lib/com.ibm.wala.util-1.3.9-SNAPSHOT-sources.jar"/>
<classpathentry kind="lib" path="lib/instrumentator.jar" sourcepath="/microbat_instrumentator"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="lib" path="lib/sqlite-jdbc-3.32.3.2.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src/main"/>
<classpathentry excluding="resources/" kind="src" path="src/test"/>
<classpathentry kind="src" path="src/evaluation"/>
<classpathentry kind="src" path="src/behavior"/>
<classpathentry exported="true" kind="lib" path="lib/mysql-connector-java-5.1.44-bin.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-util-6.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-tree-6.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/asm-6.0.jar" sourcepath="lib/asm_src.zip"/>
<classpathentry exported="true" kind="lib" path="lib/bcel-6.0.jar" sourcepath="lib/bcel-6.0-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/soot-trunk.jar" sourcepath="lib/sootclasses-trunk-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/poi-ooxml-schemas-3.11-20141221.jar"/>
<classpathentry exported="true" kind="lib" path="lib/xmlbeans-2.6.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/poi-ooxml-3.11-20141221.jar"/>
<classpathentry exported="true" kind="lib" path="lib/poi-3.11-20141221.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.ibm.wala.core-1.3.9-SNAPSHOT.jar" sourcepath="lib/com.ibm.wala.core-1.3.9-SNAPSHOT-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.ibm.wala.shrike-1.3.9-SNAPSHOT.jar" sourcepath="lib/com.ibm.wala.shrike-1.3.9-SNAPSHOT-sources.jar"/>
<classpathentry exported="true" kind="lib" path="lib/com.ibm.wala.util-1.3.9-SNAPSHOT.jar" sourcepath="lib/com.ibm.wala.util-1.3.9-SNAPSHOT-sources.jar"/>
<classpathentry kind="lib" path="lib/instrumentator.jar" sourcepath="/microbat_instrumentator"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="module" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="lib" path="lib/sqlite-jdbc-3.32.3.2.jar"/>
<classpathentry kind="lib" path="lib/neo4j-java-driver-4.3.4.jar"/>
<classpathentry kind="lib" path="lib/neo4j-jdbc-driver-4.0.2.jar"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
2 changes: 2 additions & 0 deletions microbat/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Bundle-ClassPath: .,
lib/asm-util-6.0.jar,
lib/mysql-connector-java-5.1.44-bin.jar,
lib/sqlite-jdbc-3.32.3.2.jar,
lib/neo4j-java-driver-4.3.4.jar,
lib/neo4j-jdbc-driver-4.0.2.jar,
lib/instrumentator.jar
Export-Package: microbat;uses:="org.osgi.framework,org.eclipse.jface.resource,org.eclipse.ui.plugin",
microbat.agent,
Expand Down
4 changes: 3 additions & 1 deletion microbat/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ bin.includes = META-INF/,\
ddl/Step.sql,\
ddl/StepVariableRelation.sql,\
ddl/Trace.sql,\
lib/instrumentator.jar
lib/instrumentator.jar,\
lib/neo4j-java-driver-4.3.4.jar,\
lib/neo4j-jdbc-driver-4.0.2.jar
src.excludes = src/test/
src.includes = icons/,\
plugin.xml,\
Expand Down
Binary file modified microbat/lib/instrumentator.jar
Binary file not shown.
Binary file added microbat/lib/neo4j-java-driver-4.3.4.jar
Binary file not shown.
Binary file added microbat/lib/neo4j-jdbc-driver-4.0.2.jar
Binary file not shown.
20 changes: 10 additions & 10 deletions microbat/src/main/microbat/agent/TraceAgentRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import microbat.instrumentation.precheck.PrecheckInfo;
import microbat.model.trace.Trace;
import microbat.preference.DatabasePreference;
import microbat.sql.DBSettings;
import microbat.trace.Reader;
import sav.common.core.SavException;
import sav.common.core.SavRtException;
Expand All @@ -39,7 +40,7 @@ public class TraceAgentRunner extends AgentVmRunner {
private String testFailureMessage;
private VMConfiguration config;
private boolean enableSettingHeapSize = true;

private List<Trace> traces;

public TraceAgentRunner(String agentJar, VMConfiguration vmConfig) {
Expand Down Expand Up @@ -109,9 +110,11 @@ public boolean run(Reader reader) throws SavException {
dumpFile = DatabasePreference.getDBFile();
break;
}
addAgentParam(AgentParams.OPT_TRACE_RECORDER, reader.name()); // why is reader name used for recorder option?
addAgentParam(AgentParams.OPT_TRACE_RECORDER, reader.name()); // why is reader name used for recorder
// option?
addAgentParam(AgentParams.OPT_RUN_ID, runId);
addAgentParam(AgentParams.OPT_DUMP_FILE, String.valueOf(dumpFile.getPath()));
addAgentParam(AgentParams.OPT_IS_INC_STORAGE, DBSettings.INC_STORAGE);
super.startAndWaitUntilStop(getConfig()); // Trace recording
System.out.println("|");
timer.newPoint("Read output result");
Expand All @@ -127,8 +130,7 @@ public boolean run(Reader reader) throws SavException {
System.out.println(timer.getResultString());
return true;
}



// public boolean run01(Reader reader) throws SavException {
// isPrecheckMode = false;
// StopTimer timer = new StopTimer("Building trace");
Expand Down Expand Up @@ -212,9 +214,7 @@ public boolean runWithSocket() throws SavException {
String msg = reader.readString();
updateTestResult(msg);
List<Trace> traces = reader.readTrace();
int collected = traces.stream()
.mapToInt(trace -> trace.size())
.sum();
int collected = traces.stream().mapToInt(trace -> trace.size()).sum();
runningInfo = new RunningInfo(msg, traces, precheckInfo.getStepTotal(), collected);
} catch (Exception e) {
e.printStackTrace();
Expand All @@ -241,11 +241,11 @@ protected void printOut(String line, boolean error) {
};

private void printProgress(int size, int stepNum) {
if(stepNum == 0) {

if (stepNum == 0) {
return;
}

double progress = ((double) size) / stepNum;

double preProgr = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import org.apache.commons.io.FileUtils;
import org.eclipse.jdt.core.dom.ASTNode;
Expand Down Expand Up @@ -198,7 +199,7 @@ public RunningInfo execute(PreCheckInformation info) {
RunningInfo result = agentRunner.getRunningInfo();
// System.out.println(result);
System.out.println("isExpectedStepsMet? " + result.isExpectedStepsMet());
System.out.println("trace length: " + result.getMainTrace() == null ? "0" : result.getMainTrace().size());
System.out.println("trace length: " + Optional.ofNullable(result.getMainTrace()).map(t -> t.size()).orElse(0));
System.out.println("isTestSuccessful? " + agentRunner.isTestSuccessful());
System.out.println("testFailureMessage: " + agentRunner.getTestFailureMessage());
System.out.println("finish!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public ProgramExecutor() {
*/
public void run(List<BreakPoint> runningStatements, List<BreakPoint> executionOrderList, IProgressMonitor monitor,
int stepNum, boolean isTestcaseEvaluation) throws SavException, TimeoutException {
this.trace = new Trace(appPath);
this.trace = new Trace(appPath, "");

List<String> classScope = parseScope(runningStatements);
List<LocalVariableScope> lvsList = parseLocalVariables(classScope, this.appPath);
Expand Down
11 changes: 4 additions & 7 deletions microbat/src/main/microbat/model/trace/Trace.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,17 @@ public class Trace {
private List<String> excludedLibraryClasses = new ArrayList<>();
private boolean isMain;
private String threadName;
private String id;
private String traceId;

/**
* This variable is to trace whether the variables in different lines are the same
* local variable.
*/
private LocalVariableScopes localVariableScopes = new LocalVariableScopes();

public Trace(AppJavaClassPath appJavaClassPath) {
public Trace(AppJavaClassPath appJavaClassPath, String traceId) {
this.setAppJavaClassPath(appJavaClassPath);
}

public Trace(String id) {
this.id = id;
this.traceId = traceId;
}

/**
Expand Down Expand Up @@ -153,7 +150,7 @@ public void setObservingIndex(int observingIndex) {
}

public String getId() {
return this.id;
return traceId;
}

public int searchBackwardTraceNode(String expression){
Expand Down
15 changes: 12 additions & 3 deletions microbat/src/main/microbat/preference/DatabasePreference.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,14 @@

public class DatabasePreference extends PreferencePage implements IWorkbenchPreferencePage {
private static final String ID = "microbat.preference.database";
private static final Reader[] READERS = new Reader[] { Reader.SQLITE3, Reader.MYSQL, Reader.NEO4J };
public static final String HOST = "dbHost";
public static final String PORT = "dbPort";
public static final String DATABASE = "dbName";
public static final String USER_NAME = "dbUserName";
public static final String PASSWORD = "dbPassword";
public static final String IS_STARTDB = "startdb";
public static final String IS_INC_STORAGE= "incrementalStorage";
public static final String DBMS = "dbms";
public static final String DBPATH = "dbPath`";

Expand All @@ -46,6 +48,7 @@ public class DatabasePreference extends PreferencePage implements IWorkbenchPref
private StringFieldEditor passwordField;
private Combo dataBaseDropDown;
private Button startWithSQL;
private Button incrementalStorage;
private DirectoryFieldEditor sqliteDBPath;

@Override
Expand All @@ -61,9 +64,11 @@ protected Control createContents(Composite parent) {
contents.setLayout(layout);
contents.setLayoutData(new GridData(GridData.FILL_BOTH));
startWithSQL = SWTFactory.createCheckbox(contents, "Start with SQL", 1);
incrementalStorage = SWTFactory.createCheckbox(contents, "Turn on incremental storage", 1);
dataBaseDropDown = SWTFactory.creatDropdown(contents);
dataBaseDropDown.add(Reader.SQLITE3.toString());
dataBaseDropDown.add(Reader.MYSQL.toString());
dataBaseDropDown.add(Reader.NEO4J.toString());
dataBaseDropDown.select(0);

SWTFactory.createLabel(contents, "Database Configuration:", 2);
Expand All @@ -85,21 +90,22 @@ protected Control createContents(Composite parent) {
public static Reader getReader() {
IPreferenceStore pref = Activator.getDefault().getPreferenceStore();
if (pref.getBoolean(IS_STARTDB)) {
return pref.getInt(DBMS) == 1 ? Reader.MYSQL : Reader.SQLITE3;
// return pref.getInt(DBMS) == 1 ? Reader.MYSQL : Reader.SQLITE3;
return READERS[pref.getInt(DBMS)];
} else {
return Reader.FILE;
}
}

public static File getDBFile() {
String filePath = Activator.getDefault().getPreferenceStore().getString(DBPATH);

if (filePath.trim().equals("") || filePath == null) {
System.err.println("need to specify the db file location");
} else {
return new File(filePath);
}

return null;
}

Expand All @@ -111,6 +117,7 @@ private void setDefaultValue() {
userNameField.setStringValue(pref.getString(USER_NAME));
passwordField.setStringValue(pref.getString(PASSWORD));
startWithSQL.setSelection(pref.getBoolean(IS_STARTDB));
incrementalStorage.setSelection(pref.getBoolean(IS_INC_STORAGE));
dataBaseDropDown.select(pref.getInt(DBMS));
sqliteDBPath.setStringValue(pref.getString(DBPATH));
}
Expand All @@ -131,6 +138,7 @@ public boolean performOk() {
preferences.put(USER_NAME, userNameField.getStringValue());
preferences.put(PASSWORD, passwordField.getStringValue());
preferences.putBoolean(IS_STARTDB, startWithSQL.getSelection());
preferences.putBoolean(IS_INC_STORAGE, incrementalStorage.getSelection());
preferences.putInt(DBMS, dataBaseDropDown.getSelectionIndex());
preferences.put(DBPATH, sqliteDBPath.getStringValue());
try {
Expand All @@ -146,6 +154,7 @@ public boolean performOk() {
pref.putValue(USER_NAME, userNameField.getStringValue());
pref.putValue(PASSWORD, passwordField.getStringValue());
pref.putValue(IS_STARTDB, String.valueOf(startWithSQL.getSelection()));
pref.putValue(IS_INC_STORAGE, String.valueOf(incrementalStorage.getSelection()));
pref.putValue(DBMS, String.valueOf(dataBaseDropDown.getSelectionIndex()));
pref.putValue(DBPATH, String.valueOf(sqliteDBPath.getStringValue()));

Expand Down
3 changes: 3 additions & 0 deletions microbat/src/main/microbat/sql/DBSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class DBSettings {

public static final int SQLITE3_DBMS = 0;
public static final int MYSQL_DBMS = 1;
public static final int NEO4J_DBMS = 2;

public static String dbAddress = "localhost";
public static int dbPort = 3306;
Expand All @@ -18,6 +19,7 @@ public class DBSettings {
public static String dbPath = "microbat.db";
public static int DMBS_TYPE = SQLITE3_DBMS;
public static String USE_DB = "false";
public static String INC_STORAGE = "false";
public static boolean enableAutoUpdateDb = true;
private static int version = -1; //keep track for the update

Expand All @@ -35,6 +37,7 @@ public static void updateFromPreference() {
password = pref.getString(PASSWORD);
DMBS_TYPE = pref.getInt(DBMS);
USE_DB = pref.getString(IS_STARTDB);
INC_STORAGE = pref.getString(IS_INC_STORAGE);
dbPath = pref.getString(DBPATH);
version++;
}
Expand Down
3 changes: 3 additions & 0 deletions microbat/src/main/microbat/sql/DbService.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,9 @@ public static Connection getConnection() throws SQLException {
case DBSettings.SQLITE3_DBMS:
factory = new SqliteConnectionFactory();
break;
case DBSettings.NEO4J_DBMS:
// factory = new SqliteConnectionFactory();
return null;
default:
throw new SQLException("we yet support dbms type other than mysql and sqlite3");
}
Expand Down
Loading