Loading services/core/java/com/android/server/pm/PackageDexOptimizer.java +2 −1 Original line number Diff line number Diff line Loading @@ -273,7 +273,8 @@ public class PackageDexOptimizer { options.getCompilationReason(), newResult, ArtStatsLogUtils.getApkType(path), dexCodeIsa); dexCodeIsa, path); } finally { Trace.traceEnd(Trace.TRACE_TAG_PACKAGE_MANAGER); } Loading services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java +45 −1 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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, Loading @@ -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, Loading @@ -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; Loading services/tests/servicestests/src/com/android/server/pm/dex/ArtStatsLogUtilsTest.java +20 −5 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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, Loading Loading
services/core/java/com/android/server/pm/PackageDexOptimizer.java +2 −1 Original line number Diff line number Diff line Loading @@ -273,7 +273,8 @@ public class PackageDexOptimizer { options.getCompilationReason(), newResult, ArtStatsLogUtils.getApkType(path), dexCodeIsa); dexCodeIsa, path); } finally { Trace.traceEnd(Trace.TRACE_TAG_PACKAGE_MANAGER); } Loading
services/core/java/com/android/server/pm/dex/ArtStatsLogUtils.java +45 −1 Original line number Diff line number Diff line Loading @@ -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. */ Loading Loading @@ -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, Loading @@ -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, Loading @@ -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; Loading
services/tests/servicestests/src/com/android/server/pm/dex/ArtStatsLogUtilsTest.java +20 −5 Original line number Diff line number Diff line Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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. Loading Loading @@ -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, Loading