Report BCP compilation type.
The compilation of BCP now have two cases, and their compilation time
will be very different from each other. This CL adds an enum to
distinguish them. The enum will be used as a dimension in WW and as a
filter on Pitot.
Bug: 269230245
Bug: 279004055
Test: atest art_standalone_odrefresh_tests
Test: -
1. adb shell rm -rf /data/misc/apexdata/com.android.art/dalvik-cache
2. adb shell odrefresh --compile
3. adb shell cat /data/misc/odrefresh/odrefresh-metrics.xml
Change-Id: I142784ec96fdf9855c44d40d7d2bf7ce75443b7f
diff --git a/odrefresh/odr_metrics.cc b/odrefresh/odr_metrics.cc
index 78d6673..a4533d9 100644
--- a/odrefresh/odr_metrics.cc
+++ b/odrefresh/odr_metrics.cc
@@ -93,6 +93,23 @@
}
}
+void OdrMetrics::SetBcpCompilationType(Stage stage, BcpCompilationType type) {
+ switch (stage) {
+ case Stage::kPrimaryBootClasspath:
+ primary_bcp_compilation_type_ = type;
+ break;
+ case Stage::kSecondaryBootClasspath:
+ secondary_bcp_compilation_type_ = type;
+ break;
+ case Stage::kSystemServerClasspath:
+ case Stage::kCheck:
+ case Stage::kComplete:
+ case Stage::kPreparation:
+ case Stage::kUnknown:
+ LOG(FATAL) << "Unexpected stage " << stage_ << " when setting BCP compilation type";
+ }
+}
+
int32_t OdrMetrics::GetFreeSpaceMiB(const std::string& path) {
static constexpr uint32_t kBytesPerMiB = 1024 * 1024;
static constexpr uint64_t kNominalMaximumCacheBytes = 1024 * kBytesPerMiB;
@@ -121,19 +138,21 @@
OdrMetricsRecord OdrMetrics::ToRecord() const {
return {
- .odrefresh_metrics_version = kOdrefreshMetricsVersion,
- .art_apex_version = art_apex_version_,
- .trigger = static_cast<int32_t>(trigger_),
- .stage_reached = static_cast<int32_t>(stage_),
- .status = static_cast<int32_t>(status_),
- .cache_space_free_start_mib = cache_space_free_start_mib_,
- .cache_space_free_end_mib = cache_space_free_end_mib_,
- .primary_bcp_compilation_millis = primary_bcp_compilation_millis_,
- .secondary_bcp_compilation_millis = secondary_bcp_compilation_millis_,
- .system_server_compilation_millis = system_server_compilation_millis_,
- .primary_bcp_dex2oat_result = ConvertExecResult(primary_bcp_dex2oat_result_),
- .secondary_bcp_dex2oat_result = ConvertExecResult(secondary_bcp_dex2oat_result_),
- .system_server_dex2oat_result = ConvertExecResult(system_server_dex2oat_result_),
+ .odrefresh_metrics_version = kOdrefreshMetricsVersion,
+ .art_apex_version = art_apex_version_,
+ .trigger = static_cast<int32_t>(trigger_),
+ .stage_reached = static_cast<int32_t>(stage_),
+ .status = static_cast<int32_t>(status_),
+ .cache_space_free_start_mib = cache_space_free_start_mib_,
+ .cache_space_free_end_mib = cache_space_free_end_mib_,
+ .primary_bcp_compilation_millis = primary_bcp_compilation_millis_,
+ .secondary_bcp_compilation_millis = secondary_bcp_compilation_millis_,
+ .system_server_compilation_millis = system_server_compilation_millis_,
+ .primary_bcp_dex2oat_result = ConvertExecResult(primary_bcp_dex2oat_result_),
+ .secondary_bcp_dex2oat_result = ConvertExecResult(secondary_bcp_dex2oat_result_),
+ .system_server_dex2oat_result = ConvertExecResult(system_server_dex2oat_result_),
+ .primary_bcp_compilation_type = static_cast<int32_t>(primary_bcp_compilation_type_),
+ .secondary_bcp_compilation_type = static_cast<int32_t>(secondary_bcp_compilation_type_),
};
}
diff --git a/odrefresh/odr_metrics.h b/odrefresh/odr_metrics.h
index fe39e07..94414f8 100644
--- a/odrefresh/odr_metrics.h
+++ b/odrefresh/odr_metrics.h
@@ -74,6 +74,14 @@
kMissingArtifacts = 3,
};
+ enum class BcpCompilationType : uint8_t {
+ kUnknown = 0,
+ // Compiles for both the primary boot image and the mainline extension.
+ kPrimaryAndMainline = 1,
+ // Only compiles for the mainline extension.
+ kMainline = 2,
+ };
+
explicit OdrMetrics(const std::string& cache_directory,
const std::string& metrics_file = kOdrefreshMetricsFile);
~OdrMetrics();
@@ -115,6 +123,9 @@
int64_t compilation_time,
const std::optional<ExecResult>& dex2oat_result);
+ // Sets the BCP compilation type.
+ void SetBcpCompilationType(Stage stage, BcpCompilationType type);
+
// Captures the current free space as the end free space.
void CaptureSpaceFreeEnd();
@@ -152,6 +163,8 @@
// not invoked.
std::optional<ExecResult> primary_bcp_dex2oat_result_;
+ BcpCompilationType primary_bcp_compilation_type_ = BcpCompilationType::kUnknown;
+
// The total time spent on compiling secondary BCP.
int32_t secondary_bcp_compilation_millis_ = 0;
@@ -159,6 +172,8 @@
// is not invoked.
std::optional<ExecResult> secondary_bcp_dex2oat_result_;
+ BcpCompilationType secondary_bcp_compilation_type_ = BcpCompilationType::kUnknown;
+
// The total time spent on compiling system server.
int32_t system_server_compilation_millis_ = 0;
diff --git a/odrefresh/odr_metrics_record.cc b/odrefresh/odr_metrics_record.cc
index 14ccb0c..74a69cc 100644
--- a/odrefresh/odr_metrics_record.cc
+++ b/odrefresh/odr_metrics_record.cc
@@ -141,6 +141,8 @@
primary_bcp_dex2oat_result = OR_RETURN(ReadExecResult(metrics, "primary_bcp_dex2oat_result"));
secondary_bcp_dex2oat_result = OR_RETURN(ReadExecResult(metrics, "secondary_bcp_dex2oat_result"));
system_server_dex2oat_result = OR_RETURN(ReadExecResult(metrics, "system_server_dex2oat_result"));
+ primary_bcp_compilation_type = OR_RETURN(ReadInt32(metrics, "primary_bcp_compilation_type"));
+ secondary_bcp_compilation_type = OR_RETURN(ReadInt32(metrics, "secondary_bcp_compilation_type"));
return {};
}
@@ -164,6 +166,8 @@
AddResult(metrics, "primary_bcp_dex2oat_result", primary_bcp_dex2oat_result);
AddResult(metrics, "secondary_bcp_dex2oat_result", secondary_bcp_dex2oat_result);
AddResult(metrics, "system_server_dex2oat_result", system_server_dex2oat_result);
+ AddMetric(metrics, "primary_bcp_compilation_type", primary_bcp_compilation_type);
+ AddMetric(metrics, "secondary_bcp_compilation_type", secondary_bcp_compilation_type);
tinyxml2::XMLError result = xml_document.SaveFile(filename.data(), /*compact=*/true);
if (result == tinyxml2::XML_SUCCESS) {
diff --git a/odrefresh/odr_metrics_record.h b/odrefresh/odr_metrics_record.h
index eb3ef9e..41dea3e 100644
--- a/odrefresh/odr_metrics_record.h
+++ b/odrefresh/odr_metrics_record.h
@@ -72,6 +72,8 @@
Dex2OatExecResult primary_bcp_dex2oat_result;
Dex2OatExecResult secondary_bcp_dex2oat_result;
Dex2OatExecResult system_server_dex2oat_result;
+ int32_t primary_bcp_compilation_type;
+ int32_t secondary_bcp_compilation_type;
// Reads a `MetricsRecord` from an XML file.
// Returns an error if the XML document was not found or parsed correctly.
diff --git a/odrefresh/odr_metrics_record_test.cc b/odrefresh/odr_metrics_record_test.cc
index a6bfb8b..8c24156 100644
--- a/odrefresh/odr_metrics_record_test.cc
+++ b/odrefresh/odr_metrics_record_test.cc
@@ -91,6 +91,8 @@
expected.primary_bcp_dex2oat_result = OdrMetricsRecord::Dex2OatExecResult(1, -1, 0);
expected.secondary_bcp_dex2oat_result = OdrMetricsRecord::Dex2OatExecResult(2, 15, 0);
expected.system_server_dex2oat_result = OdrMetricsRecord::Dex2OatExecResult(3, -1, 9);
+ expected.primary_bcp_compilation_type = 0x82837192;
+ expected.secondary_bcp_compilation_type = 0x91827312;
ASSERT_THAT(expected.WriteToFile(file_path_), Ok());
@@ -123,6 +125,8 @@
actual.system_server_dex2oat_result.exit_code);
ASSERT_EQ(expected.system_server_dex2oat_result.signal,
actual.system_server_dex2oat_result.signal);
+ ASSERT_EQ(expected.primary_bcp_compilation_type, actual.primary_bcp_compilation_type);
+ ASSERT_EQ(expected.secondary_bcp_compilation_type, actual.secondary_bcp_compilation_type);
ASSERT_EQ(0, memcmp(&expected, &actual, sizeof(expected)));
}
diff --git a/odrefresh/odr_metrics_test.cc b/odrefresh/odr_metrics_test.cc
index 5396d5d..64f3c59 100644
--- a/odrefresh/odr_metrics_test.cc
+++ b/odrefresh/odr_metrics_test.cc
@@ -19,6 +19,7 @@
#include <unistd.h>
#include <chrono>
+#include <cstdint>
#include <fstream>
#include <memory>
#include <string>
@@ -101,15 +102,21 @@
OdrMetrics::Stage::kPrimaryBootClasspath,
100,
ExecResult{.status = ExecResult::Status::kExited, .exit_code = 0, .signal = 0});
+ metrics.SetBcpCompilationType(OdrMetrics::Stage::kPrimaryBootClasspath,
+ OdrMetrics::BcpCompilationType::kMainline);
OdrMetricsRecord record = metrics.ToRecord();
EXPECT_EQ(record.primary_bcp_compilation_millis, 100);
EXPECT_EQ(record.primary_bcp_dex2oat_result.status, ExecResult::Status::kExited);
EXPECT_EQ(record.primary_bcp_dex2oat_result.exit_code, 0);
EXPECT_EQ(record.primary_bcp_dex2oat_result.signal, 0);
+ EXPECT_EQ(record.primary_bcp_compilation_type,
+ static_cast<int32_t>(OdrMetrics::BcpCompilationType::kMainline));
EXPECT_EQ(record.secondary_bcp_compilation_millis, 0);
EXPECT_EQ(record.secondary_bcp_dex2oat_result.status, kExecResultNotRun);
+ EXPECT_EQ(record.secondary_bcp_compilation_type,
+ static_cast<int32_t>(OdrMetrics::BcpCompilationType::kUnknown));
EXPECT_EQ(record.system_server_compilation_millis, 0);
EXPECT_EQ(record.system_server_dex2oat_result.status, kExecResultNotRun);
@@ -130,21 +137,29 @@
OdrMetrics::Stage::kPrimaryBootClasspath,
100,
ExecResult{.status = ExecResult::Status::kExited, .exit_code = 0, .signal = 0});
+ metrics.SetBcpCompilationType(OdrMetrics::Stage::kPrimaryBootClasspath,
+ OdrMetrics::BcpCompilationType::kMainline);
metrics.SetDex2OatResult(
OdrMetrics::Stage::kSecondaryBootClasspath,
200,
ExecResult{.status = ExecResult::Status::kTimedOut, .exit_code = 3, .signal = 0});
+ metrics.SetBcpCompilationType(OdrMetrics::Stage::kSecondaryBootClasspath,
+ OdrMetrics::BcpCompilationType::kPrimaryAndMainline);
OdrMetricsRecord record = metrics.ToRecord();
EXPECT_EQ(record.primary_bcp_compilation_millis, 100);
EXPECT_EQ(record.primary_bcp_dex2oat_result.status, ExecResult::Status::kExited);
EXPECT_EQ(record.primary_bcp_dex2oat_result.exit_code, 0);
EXPECT_EQ(record.primary_bcp_dex2oat_result.signal, 0);
+ EXPECT_EQ(record.primary_bcp_compilation_type,
+ static_cast<int32_t>(OdrMetrics::BcpCompilationType::kMainline));
EXPECT_EQ(record.secondary_bcp_compilation_millis, 200);
EXPECT_EQ(record.secondary_bcp_dex2oat_result.status, ExecResult::Status::kTimedOut);
EXPECT_EQ(record.secondary_bcp_dex2oat_result.exit_code, 3);
EXPECT_EQ(record.secondary_bcp_dex2oat_result.signal, 0);
+ EXPECT_EQ(record.secondary_bcp_compilation_type,
+ static_cast<int32_t>(OdrMetrics::BcpCompilationType::kPrimaryAndMainline));
EXPECT_EQ(record.system_server_compilation_millis, 0);
EXPECT_EQ(record.system_server_dex2oat_result.status, kExecResultNotRun);
diff --git a/odrefresh/odr_statslog_android.cc b/odrefresh/odr_statslog_android.cc
index 29fcf49..5e25929 100644
--- a/odrefresh/odr_statslog_android.cc
+++ b/odrefresh/odr_statslog_android.cc
@@ -133,6 +133,8 @@
return false;
}
+ // TODO(b/279004055): Translate BCP compilation types.
+
return true;
}
@@ -146,6 +148,7 @@
// Write values to statsd. The order of values passed is the same as the order of the
// fields in OdrMetricsRecord.
+ // TODO(b/279004055): Write BCP compilation types.
int bytes_written = art::metrics::statsd::stats_write(
metrics::statsd::ODREFRESH_REPORTED,
record.art_apex_version,
diff --git a/odrefresh/odrefresh.cc b/odrefresh/odrefresh.cc
index cbe8c76..55a6720 100644
--- a/odrefresh/odrefresh.cc
+++ b/odrefresh/odrefresh.cc
@@ -632,6 +632,17 @@
return count;
}
+OdrMetrics::BcpCompilationType BootImages::GetTypeForMetrics() const {
+ if (primary_boot_image && boot_image_mainline_extension) {
+ return OdrMetrics::BcpCompilationType::kPrimaryAndMainline;
+ }
+ if (boot_image_mainline_extension) {
+ return OdrMetrics::BcpCompilationType::kMainline;
+ }
+ LOG(FATAL) << "Unexpected BCP compilation type";
+ UNREACHABLE();
+}
+
int CompilationOptions::CompilationUnitCount() const {
int count = 0;
for (const auto& [isa, boot_images] : boot_images_to_generate_for_isas) {
@@ -2034,6 +2045,7 @@
CompilationResult bcp_result =
CompileBootClasspath(staging_dir, isa, boot_images_to_generate, advance_animation_progress);
metrics.SetDex2OatResult(stage, bcp_result.elapsed_time_ms, bcp_result.dex2oat_result);
+ metrics.SetBcpCompilationType(stage, boot_images_to_generate.GetTypeForMetrics());
if (!bcp_result.IsOk()) {
if (isa == system_server_isa) {
system_server_isa_failed = true;
diff --git a/odrefresh/odrefresh.h b/odrefresh/odrefresh.h
index 69a7a8e..93812eb 100644
--- a/odrefresh/odrefresh.h
+++ b/odrefresh/odrefresh.h
@@ -48,6 +48,8 @@
bool boot_image_mainline_extension : 1;
int Count() const;
+
+ OdrMetrics::BcpCompilationType GetTypeForMetrics() const;
};
struct CompilationOptions {