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 "frameworks/base/cmds/statsd/src/statsd_config.pb.h" |
Yangster-mac | d19bcae4 | 2018-01-04 15:43:39 -0800 | [diff] [blame] | 20 | #include "frameworks/base/cmds/statsd/src/statsd_internal.pb.h" |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 21 | #include "frameworks/base/cmds/statsd/src/stats_log.pb.h" |
| 22 | |
| 23 | #include <unordered_map> |
| 24 | |
| 25 | namespace android { |
| 26 | namespace os { |
| 27 | namespace statsd { |
| 28 | |
| 29 | // Function to sort the Field protos. |
| 30 | bool CompareField(const Field& a, const Field& b); |
| 31 | struct 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. |
| 39 | typedef std::map<Field, DimensionsValue, FieldCmp> FieldValueMap; |
| 40 | |
| 41 | // Util function to print the Field proto. |
| 42 | std::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. |
| 46 | bool 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. |
| 50 | const Field* getSingleLeaf(const Field* field); |
| 51 | Field* getSingleLeaf(Field* field); |
| 52 | |
| 53 | // Append a node to the current leaf. It assumes that the input "parent" has one leaf node at most. |
| 54 | void appendLeaf(Field *parent, int node_field_num); |
| 55 | void 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. |
| 58 | void getNextField(Field* field); |
| 59 | |
| 60 | // Increase the position index for the node. If the "position_index" is not set, set it as 0. |
| 61 | void increasePosition(Field *field); |
| 62 | |
| 63 | // Finds the leaf node and set the index there. |
| 64 | void setPositionForLeaf(Field *field, int index); |
| 65 | |
| 66 | // Returns true if the matcher has specified at least one leaf node. |
| 67 | bool 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. |
| 72 | int getPositionByReferenceField(const Field& reference, const Field& field_with_index); |
| 73 | |
| 74 | // Utils to build the Field proto for simple atom fields. |
| 75 | Field buildAtomField(const int tagId, const Field &atomField); |
| 76 | Field buildSimpleAtomField(const int tagId, const int atomFieldNum); |
| 77 | Field buildSimpleAtomField(const int tagId); |
| 78 | |
| 79 | // Find out all the fields specified by the matcher. |
| 80 | void 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. |
| 86 | void filterFields(const FieldMatcher& matcher, FieldValueMap* fieldValueMap); |
| 87 | |
Yangster-mac | d40053e | 2018-01-09 16:29:22 -0800 | [diff] [blame] | 88 | // Returns if the field is attribution node uid field. |
| 89 | bool IsAttributionUidField(const Field& field); |
| 90 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 91 | } // namespace statsd |
| 92 | } // namespace os |
| 93 | } // namespace android |