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

Commit 235845dc authored by Mathieu Chartier's avatar Mathieu Chartier
Browse files

Copy preopted profiles to ref for first boot

Since the app is partially compiled, compiled methods won't get new
samples. We need to copy the preopted profiles over so that the
methods are compiled for future speed-profile runs.

Test: Flash preopted speed-profile maps.
Test: Confirm ref profile exists.
Test: Close maps, recompile with speed-profile, test the profile was used.
Test: Launch maps, do some stuff until cur profile exists.
Test: Re-compile with speed-profile and confirm cur merged over ref correctly.

Bug: 38032017
Change-Id: I13f4c7eecca1feb2ab41299946828ffa4e59df7f
parent 4bfb604d
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -310,6 +310,16 @@ public class Installer extends SystemService {
        }
    }

    public boolean copySystemProfile(String systemProfile, int uid, String packageName)
            throws InstallerException {
        if (!checkBeforeRemote()) return false;
        try {
            return mInstalld.copySystemProfile(systemProfile, uid, packageName);
        } catch (Exception e) {
            throw InstallerException.from(e);
        }
    }

    public void idmap(String targetApkPath, String overlayApkPath, int uid)
            throws InstallerException {
        if (!checkBeforeRemote()) return;
+28 −0
Original line number Diff line number Diff line
@@ -8687,6 +8687,13 @@ public class PackageManagerService extends IPackageManager.Stub
        MetricsLogger.histogram(mContext, "opt_dialog_time_s", elapsedTimeSeconds);
    }
    /*
     * Return the prebuilt profile path given a package base code path.
     */
    private static String getPrebuildProfilePath(PackageParser.Package pkg) {
        return pkg.baseCodePath + ".prof";
    }
    /**
     * Performs dexopt on the set of packages in {@code packages} and returns an int array
     * containing statistics about the invocation. The array consists of three elements,
@@ -8705,6 +8712,27 @@ public class PackageManagerService extends IPackageManager.Stub
        for (PackageParser.Package pkg : pkgs) {
            numberOfPackagesVisited++;
            if ((isFirstBoot() || isUpgrade()) && isSystemApp(pkg)) {
                // Copy over initial preopt profiles since we won't get any JIT samples for methods
                // that are already compiled.
                File profileFile = new File(getPrebuildProfilePath(pkg));
                // Copy profile if it exists.
                if (profileFile.exists()) {
                    try {
                        // We could also do this lazily before calling dexopt in
                        // PackageDexOptimizer to prevent this happening on first boot. The issue
                        // is that we don't have a good way to say "do this only once".
                        if (!mInstaller.copySystemProfile(profileFile.getAbsolutePath(),
                                pkg.applicationInfo.uid, pkg.packageName)) {
                            Log.e(TAG, "Installer failed to copy system profile!");
                        }
                    } catch (Exception e) {
                        Log.e(TAG, "Failed to copy profile " + profileFile.getAbsolutePath() + " ",
                                e);
                    }
                }
            }
            if (!PackageDexOptimizer.canOptimizePackage(pkg)) {
                if (DEBUG_DEXOPT) {
                    Log.i(TAG, "Skipping update of of non-optimizable app " + pkg.packageName);