blob: a4dfdddf210b6d2825efe9e8e12ccf8d71519285 [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 "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
Yangster-macd19bcae42018-01-04 15:43:39 -080020#include "frameworks/base/cmds/statsd/src/statsd_internal.pb.h"
Yangster-mac20877162017-12-22 17:19:39 -080021#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"
22
23#include <unordered_map>
24
25namespace android {
26namespace os {
27namespace statsd {
28
29// Function to sort the Field protos.
30bool CompareField(const Field& a, const Field& b);
31struct FieldCmp {
32 bool operator()(const Field& a, const Field& b) const {
33 return CompareField(a, b);
34 }
35};
36
37// Flattened dimensions value map. To save space, usually the key contains the tree structure info
38// and value field is only leaf node.
39typedef std::map<Field, DimensionsValue, FieldCmp> FieldValueMap;
40
41// Util function to print the Field proto.
42std::string FieldToString(const Field& field);
43
44// Util function to find the leaf node from the input Field proto and set it in the corresponding
45// value proto.
46bool setFieldInLeafValueProto(const Field &field, DimensionsValue* leafValue);
47
48// Returns the leaf node from the Field proto. It assume that the input has only one
49// leaf node at most.
50const Field* getSingleLeaf(const Field* field);
51Field* getSingleLeaf(Field* field);
52
53// Append a node to the current leaf. It assumes that the input "parent" has one leaf node at most.
54void appendLeaf(Field *parent, int node_field_num);
55void appendLeaf(Field *parent, int node_field_num, int position);
56
57// Given the field sorting logic, this function is to increase the "field" at the leaf node.
58void getNextField(Field* field);
59
60// Increase the position index for the node. If the "position_index" is not set, set it as 0.
61void increasePosition(Field *field);
62
63// Finds the leaf node and set the index there.
64void setPositionForLeaf(Field *field, int index);
65
66// Returns true if the matcher has specified at least one leaf node.
67bool hasLeafNode(const FieldMatcher& matcher);
68
69// The two input Field proto are describing the same tree structure. Both contain one leaf node at
70// most. This is find the position index info for the leaf node at "reference" stored in the
71// "field_with_index" tree.
72int getPositionByReferenceField(const Field& reference, const Field& field_with_index);
73
74// Utils to build the Field proto for simple atom fields.
75Field buildAtomField(const int tagId, const Field &atomField);
76Field buildSimpleAtomField(const int tagId, const int atomFieldNum);
77Field buildSimpleAtomField(const int tagId);
78
79// Find out all the fields specified by the matcher.
80void findFields(
81 const FieldValueMap& fieldValueMap,
82 const FieldMatcher& matcher,
83 std::vector<Field>* rootFields);
84
85// Filter out the fields not in the field matcher.
86void filterFields(const FieldMatcher& matcher, FieldValueMap* fieldValueMap);
87
Yangster-macd40053e2018-01-09 16:29:22 -080088// Returns if the field is attribution node uid field.
89bool IsAttributionUidField(const Field& field);
90
Yangster-mac20877162017-12-22 17:19:39 -080091} // namespace statsd
92} // namespace os
93} // namespace android