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

Commit 612dc02f authored by Narayan Kamath's avatar Narayan Kamath
Browse files

Cherry-pick changes 3496fd and 4ec026 to goog/master.

Change 1/2:
PackageManager : Log stats about the optimizing apps dialog.

Logs the following parameters :
- Total time spent optimizing apps.
- Total number of apps that were dexopted.

TESTED: with adb logcat -b events:
05-04 15:24:16.303  2065  2065 I sysui_action: [402,3]
05-04 15:24:16.303  2065  2065 I sysui_action: [403,34]
05-04 15:24:16.303  2065  2065 I sysui_action: [404,0]
05-04 15:24:16.304  2065  2065 I sysui_action: [405,163]
05-04 15:24:16.304  2065  2065 I sysui_action: [406,12168]

This shows that:
 - 3 apps were optimized
 - 34 apps were skipped
 - 0 apps failed to optimize
 - dialog showed a total of 37 (3 + 34 + 0) apps
 - system has 163 optimizable packages
 - a total of 12.2 seconds was spent in the optimizing apps dialog

bug: 28528058
bug: 28544474

Change 2/2:
Patrially revert 4ec02693.

In preparation for using MetricsLogger.histogram / count. The main
purpose of this change is to remove the (now bogus) action IDs
associated with this logging.

bug: 28528058
bug: 28544474
Change-Id: Ia7d7db416061a3902193d6d0f3b90c3eb7ae8566
parent 8ff6f1de
Loading
Loading
Loading
Loading
+45 −23
Original line number Diff line number Diff line
@@ -7168,42 +7168,61 @@ public class PackageManagerService extends IPackageManager.Stub {
            pkgs = PackageManagerServiceUtils.getPackagesForDexopt(mPackages.values(), this);
        }
        int curr = 0;
        int total = pkgs.size();
        int numberOfPackagesVisited = 0;
        int numberOfPackagesOptimized = 0;
        int numberOfPackagesSkipped = 0;
        int numberOfPackagesFailed = 0;
        final int numberOfPackagesToDexopt = pkgs.size();
        final long startTime = System.nanoTime();
        for (PackageParser.Package pkg : pkgs) {
            curr++;
            numberOfPackagesVisited++;
            if (!PackageDexOptimizer.canOptimizePackage(pkg)) {
                if (DEBUG_DEXOPT) {
                    Log.i(TAG, "Skipping update of of non-optimizable app " + pkg.packageName);
                }
                numberOfPackagesSkipped++;
                continue;
            }
            if (DEBUG_DEXOPT) {
                Log.i(TAG, "Extracting app " + curr + " of " + total + ": " + pkg.packageName);
                Log.i(TAG, "Updating app " + numberOfPackagesVisited + " of " +
                        numberOfPackagesToDexopt + ": " + pkg.packageName);
            }
            if (mIsPreNUpgrade) {
                try {
                    ActivityManagerNative.getDefault().showBootMessage(
                            mContext.getResources().getString(R.string.android_upgrading_apk,
                                    curr, total), true);
                                    numberOfPackagesVisited, numberOfPackagesToDexopt), true);
                } catch (RemoteException e) {
                }
            }
            // checkProfiles is false to avoid merging profiles during boot which
            // might interfere with background compilation (b/28612421).
            // Unfortunately this will also means that "pm.dexopt.boot=speed-profile" will
            // behave differently than "pm.dexopt.bg-dexopt=speed-profile" but that's a
            // trade-off worth doing to save boot time work.
            performDexOpt(pkg.packageName,
            int dexOptStatus = performDexOptTraced(pkg.packageName,
                    null /* instructionSet */,
                    false /* checkProfiles */,
                    causeFirstBoot ? REASON_FIRST_BOOT : REASON_BOOT,
                    true /* checkProfiles */,
                    getCompilerFilterForReason(causeFirstBoot ? REASON_FIRST_BOOT : REASON_BOOT),
                    false /* force */);
            switch (dexOptStatus) {
                case PackageDexOptimizer.DEX_OPT_PERFORMED:
                    numberOfPackagesOptimized++;
                    break;
                case PackageDexOptimizer.DEX_OPT_SKIPPED:
                    numberOfPackagesSkipped++;
                    break;
                case PackageDexOptimizer.DEX_OPT_FAILED:
                    numberOfPackagesFailed++;
                    break;
                default:
                    Log.e(TAG, "Unexpected dexopt return code " + dexOptStatus);
                    break;
            }
        }
        final int elapsedTime = (int) TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        // TODO: Log events using MetricsLogger.histogram / MetricsLogger.count
    }
    @Override
@@ -7220,25 +7239,28 @@ public class PackageManagerService extends IPackageManager.Stub {
    // TODO: this is not used nor needed. Delete it.
    @Override
    public boolean performDexOptIfNeeded(String packageName, String instructionSet) {
        return performDexOptTraced(packageName, instructionSet, false /* checkProfiles */,
                getFullCompilerFilter(), false /* force */);
        int dexOptStatus = performDexOptTraced(packageName, instructionSet,
                false /* checkProfiles */, getFullCompilerFilter(), false /* force */);
        return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
    }
    @Override
    public boolean performDexOpt(String packageName, String instructionSet,
            boolean checkProfiles, int compileReason, boolean force) {
        return performDexOptTraced(packageName, instructionSet, checkProfiles,
        int dexOptStatus = performDexOptTraced(packageName, instructionSet, checkProfiles,
                getCompilerFilterForReason(compileReason), force);
        return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
    }
    @Override
    public boolean performDexOptMode(String packageName, String instructionSet,
            boolean checkProfiles, String targetCompilerFilter, boolean force) {
        return performDexOptTraced(packageName, instructionSet, checkProfiles,
        int dexOptStatus = performDexOptTraced(packageName, instructionSet, checkProfiles,
                targetCompilerFilter, force);
        return dexOptStatus != PackageDexOptimizer.DEX_OPT_FAILED;
    }
    private boolean performDexOptTraced(String packageName, String instructionSet,
    private int performDexOptTraced(String packageName, String instructionSet,
                boolean checkProfiles, String targetCompilerFilter, boolean force) {
        Trace.traceBegin(TRACE_TAG_PACKAGE_MANAGER, "dexopt");
        try {
@@ -7251,14 +7273,15 @@ public class PackageManagerService extends IPackageManager.Stub {
    // Run dexopt on a given package. Returns true if dexopt did not fail, i.e.
    // if the package can now be considered up to date for the given filter.
    private boolean performDexOptInternal(String packageName, String instructionSet,
    private int performDexOptInternal(String packageName, String instructionSet,
                boolean checkProfiles, String targetCompilerFilter, boolean force) {
        PackageParser.Package p;
        final String targetInstructionSet;
        synchronized (mPackages) {
            p = mPackages.get(packageName);
            if (p == null) {
                return false;
                // Package could not be found. Report failure.
                return PackageDexOptimizer.DEX_OPT_FAILED;
            }
            mPackageUsage.write(false);
@@ -7269,9 +7292,8 @@ public class PackageManagerService extends IPackageManager.Stub {
        try {
            synchronized (mInstallLock) {
                final String[] instructionSets = new String[] { targetInstructionSet };
                int result = performDexOptInternalWithDependenciesLI(p, instructionSets,
                        checkProfiles, targetCompilerFilter, force);
                return result != PackageDexOptimizer.DEX_OPT_FAILED;
                return performDexOptInternalWithDependenciesLI(p, instructionSets, checkProfiles,
                        targetCompilerFilter, force);
            }
        } finally {
            Binder.restoreCallingIdentity(callingId);