blob: 6583f579648b0251e3a2a04cb1044df1678ce9f4 [file] [log] [blame]
Yangster-mac20877162017-12-22 17:19:39 -08001/*
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>
Yao Chen8a8d16c2018-02-08 14:50:40 -080020#include "FieldValue.h"
21#include "HashableDimensionKey.h"
Chenjie Yub038b702017-12-18 15:15:34 -080022#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"
23#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
24#include "guardrail/StatsdStats.h"
Yangster-mac20877162017-12-22 17:19:39 -080025
26namespace android {
27namespace os {
28namespace statsd {
29
Yao Chen8a8d16c2018-02-08 14:50:40 -080030void writeFieldValueTreeToStream(int tagId, const std::vector<FieldValue>& values,
Chenjie Yub038b702017-12-18 15:15:34 -080031 util::ProtoOutputStream* protoOutput);
Yao Chen8a8d16c2018-02-08 14:50:40 -080032void writeDimensionToProto(const HashableDimensionKey& dimension,
33 util::ProtoOutputStream* protoOutput);
Yangster-mac20877162017-12-22 17:19:39 -080034
Yangster-macb8144812018-01-04 10:56:23 -080035// Convert the TimeUnit enum to the bucket size in millis.
36int64_t TimeUnitToBucketSizeInMillis(TimeUnit unit);
37
Chenjie Yub038b702017-12-18 15:15:34 -080038// Helper function to write PulledAtomStats to ProtoOutputStream
39void writePullerStatsToStream(const std::pair<int, StatsdStats::PulledAtomStats>& pair,
40 util::ProtoOutputStream* protoOutput);
Yangster-mac87718e22018-01-11 16:16:26 -080041
42template<class T>
43bool parseProtoOutputStream(util::ProtoOutputStream& protoOutput, T* message) {
44 std::string pbBytes;
45 auto iter = protoOutput.data();
46 while (iter.readBuffer() != NULL) {
47 size_t toRead = iter.currentToRead();
48 pbBytes.append(reinterpret_cast<const char*>(iter.readBuffer()), toRead);
49 iter.rp()->move(toRead);
50 }
51 return message->ParseFromArray(pbBytes.c_str(), pbBytes.size());
52}
53
Yangster-mac20877162017-12-22 17:19:39 -080054} // namespace statsd
55} // namespace os
56} // namespace android