Expose the optimization status of a dex file
Add a method which exposes the optimization status of a dex file based on
its expected runtime behaviour. The method returns the status in an array
[compilation filter, compilation reason].
The method will try to mimic the runtime effect of loading the dex file.
For example, if there is no usable oat file, the compiler filter will be
set to "run-from-apk".
This will enable more accurate performance monitoring of apks.
Test: oat_file_assistant_test
Bug: 73102540
Change-Id: Ida9abef502dcb3fd07e1b0988771fb60e9b2a423
diff --git a/runtime/oat_file_assistant.cc b/runtime/oat_file_assistant.cc
index 15a5954..0170073 100644
--- a/runtime/oat_file_assistant.cc
+++ b/runtime/oat_file_assistant.cc
@@ -1262,4 +1262,27 @@
}
return std::unique_ptr<OatFile>();
}
+
+// TODO(calin): we could provide a more refined status here
+// (e.g. run from uncompressed apk, run with vdex but not oat etc). It will allow us to
+// track more experiments but adds extra complexity.
+void OatFileAssistant::GetOptimizationStatus(
+ const std::string& filename,
+ InstructionSet isa,
+ std::string* out_compilation_filter,
+ std::string* out_compilation_reason) {
+ // Try to load the oat file as we would do at runtime.
+ OatFileAssistant oat_file_assistant(filename.c_str(), isa, true /* load_executable */);
+ std::unique_ptr<OatFile> oat_file = oat_file_assistant.GetBestOatFile();
+
+ if (oat_file == nullptr) {
+ *out_compilation_filter = "run-from-apk";
+ *out_compilation_reason = "unknown";
+ } else {
+ *out_compilation_filter = CompilerFilter::NameOfFilter(oat_file->GetCompilerFilter());
+ const char* reason = oat_file->GetCompilationReason();
+ *out_compilation_reason = reason == nullptr ? "unknown" : reason;
+ }
+}
+
} // namespace art