Merge "Add command line action sequencing." am: 880c9acf4a am: 3711f2f0c2
am: 2f5f210f7d
Change-Id: I10c2d3c3be0bb8748602b3a566f75f8c687f8889
This commit is contained in:
@@ -35,6 +35,7 @@ import com.android.preload.classdataretrieval.jdwp.JDWPClassDataRetriever;
|
||||
import com.android.preload.ui.IUI;
|
||||
import com.android.preload.ui.SequenceUI;
|
||||
import com.android.preload.ui.SwingUI;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -42,6 +43,7 @@ import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NoSuchElementException;
|
||||
|
||||
import javax.swing.Action;
|
||||
import javax.swing.DefaultListModel;
|
||||
@@ -89,6 +91,12 @@ public class Main {
|
||||
+ "android.webkit.WebViewClassic\\$1$" + "|" + "java.lang.ProcessManager$" + "|"
|
||||
+ "(.*\\$NoPreloadHolder$)";
|
||||
|
||||
public final static String SCAN_ALL_CMD = "scan-all";
|
||||
public final static String SCAN_PACKAGE_CMD = "scan";
|
||||
public final static String COMPUTE_FILE_CMD = "comp";
|
||||
public final static String EXPORT_CMD = "export";
|
||||
public final static String IMPORT_CMD = "import";
|
||||
|
||||
/**
|
||||
* @param args
|
||||
*/
|
||||
@@ -148,13 +156,56 @@ public class Main {
|
||||
|
||||
Iterator<String> it = Arrays.asList(args).iterator();
|
||||
it.next(); // --seq
|
||||
|
||||
// Setup
|
||||
ui.choice("#" + it.next()); // Device.
|
||||
ui.confirmNo(); // Prepare: no.
|
||||
ui.action(ScanPackageAction.class); // Take hprof dump.
|
||||
ui.client("system_process"); // Select system server.
|
||||
ui.action(ExportAction.class); // Export data.
|
||||
ui.output(new File("/tmp/system_server.data")); // Write to file.
|
||||
// Actions
|
||||
try {
|
||||
while (it.hasNext()) {
|
||||
String op = it.next();
|
||||
// Operation: Scan a single package
|
||||
if (SCAN_PACKAGE_CMD.equals(op)) {
|
||||
System.out.println("Scanning package.");
|
||||
ui.action(ScanPackageAction.class);
|
||||
ui.client(it.next());
|
||||
// Operation: Scan all packages
|
||||
} else if (SCAN_ALL_CMD.equals(op)) {
|
||||
System.out.println("Scanning all packages.");
|
||||
ui.action(ScanAllPackagesAction.class);
|
||||
// Operation: Export the output to a file
|
||||
} else if (EXPORT_CMD.equals(op)) {
|
||||
System.out.println("Exporting data.");
|
||||
ui.action(ExportAction.class);
|
||||
ui.output(new File(it.next()));
|
||||
// Operation: Import the input from a file or directory
|
||||
} else if (IMPORT_CMD.equals(op)) {
|
||||
System.out.println("Importing data.");
|
||||
File file = new File(it.next());
|
||||
if (!file.exists()) {
|
||||
throw new RuntimeException(
|
||||
String.format("File does not exist, %s.", file.getAbsolutePath()));
|
||||
} else if (file.isFile()) {
|
||||
ui.action(ImportAction.class);
|
||||
ui.input(file);
|
||||
} else if (file.isDirectory()) {
|
||||
for (File content : file.listFiles()) {
|
||||
ui.action(ImportAction.class);
|
||||
ui.input(content);
|
||||
}
|
||||
}
|
||||
// Operation: Compute preloaded classes with specific threshold
|
||||
} else if (COMPUTE_FILE_CMD.equals(op)) {
|
||||
System.out.println("Compute preloaded classes.");
|
||||
ui.action(ComputeThresholdXAction.class);
|
||||
ui.input(it.next());
|
||||
ui.confirmYes();
|
||||
ui.output(new File(it.next()));
|
||||
}
|
||||
}
|
||||
} catch (NoSuchElementException e) {
|
||||
System.out.println("Failed to parse action sequence correctly.");
|
||||
throw e;
|
||||
}
|
||||
|
||||
return main;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user