Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 990fb6b5 authored by David Brazdil's avatar David Brazdil
Browse files

Add option to compile all packages with 'cmd package compile'

To help investigate performance regressions, an option is added to
'adb shell cmd package compile' to compile all packages with the
given mode.

Bug: 27391290
Change-Id: I70a3a518e08b54535bb34f13f0cedda3a1f7085f
parent 713be06f
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -120,6 +120,8 @@ interface IPackageManager {

    int checkUidSignatures(int uid1, int uid2);

    List<String> getAllPackages();

    String[] getPackagesForUid(int uid);

    String getNameForUid(int uid);
+0 −1
Original line number Diff line number Diff line
@@ -191,7 +191,6 @@ class PackageDexOptimizer {
                        throw new IllegalStateException("Invalid dexopt:" + dexoptNeeded);
                }


                Log.i(TAG, "Running dexopt (" + dexoptType + ") on: " + path + " pkg="
                        + pkg.applicationInfo.packageName + " isa=" + dexCodeInstructionSet
                        + " vmSafeMode=" + vmSafeMode + " debuggable=" + debuggable
+7 −0
Original line number Diff line number Diff line
@@ -4442,6 +4442,13 @@ public class PackageManagerService extends IPackageManager.Stub {
        return PackageManager.SIGNATURE_NO_MATCH;
    }
    @Override
    public List<String> getAllPackages() {
        synchronized (mPackages) {
            return new ArrayList<String>(mPackages.keySet());
        }
    }
    @Override
    public String[] getPackagesForUid(int uid) {
        uid = UserHandle.getAppId(uid);
+42 −10
Original line number Diff line number Diff line
@@ -233,11 +233,15 @@ class PackageManagerShellCommand extends ShellCommand {
        boolean useJitProfiles = false;
        boolean extractOnly = false;
        boolean forceCompilation = false;
        boolean allPackages = false;
        String compilationMode = "default";

        String opt;
        while ((opt = getNextOption()) != null) {
            switch (opt) {
                case "-a":
                    allPackages = true;
                    break;
                case "-m":
                    compilationMode = getNextArgRequired();
                    break;
@@ -272,19 +276,46 @@ class PackageManagerShellCommand extends ShellCommand {
                return 1;
        }

        List<String> packageNames = null;
        if (allPackages) {
            packageNames = mInterface.getAllPackages();
        } else {
            String packageName = getNextArg();
            if (packageName == null) {
                pw.println("Error: package name not specified");
                return 1;
            }
            packageNames = Collections.singletonList(packageName);
        }

        boolean success = mInterface.performDexOpt(packageName, null /* instructionSet */,
        List<String> failedPackages = new ArrayList<>();
        for (String packageName : packageNames) {
            pw.println(packageName);
            boolean result = mInterface.performDexOpt(packageName, null /* instructionSet */,
                        useJitProfiles, extractOnly, forceCompilation);
        if (success) {
            if (!result) {
                failedPackages.add(packageName);
            }
        }

        if (failedPackages.isEmpty()) {
            pw.println("Success");
            return 0;
        } else if (failedPackages.size() == 1) {
            pw.println("Failure: package " + failedPackages.get(0) + " could not be compiled");
            return 1;
        } else {
            pw.print("Failure: the following packages could not be compiled: ");
            boolean is_first = true;
            for (String packageName : failedPackages) {
                if (is_first) {
                    is_first = false;
                } else {
            pw.println("Failure: package " + packageName + " could not be compiled");
                    pw.print(", ");
                }
                pw.print(packageName);
            }
            pw.println();
            return 1;
        }
    }
@@ -1135,9 +1166,10 @@ class PackageManagerShellCommand extends ShellCommand {
        pw.println("  help");
        pw.println("    Print this help text.");
        pw.println("");
        pw.println("  compile [-m MODE] [-f] TARGET-PACKAGE");
        pw.println("    Trigger compilation of TARGET-PACKAGE.");
        pw.println("  compile [-m MODE] [-f] (-a | TARGET-PACKAGE)");
        pw.println("    Trigger compilation of TARGET-PACKAGE or all packages if \"-a\".");
        pw.println("    Options:");
        pw.println("      -a: compile all packages");
        pw.println("      -m: select compilation mode");
        pw.println("          MODE can be one of \"default\", \"all\", \"profile\", and \"extract\"");
        pw.println("      -f: force compilation even if not needed");