aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlessio Balsini <balsini@google.com>2020-05-31 12:28:47 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2020-05-31 12:28:47 +0000
commit359095f5df114c93868bc3fdcdd6c653f351165a (patch)
treea2928791ede37d896967acfb7047abf29da32820
parent7e4ff22435d2993b06f67813675b8d62c6ac9d2c (diff)
parente2ad4d3bebd0d864400c5d6931dc8db2db3363f3 (diff)
downloadupdate_engine-359095f5df114c93868bc3fdcdd6c653f351165a.tar.gz
Report super partition size, slot size and free space am: e2ad4d3beb
Change-Id: I3c651989347e24d15232c8a445f75cd51c5d265d
-rw-r--r--metrics_reporter_android.cc53
1 files changed, 52 insertions, 1 deletions
diff --git a/metrics_reporter_android.cc b/metrics_reporter_android.cc
index 24740c8a..d8fa6e5b 100644
--- a/metrics_reporter_android.cc
+++ b/metrics_reporter_android.cc
@@ -22,10 +22,22 @@
#include <string>
#include <android-base/properties.h>
+#include <base/strings/string_util.h>
+#include <fs_mgr.h>
+#include <libdm/dm.h>
+#include <liblp/builder.h>
+#include <liblp/liblp.h>
#include <statslog.h>
#include "update_engine/common/constants.h"
+using android::fs_mgr::GetPartitionGroupName;
+using android::fs_mgr::LpMetadata;
+using android::fs_mgr::MetadataBuilder;
+using android::fs_mgr::ReadMetadata;
+using android::fs_mgr::SlotNumberForSlotSuffix;
+using base::EndsWith;
+
namespace {
// A number offset adds on top of the enum value. e.g. ErrorCode::SUCCESS will
// be reported as 10000, and AttemptResult::UPDATE_CANCELED will be reported as
@@ -58,6 +70,42 @@ void MetricsReporterAndroid::ReportUpdateAttemptMetrics(
metrics::AttemptResult attempt_result,
ErrorCode error_code) {
int64_t payload_size_mib = payload_size / kNumBytesInOneMiB;
+
+ int64_t super_partition_size_bytes = 0;
+ int64_t super_free_space = 0;
+ int64_t slot_size_bytes = 0;
+
+ if (android::base::GetBoolProperty("ro.boot.dynamic_partitions", false)) {
+ uint32_t slot = SlotNumberForSlotSuffix(fs_mgr_get_slot_suffix());
+ auto super_device = fs_mgr_get_super_partition_name();
+ std::unique_ptr<LpMetadata> metadata = ReadMetadata(super_device, slot);
+ if (metadata) {
+ super_partition_size_bytes = GetTotalSuperPartitionSize(*metadata);
+
+ for (const auto& group : metadata->groups) {
+ if (EndsWith(GetPartitionGroupName(group),
+ fs_mgr_get_slot_suffix(),
+ base::CompareCase::SENSITIVE)) {
+ slot_size_bytes += group.maximum_size;
+ }
+ }
+
+ auto metadata_builder = MetadataBuilder::New(*metadata);
+ if (metadata_builder) {
+ auto free_regions = metadata_builder->GetFreeRegions();
+ for (const auto& interval : free_regions) {
+ super_free_space += interval.length();
+ }
+ super_free_space *= android::dm::kSectorSize;
+ } else {
+ LOG(ERROR) << "Cannot create metadata builder.";
+ }
+ } else {
+ LOG(ERROR) << "Could not read dynamic partition metadata for device: "
+ << super_device;
+ }
+ }
+
android::util::stats_write(
android::util::UPDATE_ENGINE_UPDATE_ATTEMPT_REPORTED,
attempt_number,
@@ -67,7 +115,10 @@ void MetricsReporterAndroid::ReportUpdateAttemptMetrics(
payload_size_mib,
GetStatsdEnumValue(static_cast<int32_t>(attempt_result)),
GetStatsdEnumValue(static_cast<int32_t>(error_code)),
- android::base::GetProperty("ro.build.fingerprint", "").c_str());
+ android::base::GetProperty("ro.build.fingerprint", "").c_str(),
+ super_partition_size_bytes,
+ slot_size_bytes,
+ super_free_space);
}
void MetricsReporterAndroid::ReportUpdateAttemptDownloadMetrics(