yro | 00698da | 2017-09-15 10:06:40 -0700 | [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 | */ |
Yang Lu | 3eba621 | 2017-10-25 19:54:45 -0700 | [diff] [blame] | 16 | |
| 17 | #pragma once |
yro | 00698da | 2017-09-15 10:06:40 -0700 | [diff] [blame] | 18 | |
Yao Chen | 2794da2 | 2017-12-13 16:01:55 -0800 | [diff] [blame] | 19 | #include "frameworks/base/cmds/statsd/src/stats_log.pb.h" |
Chenjie Yu | d9dfda7 | 2017-12-11 17:41:20 -0800 | [diff] [blame^] | 20 | #include <sstream> |
| 21 | #include "logd/LogReader.h" |
yro | 00698da | 2017-09-15 10:06:40 -0700 | [diff] [blame] | 22 | |
Yang Lu | 3eba621 | 2017-10-25 19:54:45 -0700 | [diff] [blame] | 23 | #include <unordered_map> |
| 24 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 25 | namespace android { |
| 26 | namespace os { |
| 27 | namespace statsd { |
yro | 00698da | 2017-09-15 10:06:40 -0700 | [diff] [blame] | 28 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 29 | #define DEFAULT_DIMENSION_KEY "" |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 30 | |
| 31 | typedef std::string HashableDimensionKey; |
| 32 | |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 33 | typedef std::map<std::string, HashableDimensionKey> ConditionKey; |
| 34 | |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 35 | typedef std::unordered_map<HashableDimensionKey, int64_t> DimToValMap; |
Yang Lu | 3eba621 | 2017-10-25 19:54:45 -0700 | [diff] [blame] | 36 | |
Chenjie Yu | d9dfda7 | 2017-12-11 17:41:20 -0800 | [diff] [blame^] | 37 | /* |
| 38 | * In memory rep for LogEvent. Uses much less memory than LogEvent |
| 39 | */ |
| 40 | typedef struct EventKV { |
| 41 | std::vector<KeyValuePair> kv; |
| 42 | string ToString() const { |
| 43 | std::ostringstream result; |
| 44 | result << "{ "; |
| 45 | const size_t N = kv.size(); |
| 46 | for (size_t i = 0; i < N; i++) { |
| 47 | result << " "; |
| 48 | result << (i + 1); |
| 49 | result << "->"; |
| 50 | const auto& pair = kv[i]; |
| 51 | if (pair.has_value_int()) { |
| 52 | result << pair.value_int(); |
| 53 | } else if (pair.has_value_long()) { |
| 54 | result << pair.value_long(); |
| 55 | } else if (pair.has_value_float()) { |
| 56 | result << pair.value_float(); |
| 57 | } else if (pair.has_value_str()) { |
| 58 | result << pair.value_str().c_str(); |
| 59 | } |
| 60 | } |
| 61 | result << " }"; |
| 62 | return result.str(); |
| 63 | } |
| 64 | } EventKV; |
| 65 | |
| 66 | typedef std::unordered_map<HashableDimensionKey, std::shared_ptr<EventKV>> DimToEventKVMap; |
| 67 | |
| 68 | EventMetricData parse(log_msg msg); |
| 69 | |
| 70 | int getTagId(log_msg msg); |
| 71 | |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 72 | std::string getHashableKey(std::vector<KeyValuePair> key); |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 73 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 74 | } // namespace statsd |
| 75 | } // namespace os |
| 76 | } // namespace android |