diff options
author | 2016-11-28 18:08:00 -0800 | |
---|---|---|
committer | 2016-11-30 11:26:33 -0800 | |
commit | c37b0a40e77c0f3e2487b630d72a9a9cad694c12 (patch) | |
tree | 4019f00b3826aed6d4895744d7ad0a68dafd9df2 | |
parent | 437474990d53ea96f038205c1dc49ae3a8cc9fc1 (diff) |
Add command line action sequencing.
Supported actions:
* .. scan <process> ..
* .. scan-all ..
* .. import <infile> ..
* .. export <infile> ..
* .. comp <thresh> <outfile> ..
Test: manual
Bug: 31961946
Change-Id: I08753f31294ac5f30f6bcddeabef12d138e7e8e6
-rw-r--r-- | tools/preload2/src/com/android/preload/Main.java | 61 |
1 files changed, 56 insertions, 5 deletions
diff --git a/tools/preload2/src/com/android/preload/Main.java b/tools/preload2/src/com/android/preload/Main.java index 8e6010559d21..c42a19b58811 100644 --- a/tools/preload2/src/com/android/preload/Main.java +++ b/tools/preload2/src/com/android/preload/Main.java @@ -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; } |