Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2018 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 | #pragma once |
| 17 | |
| 18 | #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" |
Ruchir Rastogi | 1329651 | 2020-03-24 10:59:49 -0700 | [diff] [blame] | 19 | #include "annotations.h" |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 20 | |
| 21 | namespace android { |
| 22 | namespace os { |
| 23 | namespace statsd { |
| 24 | |
| 25 | class HashableDimensionKey; |
| 26 | struct Matcher; |
| 27 | struct Field; |
| 28 | struct FieldValue; |
| 29 | |
| 30 | const int32_t kAttributionField = 1; |
| 31 | const int32_t kMaxLogDepth = 2; |
| 32 | const int32_t kLastBitMask = 0x80; |
| 33 | const int32_t kClearLastBitDeco = 0x7f; |
Yangster-mac | e06cfd7 | 2018-03-10 23:22:59 -0800 | [diff] [blame] | 34 | const int32_t kClearAllPositionMatcherMask = 0xffff00ff; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 35 | |
Chenjie Yu | 12e5e67 | 2018-09-14 15:54:59 -0700 | [diff] [blame] | 36 | enum Type { UNKNOWN, INT, LONG, FLOAT, DOUBLE, STRING, STORAGE }; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 37 | |
Yao Chen | 4c959cb | 2018-02-13 13:27:48 -0800 | [diff] [blame] | 38 | int32_t getEncodedField(int32_t pos[], int32_t depth, bool includeDepth); |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 39 | |
Yao Chen | 4c959cb | 2018-02-13 13:27:48 -0800 | [diff] [blame] | 40 | int32_t encodeMatcherMask(int32_t mask[], int32_t depth); |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 41 | |
| 42 | // Get the encoded field for a leaf with a [field] number at depth 0; |
Yao Chen | 4c959cb | 2018-02-13 13:27:48 -0800 | [diff] [blame] | 43 | inline int32_t getSimpleField(size_t field) { |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 44 | return ((int32_t)field << 8 * 2); |
| 45 | } |
Yao Chen | 580ea321 | 2018-02-26 14:21:54 -0800 | [diff] [blame] | 46 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 47 | /** |
| 48 | * Field is a wrapper class for 2 integers that represents the field of a log element in its Atom |
| 49 | * proto. |
| 50 | * [mTag]: the atom id. |
| 51 | * [mField]: encoded path from the root (atom) to leaf. |
| 52 | * |
| 53 | * For example: |
| 54 | * WakeLockStateChanged { |
| 55 | * repeated AttributionNode = 1; |
| 56 | * int state = 2; |
| 57 | * string tag = 3; |
| 58 | * } |
| 59 | * Read from logd, the items are structured as below: |
| 60 | * [[[1000, "tag"], [2000, "tag2"],], 2,"hello"] |
| 61 | * |
| 62 | * When we read through the list, we will encode each field in a 32bit integer. |
| 63 | * 8bit segments |--------|--------|--------|--------| |
| 64 | * Depth field0 [L]field1 [L]field1 |
| 65 | * |
| 66 | * The first 8 bits are the depth of the field. for example, the uid 1000 has depth 2. |
| 67 | * The following 3 8-bit are for the item's position at each level. |
| 68 | * The first bit of each 8bits field is reserved to mark if the item is the last item at that level |
| 69 | * this is to make matching easier later. |
| 70 | * |
| 71 | * The above wakelock event is translated into FieldValue pairs. |
| 72 | * 0x02010101->1000 |
| 73 | * 0x02010182->tag |
| 74 | * 0x02018201->2000 |
| 75 | * 0x02018282->tag2 |
| 76 | * 0x00020000->2 |
| 77 | * 0x00030000->"hello" |
| 78 | * |
| 79 | * This encoding is the building block for the later operations. |
| 80 | * Please see the definition for Matcher below to see how the matching is done. |
| 81 | */ |
| 82 | struct Field { |
| 83 | private: |
| 84 | int32_t mTag; |
| 85 | int32_t mField; |
| 86 | |
| 87 | public: |
Yangster-mac | f520492 | 2018-02-23 13:08:03 -0800 | [diff] [blame] | 88 | Field() {} |
| 89 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 90 | Field(int32_t tag, int32_t pos[], int32_t depth) : mTag(tag) { |
| 91 | mField = getEncodedField(pos, depth, true); |
| 92 | } |
| 93 | |
| 94 | Field(const Field& from) : mTag(from.getTag()), mField(from.getField()) { |
| 95 | } |
| 96 | |
| 97 | Field(int32_t tag, int32_t field) : mTag(tag), mField(field){}; |
| 98 | |
| 99 | inline void setField(int32_t field) { |
| 100 | mField = field; |
| 101 | } |
| 102 | |
| 103 | inline void setTag(int32_t tag) { |
| 104 | mTag = tag; |
| 105 | } |
| 106 | |
| 107 | inline void decorateLastPos(int32_t depth) { |
| 108 | int32_t mask = kLastBitMask << 8 * (kMaxLogDepth - depth); |
| 109 | mField |= mask; |
| 110 | } |
| 111 | |
| 112 | inline int32_t getTag() const { |
| 113 | return mTag; |
| 114 | } |
| 115 | |
| 116 | inline int32_t getDepth() const { |
| 117 | return (mField >> 24); |
| 118 | } |
| 119 | |
| 120 | inline int32_t getPath(int32_t depth) const { |
| 121 | if (depth > 2 || depth < 0) return 0; |
| 122 | |
| 123 | int32_t field = (mField & 0x00ffffff); |
| 124 | int32_t mask = 0xffffffff; |
| 125 | return (field & (mask << 8 * (kMaxLogDepth - depth))); |
| 126 | } |
| 127 | |
| 128 | inline int32_t getPrefix(int32_t depth) const { |
| 129 | if (depth == 0) return 0; |
| 130 | return getPath(depth - 1); |
| 131 | } |
| 132 | |
| 133 | inline int32_t getField() const { |
| 134 | return mField; |
| 135 | } |
| 136 | |
| 137 | inline int32_t getRawPosAtDepth(int32_t depth) const { |
| 138 | int32_t field = (mField & 0x00ffffff); |
| 139 | int32_t shift = 8 * (kMaxLogDepth - depth); |
| 140 | int32_t mask = 0xff << shift; |
| 141 | |
| 142 | return (field & mask) >> shift; |
| 143 | } |
| 144 | |
| 145 | inline int32_t getPosAtDepth(int32_t depth) const { |
| 146 | return getRawPosAtDepth(depth) & kClearLastBitDeco; |
| 147 | } |
| 148 | |
| 149 | // Check if the first bit of the 8-bit segment for depth is 1 |
| 150 | inline bool isLastPos(int32_t depth) const { |
| 151 | int32_t field = (mField & 0x00ffffff); |
| 152 | int32_t mask = kLastBitMask << 8 * (kMaxLogDepth - depth); |
| 153 | return (field & mask) != 0; |
| 154 | } |
| 155 | |
| 156 | // if the 8-bit segment is all 0's |
| 157 | inline bool isAnyPosMatcher(int32_t depth) const { |
| 158 | return getDepth() >= depth && getRawPosAtDepth(depth) == 0; |
| 159 | } |
| 160 | // if the 8bit is 0x80 (1000 0000) |
| 161 | inline bool isLastPosMatcher(int32_t depth) const { |
| 162 | return getDepth() >= depth && getRawPosAtDepth(depth) == kLastBitMask; |
| 163 | } |
| 164 | |
| 165 | inline bool operator==(const Field& that) const { |
| 166 | return mTag == that.getTag() && mField == that.getField(); |
| 167 | }; |
| 168 | |
| 169 | inline bool operator!=(const Field& that) const { |
| 170 | return mTag != that.getTag() || mField != that.getField(); |
| 171 | }; |
| 172 | |
| 173 | bool operator<(const Field& that) const { |
| 174 | if (mTag != that.getTag()) { |
| 175 | return mTag < that.getTag(); |
| 176 | } |
| 177 | |
| 178 | if (mField != that.getField()) { |
| 179 | return mField < that.getField(); |
| 180 | } |
| 181 | |
| 182 | return false; |
| 183 | } |
Muhammad Qureshi | bfc4bdb | 2020-04-08 06:26:49 -0700 | [diff] [blame] | 184 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 185 | bool matches(const Matcher& that) const; |
| 186 | }; |
| 187 | |
| 188 | /** |
| 189 | * Matcher represents a leaf matcher in the FieldMatcher in statsd_config. |
| 190 | * |
| 191 | * It contains all information needed to match one or more leaf node. |
| 192 | * All information is encoded in a Field(2 ints) and a bit mask(1 int). |
| 193 | * |
| 194 | * For example, to match the first/any/last uid field in attribution chain in Atom 10, |
| 195 | * we have the following FieldMatcher in statsd_config |
| 196 | * FieldMatcher { |
| 197 | * field:10 |
| 198 | * FieldMatcher { |
| 199 | * field:1 |
| 200 | * position: any/last/first |
| 201 | * FieldMatcher { |
| 202 | * field:1 |
| 203 | * } |
| 204 | * } |
| 205 | * } |
| 206 | * |
| 207 | * We translate the FieldMatcher into a Field, and mask |
Yao Chen | 580ea321 | 2018-02-26 14:21:54 -0800 | [diff] [blame] | 208 | * First: [Matcher Field] 0x02010101 [Mask]0xff7f7f7f |
| 209 | * Last: [Matcher Field] 0x02018001 [Mask]0xff7f807f |
| 210 | * Any: [Matcher Field] 0x02010001 [Mask]0xff7f007f |
Yangster-mac | e06cfd7 | 2018-03-10 23:22:59 -0800 | [diff] [blame] | 211 | * All: [Matcher Field] 0x02010001 [Mask]0xff7f7f7f |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 212 | * |
| 213 | * [To match a log Field with a Matcher] we apply the bit mask to the log Field and check if |
| 214 | * the result is equal to the Matcher Field. That's a bit wise AND operation + check if 2 ints are |
| 215 | * equal. Nothing can beat the performance of this matching algorithm. |
| 216 | * |
Yao Chen | 5bfffb5 | 2018-06-21 16:58:51 -0700 | [diff] [blame] | 217 | * TODO(b/110561213): ADD EXAMPLE HERE. |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 218 | */ |
| 219 | struct Matcher { |
| 220 | Matcher(const Field& matcher, int32_t mask) : mMatcher(matcher), mMask(mask){}; |
| 221 | |
| 222 | const Field mMatcher; |
| 223 | const int32_t mMask; |
| 224 | |
Yangster-mac | 5392888 | 2018-02-25 23:02:56 -0800 | [diff] [blame] | 225 | inline const Field& getMatcher() const { |
| 226 | return mMatcher; |
| 227 | } |
| 228 | |
| 229 | inline int32_t getMask() const { |
| 230 | return mMask; |
| 231 | } |
| 232 | |
Yangster-mac | e06cfd7 | 2018-03-10 23:22:59 -0800 | [diff] [blame] | 233 | inline int32_t getRawMaskAtDepth(int32_t depth) const { |
| 234 | int32_t field = (mMask & 0x00ffffff); |
| 235 | int32_t shift = 8 * (kMaxLogDepth - depth); |
| 236 | int32_t mask = 0xff << shift; |
| 237 | |
| 238 | return (field & mask) >> shift; |
| 239 | } |
| 240 | |
| 241 | bool hasAllPositionMatcher() const { |
| 242 | return mMatcher.getDepth() == 2 && getRawMaskAtDepth(1) == 0x7f; |
| 243 | } |
| 244 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 245 | bool hasAnyPositionMatcher(int* prefix) const { |
Yangster-mac | e06cfd7 | 2018-03-10 23:22:59 -0800 | [diff] [blame] | 246 | if (mMatcher.getDepth() == 2 && mMatcher.getRawPosAtDepth(1) == 0) { |
| 247 | (*prefix) = mMatcher.getPrefix(1); |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 248 | return true; |
| 249 | } |
| 250 | return false; |
| 251 | } |
Yangster-mac | 5392888 | 2018-02-25 23:02:56 -0800 | [diff] [blame] | 252 | |
| 253 | inline bool operator!=(const Matcher& that) const { |
| 254 | return mMatcher != that.getMatcher() || mMask != that.getMask(); |
Yao Chen | 580ea321 | 2018-02-26 14:21:54 -0800 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | inline bool operator==(const Matcher& that) const { |
| 258 | return mMatcher == that.mMatcher && mMask == that.mMask; |
| 259 | } |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 260 | }; |
| 261 | |
Yao Chen | 580ea321 | 2018-02-26 14:21:54 -0800 | [diff] [blame] | 262 | inline Matcher getSimpleMatcher(int32_t tag, size_t field) { |
| 263 | return Matcher(Field(tag, getSimpleField(field)), 0xff7f0000); |
| 264 | } |
| 265 | |
tsaichristine | ed61564 | 2020-01-02 12:53:41 -0800 | [diff] [blame] | 266 | inline Matcher getFirstUidMatcher(int32_t atomId) { |
| 267 | int32_t pos[] = {1, 1, 1}; |
| 268 | return Matcher(Field(atomId, pos, 2), 0xff7f7f7f); |
| 269 | } |
| 270 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 271 | /** |
| 272 | * A wrapper for a union type to contain multiple types of values. |
| 273 | * |
| 274 | */ |
| 275 | struct Value { |
Yangster-mac | f520492 | 2018-02-23 13:08:03 -0800 | [diff] [blame] | 276 | Value() : type(UNKNOWN) {} |
| 277 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 278 | Value(int32_t v) { |
| 279 | int_value = v; |
| 280 | type = INT; |
| 281 | } |
| 282 | |
| 283 | Value(int64_t v) { |
| 284 | long_value = v; |
| 285 | type = LONG; |
| 286 | } |
| 287 | |
| 288 | Value(float v) { |
| 289 | float_value = v; |
| 290 | type = FLOAT; |
| 291 | } |
| 292 | |
Chenjie Yu | a0f0224 | 2018-07-06 16:14:34 -0700 | [diff] [blame] | 293 | Value(double v) { |
| 294 | double_value = v; |
| 295 | type = DOUBLE; |
| 296 | } |
| 297 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 298 | Value(const std::string& v) { |
| 299 | str_value = v; |
| 300 | type = STRING; |
| 301 | } |
| 302 | |
Chenjie Yu | 12e5e67 | 2018-09-14 15:54:59 -0700 | [diff] [blame] | 303 | Value(const std::vector<uint8_t>& v) { |
| 304 | storage_value = v; |
| 305 | type = STORAGE; |
| 306 | } |
| 307 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 308 | void setInt(int32_t v) { |
| 309 | int_value = v; |
| 310 | type = INT; |
| 311 | } |
| 312 | |
| 313 | void setLong(int64_t v) { |
| 314 | long_value = v; |
| 315 | type = LONG; |
| 316 | } |
| 317 | |
Chenjie Yu | a0f0224 | 2018-07-06 16:14:34 -0700 | [diff] [blame] | 318 | void setFloat(float v) { |
| 319 | float_value = v; |
| 320 | type = FLOAT; |
| 321 | } |
| 322 | |
| 323 | void setDouble(double v) { |
| 324 | double_value = v; |
| 325 | type = DOUBLE; |
| 326 | } |
| 327 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 328 | union { |
| 329 | int32_t int_value; |
| 330 | int64_t long_value; |
| 331 | float float_value; |
Chenjie Yu | a0f0224 | 2018-07-06 16:14:34 -0700 | [diff] [blame] | 332 | double double_value; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 333 | }; |
| 334 | std::string str_value; |
Chenjie Yu | 12e5e67 | 2018-09-14 15:54:59 -0700 | [diff] [blame] | 335 | std::vector<uint8_t> storage_value; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 336 | |
| 337 | Type type; |
| 338 | |
| 339 | std::string toString() const; |
| 340 | |
Chenjie Yu | c715b9e | 2018-10-19 07:52:12 -0700 | [diff] [blame] | 341 | bool isZero() const; |
| 342 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 343 | Type getType() const { |
| 344 | return type; |
| 345 | } |
| 346 | |
Chenjie Yu | a0f0224 | 2018-07-06 16:14:34 -0700 | [diff] [blame] | 347 | double getDouble() const; |
| 348 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 349 | Value(const Value& from); |
| 350 | |
| 351 | bool operator==(const Value& that) const; |
| 352 | bool operator!=(const Value& that) const; |
| 353 | |
| 354 | bool operator<(const Value& that) const; |
Chenjie Yu | a0f0224 | 2018-07-06 16:14:34 -0700 | [diff] [blame] | 355 | bool operator>(const Value& that) const; |
| 356 | bool operator>=(const Value& that) const; |
| 357 | Value operator-(const Value& that) const; |
| 358 | Value& operator+=(const Value& that); |
| 359 | Value& operator=(const Value& that); |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 360 | }; |
| 361 | |
Ruchir Rastogi | 1329651 | 2020-03-24 10:59:49 -0700 | [diff] [blame] | 362 | class Annotations { |
| 363 | public: |
Muhammad Qureshi | bfc4bdb | 2020-04-08 06:26:49 -0700 | [diff] [blame] | 364 | Annotations() { |
| 365 | setNested(true); // Nested = true by default |
| 366 | } |
Ruchir Rastogi | 1329651 | 2020-03-24 10:59:49 -0700 | [diff] [blame] | 367 | |
| 368 | // This enum stores where particular annotations can be found in the |
| 369 | // bitmask. Note that these pos do not correspond to annotation ids. |
| 370 | enum { |
| 371 | NESTED_POS = 0x0, |
| 372 | PRIMARY_POS = 0x1, |
Ruchir Rastogi | ffa34f0 | 2020-04-04 15:30:11 -0700 | [diff] [blame] | 373 | EXCLUSIVE_POS = 0x2, |
| 374 | UID_POS = 0x3 |
Ruchir Rastogi | 1329651 | 2020-03-24 10:59:49 -0700 | [diff] [blame] | 375 | }; |
| 376 | |
| 377 | inline void setNested(bool nested) { setBitmaskAtPos(NESTED_POS, nested); } |
| 378 | |
| 379 | inline void setPrimaryField(bool primary) { setBitmaskAtPos(PRIMARY_POS, primary); } |
| 380 | |
| 381 | inline void setExclusiveState(bool exclusive) { setBitmaskAtPos(EXCLUSIVE_POS, exclusive); } |
| 382 | |
Ruchir Rastogi | ffa34f0 | 2020-04-04 15:30:11 -0700 | [diff] [blame] | 383 | inline void setUidField(bool isUid) { setBitmaskAtPos(UID_POS, isUid); } |
| 384 | |
Ruchir Rastogi | 1329651 | 2020-03-24 10:59:49 -0700 | [diff] [blame] | 385 | // Default value = false |
| 386 | inline bool isNested() const { return getValueFromBitmask(NESTED_POS); } |
| 387 | |
| 388 | // Default value = false |
| 389 | inline bool isPrimaryField() const { return getValueFromBitmask(PRIMARY_POS); } |
| 390 | |
| 391 | // Default value = false |
| 392 | inline bool isExclusiveState() const { return getValueFromBitmask(EXCLUSIVE_POS); } |
| 393 | |
Ruchir Rastogi | ffa34f0 | 2020-04-04 15:30:11 -0700 | [diff] [blame] | 394 | // Default value = false |
| 395 | inline bool isUidField() const { return getValueFromBitmask(UID_POS); } |
| 396 | |
Ruchir Rastogi | 1329651 | 2020-03-24 10:59:49 -0700 | [diff] [blame] | 397 | private: |
| 398 | inline void setBitmaskAtPos(int pos, bool value) { |
| 399 | mBooleanBitmask &= ~(1 << pos); // clear |
| 400 | mBooleanBitmask |= (value << pos); // set |
| 401 | } |
| 402 | |
| 403 | inline bool getValueFromBitmask(int pos) const { |
| 404 | return (mBooleanBitmask >> pos) & 0x1; |
| 405 | } |
| 406 | |
| 407 | // This is a bitmask over all annotations stored in boolean form. Because |
Ruchir Rastogi | ffa34f0 | 2020-04-04 15:30:11 -0700 | [diff] [blame] | 408 | // there are only 4 booleans, just one byte is required. |
Ruchir Rastogi | 1329651 | 2020-03-24 10:59:49 -0700 | [diff] [blame] | 409 | uint8_t mBooleanBitmask = 0; |
Ruchir Rastogi | 1329651 | 2020-03-24 10:59:49 -0700 | [diff] [blame] | 410 | }; |
| 411 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 412 | /** |
| 413 | * Represents a log item, or a dimension item (They are essentially the same). |
| 414 | */ |
| 415 | struct FieldValue { |
Yangster-mac | f520492 | 2018-02-23 13:08:03 -0800 | [diff] [blame] | 416 | FieldValue() {} |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 417 | FieldValue(const Field& field, const Value& value) : mField(field), mValue(value) { |
| 418 | } |
| 419 | bool operator==(const FieldValue& that) const { |
| 420 | return mField == that.mField && mValue == that.mValue; |
| 421 | } |
| 422 | bool operator!=(const FieldValue& that) const { |
| 423 | return mField != that.mField || mValue != that.mValue; |
| 424 | } |
| 425 | bool operator<(const FieldValue& that) const { |
| 426 | if (mField != that.mField) { |
| 427 | return mField < that.mField; |
| 428 | } |
| 429 | |
| 430 | if (mValue != that.mValue) { |
| 431 | return mValue < that.mValue; |
| 432 | } |
| 433 | |
| 434 | return false; |
| 435 | } |
| 436 | |
| 437 | Field mField; |
| 438 | Value mValue; |
Ruchir Rastogi | 1329651 | 2020-03-24 10:59:49 -0700 | [diff] [blame] | 439 | Annotations mAnnotations; |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 440 | }; |
| 441 | |
Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 442 | bool HasPositionANY(const FieldMatcher& matcher); |
Yangster-mac | 9def8e3 | 2018-04-17 13:55:51 -0700 | [diff] [blame] | 443 | bool HasPositionALL(const FieldMatcher& matcher); |
Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 444 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 445 | bool isAttributionUidField(const FieldValue& value); |
| 446 | |
Yao Chen | 4ce0729 | 2019-02-13 13:06:36 -0800 | [diff] [blame] | 447 | /* returns uid if the field is uid field, or -1 if the field is not a uid field */ |
| 448 | int getUidIfExists(const FieldValue& value); |
| 449 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 450 | void translateFieldMatcher(const FieldMatcher& matcher, std::vector<Matcher>* output); |
| 451 | |
| 452 | bool isAttributionUidField(const Field& field, const Value& value); |
Ruchir Rastogi | ffa34f0 | 2020-04-04 15:30:11 -0700 | [diff] [blame] | 453 | bool isUidField(const FieldValue& fieldValue); |
Yangster | 13fb7e4 | 2018-03-07 17:30:49 -0800 | [diff] [blame] | 454 | |
| 455 | bool equalDimensions(const std::vector<Matcher>& dimension_a, |
| 456 | const std::vector<Matcher>& dimension_b); |
tsaichristine | 3a83e81 | 2019-12-13 16:46:11 -0800 | [diff] [blame] | 457 | |
| 458 | // Returns true if dimension_a is a subset of dimension_b. |
| 459 | bool subsetDimensions(const std::vector<Matcher>& dimension_a, |
| 460 | const std::vector<Matcher>& dimension_b); |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 461 | } // namespace statsd |
| 462 | } // namespace os |
| 463 | } // namespace android |