libsnapshot: Add more feature flags to SnapshotMergeReport.

This patch also begins reducing the complexity of SnapshotMergeStats by
eliminating the indirection layer between the protobuf and
SnapshotManager.

Bug: 222117189
Test: statsd_testdrive
Change-Id: I15d740121c381da7d8311f0cbbd0da82db877555
This commit is contained in:
David Anderson 2022-03-08 23:13:47 -08:00
parent 50e130ed73
commit 93faa18bce
9 changed files with 49 additions and 33 deletions

View file

@ -235,4 +235,13 @@ message SnapshotMergeReport {
// The source fingerprint at the time the OTA was downloaded.
string source_build_fingerprint = 10;
// Whether this update attempt uses userspace snapshots.
bool userspace_snapshots_used = 11;
// Whether this update attempt uses XOR compression.
bool xor_compression_used = 12;
// Whether this update attempt used io_uring.
bool iouring_used = 13;
}

View file

@ -62,6 +62,7 @@ class MockSnapshotManager : public ISnapshotManager {
MOCK_METHOD(std::unique_ptr<AutoDevice>, EnsureMetadataMounted, (), (override));
MOCK_METHOD(ISnapshotMergeStats*, GetSnapshotMergeStatsInstance, (), (override));
MOCK_METHOD(std::string, ReadSourceBuildFingerprint, (), (override));
MOCK_METHOD(void, SetMergeStatsFeatures, (ISnapshotMergeStats*), (override));
};
} // namespace android::snapshot

View file

@ -28,10 +28,7 @@ class MockSnapshotMergeStats final : public ISnapshotMergeStats {
virtual ~MockSnapshotMergeStats() = default;
// Called when merge starts or resumes.
MOCK_METHOD(bool, Start, (), (override));
MOCK_METHOD(void, set_state, (android::snapshot::UpdateState, bool), (override));
MOCK_METHOD(void, set_cow_file_size, (uint64_t), ());
MOCK_METHOD(void, set_total_cow_size_bytes, (uint64_t), (override));
MOCK_METHOD(void, set_estimated_cow_size_bytes, (uint64_t), (override));
MOCK_METHOD(void, set_state, (android::snapshot::UpdateState), (override));
MOCK_METHOD(void, set_boot_complete_time_ms, (uint32_t), (override));
MOCK_METHOD(void, set_boot_complete_to_merge_start_time_ms, (uint32_t), (override));
MOCK_METHOD(void, set_merge_failure_code, (MergeFailureCode), (override));
@ -45,6 +42,7 @@ class MockSnapshotMergeStats final : public ISnapshotMergeStats {
MOCK_METHOD(MergeFailureCode, merge_failure_code, (), (override));
MOCK_METHOD(std::unique_ptr<Result>, Finish, (), (override));
MOCK_METHOD(bool, WriteState, (), (override));
MOCK_METHOD(SnapshotMergeReport*, report, (), (override));
using ISnapshotMergeStats::Result;
// Return nullptr if any failure.

View file

@ -134,6 +134,9 @@ class ISnapshotManager {
// may need to be merged before wiping.
virtual bool FinishedSnapshotWrites(bool wipe) = 0;
// Set feature flags on an ISnapshotMergeStats object.
virtual void SetMergeStatsFeatures(ISnapshotMergeStats* stats) = 0;
// Update an ISnapshotMergeStats object with statistics about COW usage.
// This should be called before the merge begins as otherwise snapshots
// may be deleted.
@ -378,6 +381,7 @@ class SnapshotManager final : public ISnapshotManager {
bool MapAllSnapshots(const std::chrono::milliseconds& timeout_ms = {}) override;
bool UnmapAllSnapshots() override;
std::string ReadSourceBuildFingerprint() override;
void SetMergeStatsFeatures(ISnapshotMergeStats* stats) override;
// We can't use WaitForFile during first-stage init, because ueventd is not
// running and therefore will not automatically create symlinks. Instead,

View file

@ -28,10 +28,7 @@ class ISnapshotMergeStats {
virtual ~ISnapshotMergeStats() = default;
// Called when merge starts or resumes.
virtual bool Start() = 0;
virtual void set_state(android::snapshot::UpdateState state, bool using_compression) = 0;
virtual void set_cow_file_size(uint64_t cow_file_size) = 0;
virtual void set_total_cow_size_bytes(uint64_t bytes) = 0;
virtual void set_estimated_cow_size_bytes(uint64_t bytes) = 0;
virtual void set_state(android::snapshot::UpdateState state) = 0;
virtual void set_boot_complete_time_ms(uint32_t ms) = 0;
virtual void set_boot_complete_to_merge_start_time_ms(uint32_t ms) = 0;
virtual void set_merge_failure_code(MergeFailureCode code) = 0;
@ -55,6 +52,9 @@ class ISnapshotMergeStats {
// Return nullptr if any failure.
virtual std::unique_ptr<Result> Finish() = 0;
// Return the underlying implementation.
virtual SnapshotMergeReport* report() = 0;
// Write out the current state. This should be called when data might be lost that
// cannot be recovered (eg the COW sizes).
virtual bool WriteState() = 0;
@ -67,11 +67,8 @@ class SnapshotMergeStats : public ISnapshotMergeStats {
// ISnapshotMergeStats overrides
bool Start() override;
void set_state(android::snapshot::UpdateState state, bool using_compression) override;
void set_cow_file_size(uint64_t cow_file_size) override;
void set_state(android::snapshot::UpdateState state) override;
uint64_t cow_file_size() override;
void set_total_cow_size_bytes(uint64_t bytes) override;
void set_estimated_cow_size_bytes(uint64_t bytes) override;
uint64_t total_cow_size_bytes() override;
uint64_t estimated_cow_size_bytes() override;
void set_boot_complete_time_ms(uint32_t ms) override;
@ -85,6 +82,9 @@ class SnapshotMergeStats : public ISnapshotMergeStats {
std::unique_ptr<Result> Finish() override;
bool WriteState() override;
// Access the underlying report before it is finished.
SnapshotMergeReport* report() override { return &report_; }
private:
bool ReadState();
bool DeleteState();

View file

@ -59,6 +59,7 @@ class SnapshotManagerStub : public ISnapshotManager {
bool MapAllSnapshots(const std::chrono::milliseconds& timeout_ms) override;
bool UnmapAllSnapshots() override;
std::string ReadSourceBuildFingerprint() override;
void SetMergeStatsFeatures(ISnapshotMergeStats* stats) override;
};
} // namespace android::snapshot

View file

@ -4120,9 +4120,20 @@ void SnapshotManager::UpdateCowStats(ISnapshotMergeStats* stats) {
estimated_cow_size += status.estimated_cow_size();
}
stats->set_cow_file_size(cow_file_size);
stats->set_total_cow_size_bytes(total_cow_size);
stats->set_estimated_cow_size_bytes(estimated_cow_size);
stats->report()->set_cow_file_size(cow_file_size);
stats->report()->set_total_cow_size_bytes(total_cow_size);
stats->report()->set_estimated_cow_size_bytes(estimated_cow_size);
}
void SnapshotManager::SetMergeStatsFeatures(ISnapshotMergeStats* stats) {
auto lock = LockExclusive();
if (!lock) return;
SnapshotUpdateStatus update_status = ReadSnapshotUpdateStatus(lock.get());
stats->report()->set_iouring_used(update_status.io_uring_enabled());
stats->report()->set_userspace_snapshots_used(update_status.userspace_snapshots());
stats->report()->set_xor_compression_used(
android::base::GetBoolProperty("ro.virtual_ab.compression.xor.enabled", false));
}
bool SnapshotManager::DeleteDeviceIfExists(const std::string& name,

View file

@ -84,27 +84,14 @@ bool SnapshotMergeStats::Start() {
return WriteState();
}
void SnapshotMergeStats::set_state(android::snapshot::UpdateState state, bool using_compression) {
void SnapshotMergeStats::set_state(android::snapshot::UpdateState state) {
report_.set_state(state);
report_.set_compression_enabled(using_compression);
}
void SnapshotMergeStats::set_cow_file_size(uint64_t cow_file_size) {
report_.set_cow_file_size(cow_file_size);
}
uint64_t SnapshotMergeStats::cow_file_size() {
return report_.cow_file_size();
}
void SnapshotMergeStats::set_total_cow_size_bytes(uint64_t bytes) {
report_.set_total_cow_size_bytes(bytes);
}
void SnapshotMergeStats::set_estimated_cow_size_bytes(uint64_t bytes) {
report_.set_estimated_cow_size_bytes(bytes);
}
uint64_t SnapshotMergeStats::total_cow_size_bytes() {
return report_.total_cow_size_bytes();
}

View file

@ -128,12 +128,9 @@ bool SnapshotManagerStub::UpdateUsesUserSnapshots() {
class SnapshotMergeStatsStub : public ISnapshotMergeStats {
bool Start() override { return false; }
void set_state(android::snapshot::UpdateState, bool) override {}
void set_cow_file_size(uint64_t) override {}
void set_state(android::snapshot::UpdateState) override {}
uint64_t cow_file_size() override { return 0; }
std::unique_ptr<Result> Finish() override { return nullptr; }
void set_total_cow_size_bytes(uint64_t) override {}
void set_estimated_cow_size_bytes(uint64_t) override {}
uint64_t total_cow_size_bytes() override { return 0; }
uint64_t estimated_cow_size_bytes() override { return 0; }
void set_boot_complete_time_ms(uint32_t) override {}
@ -145,6 +142,10 @@ class SnapshotMergeStatsStub : public ISnapshotMergeStats {
void set_source_build_fingerprint(const std::string&) override {}
std::string source_build_fingerprint() override { return {}; }
bool WriteState() override { return false; }
SnapshotMergeReport* report() override { return &report_; }
private:
SnapshotMergeReport report_;
};
ISnapshotMergeStats* SnapshotManagerStub::GetSnapshotMergeStatsInstance() {
@ -183,4 +184,8 @@ std::string SnapshotManagerStub::ReadSourceBuildFingerprint() {
return {};
}
void SnapshotManagerStub::SetMergeStatsFeatures(ISnapshotMergeStats*) {
LOG(ERROR) << __FUNCTION__ << " should never be called.";
}
} // namespace android::snapshot