Add --compilation-reason option to dex2oat
The compilation reason is an optional metadata specifying the reason for
compiling the apk. If specified, the string will be embedded verbatim in
the key value store of the oat file.
This will allow a more precise performance monitoring based on the actual
reason for compilation (e.g. install time vs background dexopt time).
Test: dex2oat_test
Bug: 73102540
Change-Id: I73c7fcc73e37a695f1684d9e282c7cc5be3030f8
diff --git a/runtime/oat.h b/runtime/oat.h
index 8f81010..af14b3e 100644
--- a/runtime/oat.h
+++ b/runtime/oat.h
@@ -45,6 +45,7 @@
static constexpr const char* kClassPathKey = "classpath";
static constexpr const char* kBootClassPathKey = "bootclasspath";
static constexpr const char* kConcurrentCopying = "concurrent-copying";
+ static constexpr const char* kCompilationReasonKey = "compilation-reason";
static constexpr const char kTrueValue[] = "true";
static constexpr const char kFalseValue[] = "false";
diff --git a/runtime/oat_file.cc b/runtime/oat_file.cc
index 600449c..0852da5 100644
--- a/runtime/oat_file.cc
+++ b/runtime/oat_file.cc
@@ -1924,6 +1924,10 @@
return GetOatHeader().GetStoreValueByKey(OatHeader::kClassPathKey);
}
+const char* OatFile::GetCompilationReason() const {
+ return GetOatHeader().GetStoreValueByKey(OatHeader::kCompilationReasonKey);
+}
+
OatFile::OatClass OatFile::FindOatClass(const DexFile& dex_file,
uint16_t class_def_idx,
bool* found) {
diff --git a/runtime/oat_file.h b/runtime/oat_file.h
index 46c692e..802adc3 100644
--- a/runtime/oat_file.h
+++ b/runtime/oat_file.h
@@ -130,6 +130,8 @@
std::string GetClassLoaderContext() const;
+ const char* GetCompilationReason() const;
+
const std::string& GetLocation() const {
return location_;
}