• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2021 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef ART_ODREFRESH_ODR_METRICS_RECORD_H_
18 #define ART_ODREFRESH_ODR_METRICS_RECORD_H_
19 
20 #include <cstdint>
21 #include <iosfwd>  // For forward-declaration of std::string.
22 
23 #include "android-base/result.h"
24 #include "exec_utils.h"
25 #include "tinyxml2.h"
26 
27 namespace art {
28 namespace odrefresh {
29 
30 // Default location for storing metrics from odrefresh.
31 constexpr const char* kOdrefreshMetricsFile = "/data/misc/odrefresh/odrefresh-metrics.xml";
32 
33 // Initial OdrefreshMetrics version
34 static constexpr int32_t kOdrefreshMetricsVersion = 4;
35 
36 // Constant value used in ExecResult when the process was not run at all.
37 // Mirrors EXEC_RESULT_STATUS_NOT_RUN contained in frameworks/proto_logging/atoms.proto.
38 static constexpr int32_t kExecResultNotRun = 5;
39 static_assert(kExecResultNotRun > ExecResult::Status::kLast,
40               "`art::odrefresh::kExecResultNotRun` value should not overlap with"
41               " values of enum `art::ExecResult::Status`");
42 
43 
44 // MetricsRecord is a simpler container for Odrefresh metric values reported to statsd. The order
45 // and types of fields here mirror definition of `OdrefreshReported` in
46 // frameworks/proto_logging/stats/atoms.proto.
47 struct OdrMetricsRecord {
48   struct Dex2OatExecResult {
49     int32_t status;
50     int32_t exit_code;
51     int32_t signal;
52 
Dex2OatExecResultOdrMetricsRecord::Dex2OatExecResult53     explicit Dex2OatExecResult(int32_t status, int32_t exit_code, int32_t signal)
54       : status(status), exit_code(exit_code), signal(signal) {}
55 
Dex2OatExecResultOdrMetricsRecord::Dex2OatExecResult56     explicit Dex2OatExecResult(const ExecResult& result)
57       : status(result.status), exit_code(result.exit_code), signal(result.signal) {}
58 
Dex2OatExecResultOdrMetricsRecord::Dex2OatExecResult59     Dex2OatExecResult() : status(kExecResultNotRun), exit_code(-1), signal(0) {}
60   };
61 
62   int32_t odrefresh_metrics_version;
63   int64_t art_apex_version;
64   int32_t trigger;
65   int32_t stage_reached;
66   int32_t status;
67   int32_t cache_space_free_start_mib;
68   int32_t cache_space_free_end_mib;
69   int32_t primary_bcp_compilation_millis;
70   int32_t secondary_bcp_compilation_millis;
71   int32_t system_server_compilation_millis;
72   Dex2OatExecResult primary_bcp_dex2oat_result;
73   Dex2OatExecResult secondary_bcp_dex2oat_result;
74   Dex2OatExecResult system_server_dex2oat_result;
75   int32_t primary_bcp_compilation_type;
76   int32_t secondary_bcp_compilation_type;
77 
78   // Reads a `MetricsRecord` from an XML file.
79   // Returns an error if the XML document was not found or parsed correctly.
80   android::base::Result<void> ReadFromFile(const std::string& filename);
81 
82   // Writes a `MetricsRecord` to an XML file.
83   // Returns an error if the XML document was not saved correctly.
84   android::base::Result<void> WriteToFile(const std::string& filename) const;
85 };
86 
87 }  // namespace odrefresh
88 }  // namespace art
89 
90 #endif  // ART_ODREFRESH_ODR_METRICS_RECORD_H_
91