Pass --top-k-profile-threshold to dex2oat if available.

Also, don't pass --profile-file if the file is empty.
Bug: 12877748

Change-Id: I587d198e64da709930e2cea50a87fed1525281e5
This commit is contained in:
Calin Juravle 2014-06-06 16:58:43 +01:00
parent 57c69c3964
commit 4fdff46166

View File

@ -622,12 +622,11 @@ static void run_dex2oat(int zip_fd, int oat_fd, const char* input_file_name,
const char* output_file_name, const char *pkgname, const char *instruction_set)
{
char dex2oat_flags[PROPERTY_VALUE_MAX];
property_get("dalvik.vm.dex2oat-flags", dex2oat_flags, "");
bool have_dex2oat_flags = property_get("dalvik.vm.dex2oat-flags", dex2oat_flags, NULL) > 0;
ALOGV("dalvik.vm.dex2oat-flags=%s\n", dex2oat_flags);
char profiler_prop[PROPERTY_VALUE_MAX];
bool profiler = property_get("dalvik.vm.profiler", profiler_prop, "0")
&& (profiler_prop[0] == '1');
char prop_buf[PROPERTY_VALUE_MAX];
bool profiler = (property_get("dalvik.vm.profiler", prop_buf, "0") > 0) && (prop_buf[0] == '1');
static const char* DEX2OAT_BIN = "/system/bin/dex2oat";
static const int MAX_INT_LEN = 12; // '-'+10dig+'\0' -OR- 0x+8dig
@ -643,8 +642,9 @@ static void run_dex2oat(int zip_fd, int oat_fd, const char* input_file_name,
char zip_location_arg[strlen("--zip-location=") + PKG_PATH_MAX];
char oat_fd_arg[strlen("--oat-fd=") + MAX_INT_LEN];
char oat_location_arg[strlen("--oat-name=") + PKG_PATH_MAX];
char profile_file_arg[strlen("--profile-file=") + PKG_PATH_MAX];
char instruction_set_arg[strlen("--instruction-set=") + MAX_INSTRUCTION_SET_LEN];
char profile_file_arg[strlen("--profile-file=") + PKG_PATH_MAX];
char top_k_profile_threshold_arg[strlen("--top-k-profile-threshold=") + PROPERTY_VALUE_MAX];
sprintf(zip_fd_arg, "--zip-fd=%d", zip_fd);
sprintf(zip_location_arg, "--zip-location=%s", input_file_name);
@ -652,27 +652,49 @@ static void run_dex2oat(int zip_fd, int oat_fd, const char* input_file_name,
sprintf(oat_location_arg, "--oat-location=%s", output_file_name);
sprintf(instruction_set_arg, "--instruction-set=%s", instruction_set);
bool have_profile_file = false;
bool have_top_k_profile_threshold = false;
if (profiler && (strcmp(pkgname, "*") != 0)) {
char profile_file[PKG_PATH_MAX];
snprintf(profile_file, sizeof(profile_file), "%s/%s",
DALVIK_CACHE_PREFIX "profiles", pkgname);
struct stat st;
if (stat(profile_file, &st) == -1) {
strcpy(profile_file_arg, "--no-profile-file");
} else {
if ((stat(profile_file, &st) == 0) && (st.st_size > 0)) {
sprintf(profile_file_arg, "--profile-file=%s", profile_file);
have_profile_file = true;
if (property_get("dalvik.vm.profile.top-k-thr", prop_buf, NULL) > 0) {
snprintf(top_k_profile_threshold_arg, sizeof(top_k_profile_threshold_arg),
"--top-k-profile-threshold=%s", prop_buf);
have_top_k_profile_threshold = true;
}
}
} else {
strcpy(profile_file_arg, "--no-profile-file");
}
ALOGV("Running %s in=%s out=%s\n", DEX2OAT_BIN, input_file_name, output_file_name);
execl(DEX2OAT_BIN, DEX2OAT_BIN,
zip_fd_arg, zip_location_arg,
oat_fd_arg, oat_location_arg,
profile_file_arg, instruction_set_arg,
strlen(dex2oat_flags) > 0 ? dex2oat_flags : NULL,
(char*) NULL);
char* argv[7 // program name, mandatory arguments and the final NULL
+ (have_profile_file ? 1 : 0)
+ (have_top_k_profile_threshold ? 1 : 0)
+ (have_dex2oat_flags ? 1 : 0)];
int i = 0;
argv[i++] = (char*)DEX2OAT_BIN;
argv[i++] = zip_fd_arg;
argv[i++] = zip_location_arg;
argv[i++] = oat_fd_arg;
argv[i++] = oat_location_arg;
argv[i++] = instruction_set_arg;
if (have_profile_file) {
argv[i++] = profile_file_arg;
}
if (have_top_k_profile_threshold) {
argv[i++] = top_k_profile_threshold_arg;
}
if (have_dex2oat_flags) {
argv[i++] = dex2oat_flags;
}
argv[i] = NULL;
execv(DEX2OAT_BIN, (char* const *)argv);
ALOGE("execl(%s) failed: %s\n", DEX2OAT_BIN, strerror(errno));
}