| // Copyright 2020 The Fuchsia Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #ifndef COBALT_SRC_PB_METADATA_BUILDER_H_ |
| #define COBALT_SRC_PB_METADATA_BUILDER_H_ |
| |
| #include "src/lib/util/clock.h" |
| #include "src/lib/util/consistent_proto_store.h" |
| #include "src/lib/util/protected_fields.h" |
| #include "src/logger/project_context.h" |
| #include "src/pb/observation_batch.pb.h" |
| #include "src/pb/system_data_history.pb.h" |
| #include "src/registry/metric_definition.pb.h" |
| #include "src/registry/report_definition.pb.h" |
| #include "src/system_data/system_data.h" |
| |
| namespace cobalt { |
| |
| class MetadataBuilder { |
| public: |
| MetadataBuilder(system_data::SystemDataInterface *system_data, |
| std::string system_profile_cache_dir, util::FileSystem *fs) |
| : MetadataBuilder(system_data, nullptr, std::move(system_profile_cache_dir), fs) {} |
| |
| MetadataBuilder(system_data::SystemDataInterface *system_data, |
| util::ValidatedClockInterface *validated_clock, |
| std::string system_profile_cache_dir, util::FileSystem *fs); |
| |
| [[nodiscard]] std::unique_ptr<ObservationMetadata> Build(const logger::MetricRef &metric, |
| const ReportDefinition &report, |
| uint32_t day_index, |
| uint32_t hour_id) const; |
| |
| void SnapshotSystemData(); |
| void CleanupBefore(std::chrono::hours hours_ago); |
| |
| private: |
| void FilteredSystemProfile(const ReportDefinition &report, SystemProfile *profile_out) const; |
| |
| static void FilteredSystemProfile(const ReportDefinition &report, const SystemProfile &profile_in, |
| SystemProfile *profile_out); |
| |
| void WriteHistory(util::ProtectedFields<SystemProfileHistory>::LockedFieldsPtr history); |
| |
| util::ProtectedFields<SystemProfileHistory> system_profile_history_; |
| |
| system_data::SystemDataInterface *system_data_; |
| std::unique_ptr<util::AlwaysAccurateClock> owned_clock_; |
| util::ValidatedClockInterface *validated_clock_; |
| std::unique_ptr<util::ConsistentProtoStore> history_store_; |
| }; |
| |
| } // namespace cobalt |
| |
| #endif // COBALT_SRC_PB_METADATA_BUILDER_H_ |