Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2017 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 | #pragma once |
| 18 | |
| 19 | #include <android/util/ProtoOutputStream.h> |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 20 | #include "field_util.h" |
Chenjie Yu | b038b70 | 2017-12-18 15:15:34 -0800 | [diff] [blame] | 21 | #include "frameworks/base/cmds/statsd/src/stats_log.pb.h" |
| 22 | #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" |
| 23 | #include "guardrail/StatsdStats.h" |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 24 | |
| 25 | namespace android { |
| 26 | namespace os { |
| 27 | namespace statsd { |
| 28 | |
| 29 | // Helper function to write DimensionsValue proto to ProtoOutputStream. |
Chenjie Yu | b038b70 | 2017-12-18 15:15:34 -0800 | [diff] [blame] | 30 | void writeDimensionsValueProtoToStream(const DimensionsValue& fieldValue, |
| 31 | util::ProtoOutputStream* protoOutput); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 32 | |
| 33 | // Helper function to write Field proto to ProtoOutputStream. |
Chenjie Yu | b038b70 | 2017-12-18 15:15:34 -0800 | [diff] [blame] | 34 | void writeFieldProtoToStream(const Field& field, util::ProtoOutputStream* protoOutput); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 35 | |
| 36 | // Helper function to construct the field value tree and write to ProtoOutputStream |
Chenjie Yu | b038b70 | 2017-12-18 15:15:34 -0800 | [diff] [blame] | 37 | void writeFieldValueTreeToStream(const FieldValueMap& fieldValueMap, |
| 38 | util::ProtoOutputStream* protoOutput); |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 39 | |
Yangster-mac | b814481 | 2018-01-04 10:56:23 -0800 | [diff] [blame] | 40 | // Convert the TimeUnit enum to the bucket size in millis. |
| 41 | int64_t TimeUnitToBucketSizeInMillis(TimeUnit unit); |
| 42 | |
Chenjie Yu | b038b70 | 2017-12-18 15:15:34 -0800 | [diff] [blame] | 43 | // Helper function to write PulledAtomStats to ProtoOutputStream |
| 44 | void writePullerStatsToStream(const std::pair<int, StatsdStats::PulledAtomStats>& pair, |
| 45 | util::ProtoOutputStream* protoOutput); |
Yangster-mac | 87718e2 | 2018-01-11 16:16:26 -0800 | [diff] [blame^] | 46 | |
| 47 | template<class T> |
| 48 | bool parseProtoOutputStream(util::ProtoOutputStream& protoOutput, T* message) { |
| 49 | std::string pbBytes; |
| 50 | auto iter = protoOutput.data(); |
| 51 | while (iter.readBuffer() != NULL) { |
| 52 | size_t toRead = iter.currentToRead(); |
| 53 | pbBytes.append(reinterpret_cast<const char*>(iter.readBuffer()), toRead); |
| 54 | iter.rp()->move(toRead); |
| 55 | } |
| 56 | return message->ParseFromArray(pbBytes.c_str(), pbBytes.size()); |
| 57 | } |
| 58 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 59 | } // namespace statsd |
| 60 | } // namespace os |
| 61 | } // namespace android |