blob: 5f1f295d450a70b043446f814037a55f56a31a4d [file] [log] [blame]
Yao Chencaf339d2017-10-06 16:01:10 -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 */
16#ifndef METRIC_UTIL_H
17#define METRIC_UTIL_H
18#include <memory>
19#include <set>
20#include <unordered_map>
21#include <vector>
22
23#include "../condition/ConditionTracker.h"
24#include "../matchers/LogMatchingTracker.h"
25#include "CountMetricProducer.h"
26
27namespace android {
28namespace os {
29namespace statsd {
30
31// Helper functions for MetricsManager to initialize from StatsdConfig.
32// *Note*: only initStatsdConfig() should be called from outside.
33// All other functions are intermediate
34// steps, created to make unit tests easier. And most of the parameters in these
35// functions are temporary objects in the initialization phase.
36
37// Initialize the LogMatchingTrackers.
38// input:
39// [config]: the input StatsdConfig
40// output:
41// [logTrackerMap]: this map should contain matcher name to index mapping
42// [allLogEntryMatchers]: should store the sp to all the LogMatchingTracker
43// [allTagIds]: contains the set of all interesting tag ids to this config.
44bool initLogTrackers(const StatsdConfig& config,
45 std::unordered_map<std::string, int>& logTrackerMap,
46 std::vector<sp<LogMatchingTracker>>& allLogEntryMatchers,
47 std::set<int>& allTagIds);
48
49// Initialize ConditionTrackers
50// input:
51// [config]: the input config
52// [logTrackerMap]: LogMatchingTracker name to index mapping from previous step.
53// output:
54// [conditionTrackerMap]: this map should contain condition name to index mapping
55// [allConditionTrackers]: stores the sp to all the ConditionTrackers
56// [trackerToConditionMap]: contain the mapping from index of
57// log tracker to condition trackers that use the log tracker
58bool initConditions(const StatsdConfig& config,
59 const std::unordered_map<std::string, int>& logTrackerMap,
60 std::unordered_map<std::string, int>& conditionTrackerMap,
61 std::vector<sp<ConditionTracker>>& allConditionTrackers,
62 std::unordered_map<int, std::vector<int>>& trackerToConditionMap);
63
64// Initialize MetricProducers.
65// input:
66// [config]: the input config
67// [logTrackerMap]: LogMatchingTracker name to index mapping from previous step.
68// [conditionTrackerMap]: condition name to index mapping
69// output:
70// [allMetricProducers]: contains the list of sp to the MetricProducers created.
71// [conditionToMetricMap]: contains the mapping from condition tracker index to
72// the list of MetricProducer index
73// [trackerToMetricMap]: contains the mapping from log tracker to MetricProducer index.
74bool initMetrics(const StatsdConfig& config,
75 const std::unordered_map<std::string, int>& logTrackerMap,
76 const std::unordered_map<std::string, int>& conditionTrackerMap,
77 std::vector<sp<MetricProducer>>& allMetricProducers,
78 std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
79 std::unordered_map<int, std::vector<int>>& trackerToMetricMap);
80
81// Initialize MetricManager from StatsdConfig.
82// Parameters are the members of MetricsManager. See MetricsManager for declaration.
83bool initStatsdConfig(const StatsdConfig& config, std::set<int>& allTagIds,
84 std::vector<sp<LogMatchingTracker>>& allLogEntryMatchers,
85 std::vector<sp<ConditionTracker>>& allConditionTrackers,
86 std::vector<sp<MetricProducer>>& allMetricProducers,
87 std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
88 std::unordered_map<int, std::vector<int>>& trackerToMetricMap,
89 std::unordered_map<int, std::vector<int>>& trackerToConditionMap);
90
91} // namespace statsd
92} // namespace os
93} // namespace android
94#endif // METRIC_UTIL_H