Add measurement for dex size.

The memory issue is due to the use of regex. Remove that and
add a simple util method to check classes dex.

Bug: 183407097
Test: run via forrest and verify the result https://fusion2.corp.google.com/invocations/99ac3b54-9dea-47aa-9f1a-f33e4a08a048/artifacts
Change-Id: I7ce5278b7fd6baa325e477ebf428b21db544cab6
This commit is contained in:
Yan Wang
2021-03-22 17:37:54 +00:00
parent 07ff79a595
commit 6a97b0686c
3 changed files with 67 additions and 7 deletions

View File

@@ -273,7 +273,8 @@ public class PackageDexOptimizer {
options.getCompilationReason(),
newResult,
ArtStatsLogUtils.getApkType(path),
dexCodeIsa);
dexCodeIsa,
path);
} finally {
Trace.traceEnd(Trace.TRACE_TAG_PACKAGE_MANAGER);
}

View File

@@ -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;

View File

@@ -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,