diff options
| -rw-r--r-- | runtime/jit/offline_profiling_info.cc | 4 | ||||
| -rw-r--r-- | runtime/native/dalvik_system_VMRuntime.cc | 14 | ||||
| -rw-r--r-- | runtime/runtime.cc | 26 | ||||
| -rw-r--r-- | runtime/utils.cc | 5 | ||||
| -rw-r--r-- | 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 5dc0e45234..3942b0ba02 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 4b24f821cb..da4a891ff5 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<std::string> 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 4a7ecccc75..6b8f17ddaa 100644 --- a/runtime/runtime.cc +++ b/runtime/runtime.cc @@ -1696,13 +1696,29 @@ void Runtime::SetCalleeSaveMethod(ArtMethod* method, CalleeSaveType type) { void Runtime::RegisterAppInfo(const std::vector<std::string>& 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 ff6b4c0d20..1e1c7e7098 100644 --- a/runtime/utils.cc +++ b/runtime/utils.cc @@ -1446,6 +1446,11 @@ bool Exec(std::vector<std::string>& 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 a07e74c62b..5ceb3b5cd4 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<std::string>& arg_vector, std::string* error_msg); +// Returns true if the file exists. +bool FileExists(const std::string& filename); + class VoidFunctor { public: template <typename A> |