Merge "Convert compilation reason and filter to int-enum before logging" into pi-dev

This commit is contained in:
TreeHugger Robot
2018-03-28 20:35:37 +00:00
committed by Android (Google) Code Review
4 changed files with 114 additions and 14 deletions

View File

@@ -1347,10 +1347,10 @@ message AppStartChanged {
optional string launch_token = 13;
// The compiler filter used when when the package was optimized.
optional string package_optimization_compilation_filter = 14;
optional int32 package_optimization_compilation_filter = 14;
// The reason why the package was optimized.
optional string package_optimization_compilation_reason = 15;
optional int32 package_optimization_compilation_reason = 15;
}
message AppStartCancelChanged {

View File

@@ -22,19 +22,19 @@ package android.content.pm.dex;
* @hide
*/
public class PackageOptimizationInfo {
private final String mCompilationFilter;
private final String mCompilationReason;
private final int mCompilationFilter;
private final int mCompilationReason;
public PackageOptimizationInfo(String compilerFilter, String compilationReason) {
public PackageOptimizationInfo(int compilerFilter, int compilationReason) {
this.mCompilationReason = compilationReason;
this.mCompilationFilter = compilerFilter;
}
public String getCompilationReason() {
public int getCompilationReason() {
return mCompilationReason;
}
public String getCompilationFilter() {
public int getCompilationFilter() {
return mCompilationFilter;
}
@@ -42,6 +42,6 @@ public class PackageOptimizationInfo {
* Create a default optimization info object for the case when we have no information.
*/
public static PackageOptimizationInfo createWithNoInfo() {
return new PackageOptimizationInfo("no-info", "no-info");
return new PackageOptimizationInfo(-1, -1);
}
}

View File

@@ -25,7 +25,7 @@ import dalvik.system.DexFile;
*/
public class PackageManagerServiceCompilerMapping {
// Names for compilation reasons.
static final String REASON_STRINGS[] = {
public static final String REASON_STRINGS[] = {
"first-boot", "boot", "install", "bg-dexopt", "ab-ota", "inactive", "shared"
};

View File

@@ -27,19 +27,18 @@ import android.content.pm.dex.ArtManager;
import android.content.pm.dex.ArtManager.ProfileType;
import android.content.pm.dex.ArtManagerInternal;
import android.content.pm.dex.DexMetadataHelper;
import android.content.pm.dex.ISnapshotRuntimeProfileCallback;
import android.content.pm.dex.PackageOptimizationInfo;
import android.os.Binder;
import android.os.Build;
import android.os.Handler;
import android.os.ParcelFileDescriptor;
import android.os.RemoteException;
import android.content.pm.dex.ISnapshotRuntimeProfileCallback;
import android.os.SystemProperties;
import android.os.UserHandle;
import android.system.Os;
import android.util.ArrayMap;
import android.util.Slog;
import com.android.internal.annotations.GuardedBy;
import com.android.internal.os.BackgroundThread;
import com.android.internal.util.ArrayUtils;
@@ -47,9 +46,8 @@ import com.android.internal.util.Preconditions;
import com.android.server.LocalServices;
import com.android.server.pm.Installer;
import com.android.server.pm.Installer.InstallerException;
import com.android.server.pm.PackageManagerServiceCompilerMapping;
import dalvik.system.DexFile;
import dalvik.system.VMRuntime;
import java.io.File;
import java.io.FileNotFoundException;
@@ -88,6 +86,10 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
private final Handler mHandler;
static {
verifyTronLoggingConstants();
}
public ArtManagerService(IPackageManager pm, Installer installer, Object installLock) {
mPackageManager = pm;
mInstaller = installer;
@@ -423,6 +425,100 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
return result;
}
// Constants used for logging compilation filter to TRON.
// DO NOT CHANGE existing values.
//
// NOTE: '-1' value is reserved for the case where we cannot produce a valid
// PackageOptimizationInfo because the ArtManagerInternal is not ready to be used by the
// ActivityMetricsLoggers.
private static final int TRON_COMPILATION_FILTER_ERROR = 0;
private static final int TRON_COMPILATION_FILTER_UNKNOWN = 1;
private static final int TRON_COMPILATION_FILTER_ASSUMED_VERIFIED = 2;
private static final int TRON_COMPILATION_FILTER_EXTRACT = 3;
private static final int TRON_COMPILATION_FILTER_VERIFY = 4;
private static final int TRON_COMPILATION_FILTER_QUICKEN = 5;
private static final int TRON_COMPILATION_FILTER_SPACE_PROFILE = 6;
private static final int TRON_COMPILATION_FILTER_SPACE = 7;
private static final int TRON_COMPILATION_FILTER_SPEED_PROFILE = 8;
private static final int TRON_COMPILATION_FILTER_SPEED = 9;
private static final int TRON_COMPILATION_FILTER_EVERYTHING_PROFILE = 10;
private static final int TRON_COMPILATION_FILTER_EVERYTHING = 11;
private static final int TRON_COMPILATION_FILTER_FAKE_RUN_FROM_APK = 12;
private static final int TRON_COMPILATION_FILTER_FAKE_RUN_FROM_APK_FALLBACK = 13;
private static final int TRON_COMPILATION_FILTER_FAKE_RUN_FROM_VDEX_FALLBACK = 14;
// Constants used for logging compilation reason to TRON.
// DO NOT CHANGE existing values.
//
// NOTE: '-1' value is reserved for the case where we cannot produce a valid
// PackageOptimizationInfo because the ArtManagerInternal is not ready to be used by the
// ActivityMetricsLoggers.
private static final int TRON_COMPILATION_REASON_ERROR = 0;
private static final int TRON_COMPILATION_REASON_UNKNOWN = 1;
private static final int TRON_COMPILATION_REASON_FIRST_BOOT = 2;
private static final int TRON_COMPILATION_REASON_BOOT = 3;
private static final int TRON_COMPILATION_REASON_INSTALL = 4;
private static final int TRON_COMPILATION_REASON_BG_DEXOPT = 5;
private static final int TRON_COMPILATION_REASON_AB_OTA = 6;
private static final int TRON_COMPILATION_REASON_INACTIVE = 7;
private static final int TRON_COMPILATION_REASON_SHARED = 8;
/**
* Convert the compilation reason to an int suitable to be logged to TRON.
*/
private static int getCompilationReasonTronValue(String compilationReason) {
switch (compilationReason) {
case "unknown" : return TRON_COMPILATION_REASON_UNKNOWN;
case "error" : return TRON_COMPILATION_REASON_ERROR;
case "first-boot" : return TRON_COMPILATION_REASON_FIRST_BOOT;
case "boot" : return TRON_COMPILATION_REASON_BOOT;
case "install" : return TRON_COMPILATION_REASON_INSTALL;
case "bg-dexopt" : return TRON_COMPILATION_REASON_BG_DEXOPT;
case "ab-ota" : return TRON_COMPILATION_REASON_AB_OTA;
case "inactive" : return TRON_COMPILATION_REASON_INACTIVE;
case "shared" : return TRON_COMPILATION_REASON_SHARED;
default: return TRON_COMPILATION_REASON_UNKNOWN;
}
}
/**
* Convert the compilation filter to an int suitable to be logged to TRON.
*/
private static int getCompilationFilterTronValue(String compilationFilter) {
switch (compilationFilter) {
case "error" : return TRON_COMPILATION_FILTER_ERROR;
case "unknown" : return TRON_COMPILATION_FILTER_UNKNOWN;
case "assume-verified" : return TRON_COMPILATION_FILTER_ASSUMED_VERIFIED;
case "extract" : return TRON_COMPILATION_FILTER_EXTRACT;
case "verify" : return TRON_COMPILATION_FILTER_VERIFY;
case "quicken" : return TRON_COMPILATION_FILTER_QUICKEN;
case "space-profile" : return TRON_COMPILATION_FILTER_SPACE_PROFILE;
case "space" : return TRON_COMPILATION_FILTER_SPACE;
case "speed-profile" : return TRON_COMPILATION_FILTER_SPEED_PROFILE;
case "speed" : return TRON_COMPILATION_FILTER_SPEED;
case "everything-profile" : return TRON_COMPILATION_FILTER_EVERYTHING_PROFILE;
case "everything" : return TRON_COMPILATION_FILTER_EVERYTHING;
case "run-from-apk" : return TRON_COMPILATION_FILTER_FAKE_RUN_FROM_APK;
case "run-from-apk-fallback" :
return TRON_COMPILATION_FILTER_FAKE_RUN_FROM_APK_FALLBACK;
case "run-from-vdex-fallback" :
return TRON_COMPILATION_FILTER_FAKE_RUN_FROM_VDEX_FALLBACK;
default: return TRON_COMPILATION_FILTER_UNKNOWN;
}
}
private static void verifyTronLoggingConstants() {
for (int i = 0; i < PackageManagerServiceCompilerMapping.REASON_STRINGS.length; i++) {
String reason = PackageManagerServiceCompilerMapping.REASON_STRINGS[i];
int value = getCompilationReasonTronValue(reason);
if (value == TRON_COMPILATION_REASON_ERROR
|| value == TRON_COMPILATION_REASON_UNKNOWN) {
throw new IllegalArgumentException("Compilation reason not configured for TRON "
+ "logging: " + reason);
}
}
}
private class ArtManagerInternalImpl extends ArtManagerInternal {
@Override
public PackageOptimizationInfo getPackageOptimizationInfo(
@@ -445,7 +541,11 @@ public class ArtManagerService extends android.content.pm.dex.IArtManager.Stub {
compilationReason = "error";
}
return new PackageOptimizationInfo(compilationFilter, compilationReason);
int compilationFilterTronValue = getCompilationFilterTronValue(compilationFilter);
int compilationReasonTronValue = getCompilationReasonTronValue(compilationReason);
return new PackageOptimizationInfo(
compilationFilterTronValue, compilationReasonTronValue);
}
}
}