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

Commit a3e895e6 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "Add measurement for dex size." am: bdcda2cb

Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/1648807

Change-Id: Ibeef0e1d96d2fd8cc7e4f02a5aa9aaf12378de0d
parents 7825cff2 bdcda2cb
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -273,7 +273,8 @@ public class PackageDexOptimizer {
                                options.getCompilationReason(),
                                newResult,
                                ArtStatsLogUtils.getApkType(path),
                                dexCodeIsa);
                                dexCodeIsa,
                                path);
                    } finally {
                        Trace.traceEnd(Trace.TRACE_TAG_PACKAGE_MANAGER);
                    }
+45 −1
Original line number Diff line number Diff line
@@ -32,6 +32,8 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.zip.ZipEntry;

/** Utils class to report ART metrics to statsd. */
@@ -150,7 +152,8 @@ public class ArtStatsLogUtils {
            int compilationReason,
            int result,
            int apkType,
            String isa) {
            String isa,
            String apkPath) {
        int dexMetadataType = getDexMetadataType(dexMetadataPath);
        logger.write(
                sessionId,
@@ -162,6 +165,16 @@ public class ArtStatsLogUtils {
                dexMetadataType,
                apkType,
                isa);
        logger.write(
                sessionId,
                uid,
                compilationReason,
                compilerFilter,
                ArtStatsLog.ART_DATUM_REPORTED__KIND__ART_DATUM_DEX2OAT_DEX_CODE_BYTES,
                getDexBytes(apkPath),
                dexMetadataType,
                apkType,
                isa);
        logger.write(
                sessionId,
                uid,
@@ -181,6 +194,37 @@ public class ArtStatsLogUtils {
        return ArtStatsLog.ART_DATUM_REPORTED__APK_TYPE__ART_APK_TYPE_SPLIT;
    }

    private static long getDexBytes(String apkPath) {
        StrictJarFile jarFile = null;
        long dexBytes = 0;
        try {
            jarFile = new StrictJarFile(apkPath,
                    /*verify=*/ false,
                    /*signatureSchemeRollbackProtectionsEnforced=*/ false);
            Iterator<ZipEntry> it = jarFile.iterator();
            Pattern p = Pattern.compile("classes(\\d)*[.]dex");
            Matcher m = p.matcher("");
            while (it.hasNext()) {
                ZipEntry entry = it.next();
                m.reset(entry.getName());
                if (m.matches()) {
                    dexBytes += entry.getSize();
                }
            }
            return dexBytes;
        } catch (IOException ignore) {
            Slog.e(TAG, "Error when parsing APK " + apkPath);
            return -1L;
        } finally {
            try {
                if (jarFile != null) {
                    jarFile.close();
                }
            } catch (IOException ignore) {
            }
        }
    }

    private static int getDexMetadataType(String dexMetadataPath) {
        if (dexMetadataPath == null) {
            return ArtStatsLog.ART_DATUM_REPORTED__DEX_METADATA_TYPE__ART_DEX_METADATA_TYPE_NONE;
+20 −5
Original line number Diff line number Diff line
@@ -108,7 +108,8 @@ public final class ArtStatsLogUtilsTest {
                    COMPILATION_REASON,
                    RESULT_CODE,
                    ArtStatsLog.ART_DATUM_REPORTED__APK_TYPE__ART_APK_TYPE_BASE,
                    INSTRUCTION_SET);
                    INSTRUCTION_SET,
                    apk.toString());

            // Assert
            verifyWrites(ArtStatsLog.
@@ -139,7 +140,8 @@ public final class ArtStatsLogUtilsTest {
                    COMPILATION_REASON,
                    RESULT_CODE,
                    ArtStatsLog.ART_DATUM_REPORTED__APK_TYPE__ART_APK_TYPE_BASE,
                    INSTRUCTION_SET);
                    INSTRUCTION_SET,
                    apk.toString());

            // Assert
            verifyWrites(ArtStatsLog.
@@ -170,7 +172,8 @@ public final class ArtStatsLogUtilsTest {
                    COMPILATION_REASON,
                    RESULT_CODE,
                    ArtStatsLog.ART_DATUM_REPORTED__APK_TYPE__ART_APK_TYPE_BASE,
                    INSTRUCTION_SET);
                    INSTRUCTION_SET,
                    apk.toString());

            // Assert
            verifyWrites(ArtStatsLog.
@@ -199,7 +202,8 @@ public final class ArtStatsLogUtilsTest {
                    COMPILATION_REASON,
                    RESULT_CODE,
                    ArtStatsLog.ART_DATUM_REPORTED__APK_TYPE__ART_APK_TYPE_BASE,
                    INSTRUCTION_SET);
                    INSTRUCTION_SET,
                    apk.toString());

            // Assert
            verifyWrites(ArtStatsLog.
@@ -229,7 +233,8 @@ public final class ArtStatsLogUtilsTest {
                    COMPILATION_REASON,
                    RESULT_CODE,
                    ArtStatsLog.ART_DATUM_REPORTED__APK_TYPE__ART_APK_TYPE_BASE,
                    INSTRUCTION_SET);
                    INSTRUCTION_SET,
                    apk.toString());

            // Assert
            verifyWrites(ArtStatsLog.
@@ -262,6 +267,16 @@ public final class ArtStatsLogUtilsTest {
                dexMetadataType,
                ArtStatsLog.ART_DATUM_REPORTED__APK_TYPE__ART_APK_TYPE_BASE,
                INSTRUCTION_SET);
        inorder.verify(mockLogger).write(
                SESSION_ID,
                UID,
                COMPILATION_REASON,
                COMPILER_FILTER,
                ArtStatsLog.ART_DATUM_REPORTED__KIND__ART_DATUM_DEX2OAT_DEX_CODE_BYTES,
                DEX_CONTENT.length,
                dexMetadataType,
                ArtStatsLog.ART_DATUM_REPORTED__APK_TYPE__ART_APK_TYPE_BASE,
                INSTRUCTION_SET);
        inorder.verify(mockLogger).write(
                SESSION_ID,
                UID,