From 5e2b971e468ca73a8e10a120730b3b6f17fad408 Mon Sep 17 00:00:00 2001 From: Calin Juravle Date: Fri, 18 Dec 2015 14:10:00 +0200 Subject: [PATCH] Assume the profile file was created before saving. bug: 26080105 Change-Id: I9969a4abd8533614922076551fcbae2cdf695525 --- runtime/jit/offline_profiling_info.cc | 4 +--- runtime/native/dalvik_system_VMRuntime.cc | 14 ++++++-------- runtime/runtime.cc | 26 +++++++++++++++++++++----- runtime/utils.cc | 5 +++++ runtime/utils.h | 3 +++ 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/runtime/jit/offline_profiling_info.cc b/runtime/jit/offline_profiling_info.cc index 5dc0e4523..3942b0ba0 100644 --- a/runtime/jit/offline_profiling_info.cc +++ b/runtime/jit/offline_profiling_info.cc @@ -77,9 +77,7 @@ static int OpenFile(const std::string& filename, OpenMode open_mode) { break; case READ_WRITE: // TODO(calin) allow the shared uid of the app to access the file. - fd = open(filename.c_str(), - O_CREAT | O_WRONLY | O_TRUNC | O_NOFOLLOW | O_CLOEXEC, - S_IRUSR | S_IWUSR); + fd = open(filename.c_str(), O_WRONLY | O_TRUNC | O_NOFOLLOW | O_CLOEXEC); break; } diff --git a/runtime/native/dalvik_system_VMRuntime.cc b/runtime/native/dalvik_system_VMRuntime.cc index 4b24f821c..da4a891ff 100644 --- a/runtime/native/dalvik_system_VMRuntime.cc +++ b/runtime/native/dalvik_system_VMRuntime.cc @@ -565,8 +565,8 @@ static void VMRuntime_preloadDexCaches(JNIEnv* env, jobject) { */ static void VMRuntime_registerAppInfo(JNIEnv* env, jclass clazz ATTRIBUTE_UNUSED, - jstring pkg_name, - jstring app_dir, + jstring profile_file, + jstring app_dir ATTRIBUTE_UNUSED, // TODO: remove argument jobjectArray code_paths) { std::vector code_paths_vec; int code_paths_length = env->GetArrayLength(code_paths); @@ -577,13 +577,11 @@ static void VMRuntime_registerAppInfo(JNIEnv* env, env->ReleaseStringUTFChars(code_path, raw_code_path); } - const char* raw_app_dir = env->GetStringUTFChars(app_dir, nullptr); - const char* raw_pkg_name = env->GetStringUTFChars(pkg_name, nullptr); - std::string profile_file = StringPrintf("%s/code_cache/%s.prof", raw_app_dir, raw_pkg_name); - env->ReleaseStringUTFChars(pkg_name, raw_pkg_name); - env->ReleaseStringUTFChars(app_dir, raw_app_dir); + const char* raw_profile_file = env->GetStringUTFChars(profile_file, nullptr); + std::string profile_file_str(raw_profile_file); + env->ReleaseStringUTFChars(profile_file, raw_profile_file); - Runtime::Current()->RegisterAppInfo(code_paths_vec, profile_file); + Runtime::Current()->RegisterAppInfo(code_paths_vec, profile_file_str); } static jboolean VMRuntime_isBootClassPathOnDisk(JNIEnv* env, jclass, jstring java_instruction_set) { diff --git a/runtime/runtime.cc b/runtime/runtime.cc index 5c7262932..b7fdcdfc7 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -1685,13 +1685,29 @@ void Runtime::SetCalleeSaveMethod(ArtMethod* method, CalleeSaveType type) { void Runtime::RegisterAppInfo(const std::vector& code_paths, const std::string& profile_output_filename) { - VLOG(profiler) << "Register app with " << profile_output_filename_ + if (jit_.get() == nullptr) { + // We are not JITing. Nothing to do. + return; + } + + VLOG(profiler) << "Register app with " << profile_output_filename << " " << Join(code_paths, ':'); - DCHECK(!profile_output_filename.empty()); - profile_output_filename_ = profile_output_filename; - if (jit_.get() != nullptr && !profile_output_filename.empty() && !code_paths.empty()) { - jit_->StartProfileSaver(profile_output_filename, code_paths); + + if (profile_output_filename.empty()) { + LOG(WARNING) << "JIT profile information will not be recorded: profile filename is empty."; + return; } + if (!FileExists(profile_output_filename)) { + LOG(WARNING) << "JIT profile information will not be recorded: profile file does not exits."; + return; + } + if (code_paths.empty()) { + LOG(WARNING) << "JIT profile information will not be recorded: code paths is empty."; + return; + } + + profile_output_filename_ = profile_output_filename; + jit_->StartProfileSaver(profile_output_filename, code_paths); } // Transaction support. diff --git a/runtime/utils.cc b/runtime/utils.cc index ff6b4c0d2..1e1c7e709 100644 --- a/runtime/utils.cc +++ b/runtime/utils.cc @@ -1446,6 +1446,11 @@ bool Exec(std::vector& arg_vector, std::string* error_msg) { return true; } +bool FileExists(const std::string& filename) { + struct stat buffer; + return stat(filename.c_str(), &buffer) == 0; +} + std::string PrettyDescriptor(Primitive::Type type) { return PrettyDescriptor(Primitive::Descriptor(type)); } diff --git a/runtime/utils.h b/runtime/utils.h index a07e74c62..5ceb3b5cd 100644 --- a/runtime/utils.h +++ b/runtime/utils.h @@ -276,6 +276,9 @@ std::string GetSystemImageFilename(const char* location, InstructionSet isa); // Wrapper on fork/execv to run a command in a subprocess. bool Exec(std::vector& arg_vector, std::string* error_msg); +// Returns true if the file exists. +bool FileExists(const std::string& filename); + class VoidFunctor { public: template -- 2.11.0