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 #include "odr_metrics_record.h"
18 
19 #include <iosfwd>
20 #include <istream>
21 #include <ostream>
22 #include <streambuf>
23 #include <string>
24 
25 namespace art {
26 namespace odrefresh {
27 
operator >>(std::istream & is,OdrMetricsRecord & record)28 std::istream& operator>>(std::istream& is, OdrMetricsRecord& record) {
29   // Block I/O related exceptions
30   auto saved_exceptions = is.exceptions();
31   is.exceptions(std::ios_base::iostate {});
32 
33   // The order here matches the field order of MetricsRecord.
34   is >> record.art_apex_version >> std::ws;
35   is >> record.trigger >> std::ws;
36   is >> record.stage_reached >> std::ws;
37   is >> record.status >> std::ws;
38   is >> record.primary_bcp_compilation_seconds >> std::ws;
39   is >> record.secondary_bcp_compilation_seconds >> std::ws;
40   is >> record.system_server_compilation_seconds >> std::ws;
41   is >> record.cache_space_free_start_mib >> std::ws;
42   is >> record.cache_space_free_end_mib >> std::ws;
43 
44   // Restore I/O related exceptions
45   is.exceptions(saved_exceptions);
46   return is;
47 }
48 
operator <<(std::ostream & os,const OdrMetricsRecord & record)49 std::ostream& operator<<(std::ostream& os, const OdrMetricsRecord& record) {
50   static const char kSpace = ' ';
51 
52   // Block I/O related exceptions
53   auto saved_exceptions = os.exceptions();
54   os.exceptions(std::ios_base::iostate {});
55 
56   // The order here matches the field order of MetricsRecord.
57   os << record.art_apex_version << kSpace;
58   os << record.trigger << kSpace;
59   os << record.stage_reached << kSpace;
60   os << record.status << kSpace;
61   os << record.primary_bcp_compilation_seconds << kSpace;
62   os << record.secondary_bcp_compilation_seconds << kSpace;
63   os << record.system_server_compilation_seconds << kSpace;
64   os << record.cache_space_free_start_mib << kSpace;
65   os << record.cache_space_free_end_mib << std::endl;
66 
67   // Restore I/O related exceptions
68   os.exceptions(saved_exceptions);
69   return os;
70 }
71 
72 }  // namespace odrefresh
73 }  // namespace art
74