1*e1997b9aSAndroid Build Coastguard Worker /* 2*e1997b9aSAndroid Build Coastguard Worker * Copyright (C) 2022 The Android Open Source Project 3*e1997b9aSAndroid Build Coastguard Worker * 4*e1997b9aSAndroid Build Coastguard Worker * Licensed under the Apache License, Version 2.0 (the "License"); 5*e1997b9aSAndroid Build Coastguard Worker * you may not use this file except in compliance with the License. 6*e1997b9aSAndroid Build Coastguard Worker * You may obtain a copy of the License at 7*e1997b9aSAndroid Build Coastguard Worker * 8*e1997b9aSAndroid Build Coastguard Worker * http://www.apache.org/licenses/LICENSE-2.0 9*e1997b9aSAndroid Build Coastguard Worker * 10*e1997b9aSAndroid Build Coastguard Worker * Unless required by applicable law or agreed to in writing, software 11*e1997b9aSAndroid Build Coastguard Worker * distributed under the License is distributed on an "AS IS" BASIS, 12*e1997b9aSAndroid Build Coastguard Worker * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*e1997b9aSAndroid Build Coastguard Worker * See the License for the specific language governing permissions and 14*e1997b9aSAndroid Build Coastguard Worker * limitations under the License. 15*e1997b9aSAndroid Build Coastguard Worker */ 16*e1997b9aSAndroid Build Coastguard Worker 17*e1997b9aSAndroid Build Coastguard Worker #pragma once 18*e1997b9aSAndroid Build Coastguard Worker 19*e1997b9aSAndroid Build Coastguard Worker #include <fstream> 20*e1997b9aSAndroid Build Coastguard Worker 21*e1997b9aSAndroid Build Coastguard Worker #include "statslog_odsign.h" 22*e1997b9aSAndroid Build Coastguard Worker 23*e1997b9aSAndroid Build Coastguard Worker // Class to store CompOsArtifactsCheck related metrics. 24*e1997b9aSAndroid Build Coastguard Worker // These are flushed to a file kOdsignMetricsFile and consumed by 25*e1997b9aSAndroid Build Coastguard Worker // System Server (in class OdsignStatsLogger) & sent to statsd. 26*e1997b9aSAndroid Build Coastguard Worker class StatsReporter { 27*e1997b9aSAndroid Build Coastguard Worker public: 28*e1997b9aSAndroid Build Coastguard Worker // Keep in sync with the EarlyBootCompOsArtifactsCheckReported definition in 29*e1997b9aSAndroid Build Coastguard Worker // proto_logging/stats/atoms.proto. 30*e1997b9aSAndroid Build Coastguard Worker struct CompOsArtifactsCheckRecord { 31*e1997b9aSAndroid Build Coastguard Worker bool current_artifacts_ok = false; 32*e1997b9aSAndroid Build Coastguard Worker bool comp_os_pending_artifacts_exists = false; 33*e1997b9aSAndroid Build Coastguard Worker bool use_comp_os_generated_artifacts = false; 34*e1997b9aSAndroid Build Coastguard Worker }; 35*e1997b9aSAndroid Build Coastguard Worker 36*e1997b9aSAndroid Build Coastguard Worker // Keep in sync with the OdsignReported definition in proto_logging/stats/atoms.proto. 37*e1997b9aSAndroid Build Coastguard Worker struct OdsignRecord { 38*e1997b9aSAndroid Build Coastguard Worker int32_t status = art::metrics::statsd::ODSIGN_REPORTED__STATUS__STATUS_UNSPECIFIED; 39*e1997b9aSAndroid Build Coastguard Worker }; 40*e1997b9aSAndroid Build Coastguard Worker 41*e1997b9aSAndroid Build Coastguard Worker // The report is flushed (from buffer) into a file by the destructor. 42*e1997b9aSAndroid Build Coastguard Worker ~StatsReporter(); 43*e1997b9aSAndroid Build Coastguard Worker 44*e1997b9aSAndroid Build Coastguard Worker // Returns a mutable CompOS record. The pointer remains valid for the lifetime of this 45*e1997b9aSAndroid Build Coastguard Worker // StatsReporter. If this function is not called, no CompOS record will be logged. 46*e1997b9aSAndroid Build Coastguard Worker CompOsArtifactsCheckRecord* GetOrCreateComposArtifactsCheckRecord(); 47*e1997b9aSAndroid Build Coastguard Worker 48*e1997b9aSAndroid Build Coastguard Worker // Returns a mutable odsign record. The pointer remains valid for the lifetime of this 49*e1997b9aSAndroid Build Coastguard Worker // StatsReporter. GetOdsignRecord()50*e1997b9aSAndroid Build Coastguard Worker OdsignRecord* GetOdsignRecord() { return &odsign_record_; } 51*e1997b9aSAndroid Build Coastguard Worker 52*e1997b9aSAndroid Build Coastguard Worker // Enables/disables odsign metrics. SetOdsignRecordEnabled(bool value)53*e1997b9aSAndroid Build Coastguard Worker void SetOdsignRecordEnabled(bool value) { odsign_record_enabled_ = value; } 54*e1997b9aSAndroid Build Coastguard Worker 55*e1997b9aSAndroid Build Coastguard Worker private: 56*e1997b9aSAndroid Build Coastguard Worker // Temporary buffer which stores the metrics. 57*e1997b9aSAndroid Build Coastguard Worker std::unique_ptr<CompOsArtifactsCheckRecord> comp_os_artifacts_check_record_; 58*e1997b9aSAndroid Build Coastguard Worker 59*e1997b9aSAndroid Build Coastguard Worker OdsignRecord odsign_record_; 60*e1997b9aSAndroid Build Coastguard Worker bool odsign_record_enabled_ = true; 61*e1997b9aSAndroid Build Coastguard Worker }; 62