blob: 27d0d12ec5be3a9d61541fbbef4ff39760890d5a [file] [log] [blame]
yro00698da2017-09-15 10:06:40 -07001/*
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 Lu3eba6212017-10-25 19:54:45 -070016
17#pragma once
yro00698da2017-09-15 10:06:40 -070018
Yao Chen2794da22017-12-13 16:01:55 -080019#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"
Chenjie Yud9dfda72017-12-11 17:41:20 -080020#include <sstream>
21#include "logd/LogReader.h"
yro00698da2017-09-15 10:06:40 -070022
Yang Lu3eba6212017-10-25 19:54:45 -070023#include <unordered_map>
24
Yao Chen44cf27c2017-09-14 22:32:50 -070025namespace android {
26namespace os {
27namespace statsd {
yro00698da2017-09-15 10:06:40 -070028
Yao Chen729093d2017-10-16 10:33:26 -070029#define DEFAULT_DIMENSION_KEY ""
Yao Chen729093d2017-10-16 10:33:26 -070030
31typedef std::string HashableDimensionKey;
32
Yao Chen5154a3792017-10-30 22:57:06 -070033typedef std::map<std::string, HashableDimensionKey> ConditionKey;
34
Yangster-mace2cd6d52017-11-09 20:38:30 -080035typedef std::unordered_map<HashableDimensionKey, int64_t> DimToValMap;
Yang Lu3eba6212017-10-25 19:54:45 -070036
Chenjie Yud9dfda72017-12-11 17:41:20 -080037/*
38 * In memory rep for LogEvent. Uses much less memory than LogEvent
39 */
40typedef 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
66typedef std::unordered_map<HashableDimensionKey, std::shared_ptr<EventKV>> DimToEventKVMap;
67
68EventMetricData parse(log_msg msg);
69
70int getTagId(log_msg msg);
71
Yao Chen729093d2017-10-16 10:33:26 -070072std::string getHashableKey(std::vector<KeyValuePair> key);
Yangster-mace2cd6d52017-11-09 20:38:30 -080073
Yao Chen44cf27c2017-09-14 22:32:50 -070074} // namespace statsd
75} // namespace os
76} // namespace android