• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 <memory>
20 #include <set>
21 #include <unordered_map>
22 #include <vector>
23 
24 #include "../anomaly/AlarmTracker.h"
25 #include "../condition/ConditionTracker.h"
26 #include "../external/StatsPullerManagerImpl.h"
27 #include "../matchers/LogMatchingTracker.h"
28 #include "../metrics/MetricProducer.h"
29 
30 namespace android {
31 namespace os {
32 namespace statsd {
33 
34 // Helper functions for MetricsManager to initialize from StatsdConfig.
35 // *Note*: only initStatsdConfig() should be called from outside.
36 // All other functions are intermediate
37 // steps, created to make unit tests easier. And most of the parameters in these
38 // functions are temporary objects in the initialization phase.
39 
40 // Initialize the LogMatchingTrackers.
41 // input:
42 // [key]: the config key that this config belongs to
43 // [config]: the input StatsdConfig
44 // output:
45 // [logTrackerMap]: this map should contain matcher name to index mapping
46 // [allAtomMatchers]: should store the sp to all the LogMatchingTracker
47 // [allTagIds]: contains the set of all interesting tag ids to this config.
48 bool initLogTrackers(const StatsdConfig& config,
49                      const UidMap& uidMap,
50                      std::unordered_map<int64_t, int>& logTrackerMap,
51                      std::vector<sp<LogMatchingTracker>>& allAtomMatchers,
52                      std::set<int>& allTagIds);
53 
54 // Initialize ConditionTrackers
55 // input:
56 // [key]: the config key that this config belongs to
57 // [config]: the input config
58 // [logTrackerMap]: LogMatchingTracker name to index mapping from previous step.
59 // output:
60 // [conditionTrackerMap]: this map should contain condition name to index mapping
61 // [allConditionTrackers]: stores the sp to all the ConditionTrackers
62 // [trackerToConditionMap]: contain the mapping from index of
63 //                        log tracker to condition trackers that use the log tracker
64 bool initConditions(const ConfigKey& key, const StatsdConfig& config,
65                     const std::unordered_map<int64_t, int>& logTrackerMap,
66                     std::unordered_map<int64_t, int>& conditionTrackerMap,
67                     std::vector<sp<ConditionTracker>>& allConditionTrackers,
68                     std::unordered_map<int, std::vector<int>>& trackerToConditionMap,
69                     std::unordered_map<int, std::vector<MetricConditionLink>>& eventConditionLinks);
70 
71 // Initialize MetricProducers.
72 // input:
73 // [key]: the config key that this config belongs to
74 // [config]: the input config
75 // [timeBaseSec]: start time base for all metrics
76 // [logTrackerMap]: LogMatchingTracker name to index mapping from previous step.
77 // [conditionTrackerMap]: condition name to index mapping
78 // output:
79 // [allMetricProducers]: contains the list of sp to the MetricProducers created.
80 // [conditionToMetricMap]: contains the mapping from condition tracker index to
81 //                          the list of MetricProducer index
82 // [trackerToMetricMap]: contains the mapping from log tracker to MetricProducer index.
83 bool initMetrics(
84         const ConfigKey& key, const StatsdConfig& config,
85         const int64_t timeBaseTimeNs, const int64_t currentTimeNs,
86         UidMap& uidMap,
87         const std::unordered_map<int64_t, int>& logTrackerMap,
88         const std::unordered_map<int64_t, int>& conditionTrackerMap,
89         const std::unordered_map<int, std::vector<MetricConditionLink>>& eventConditionLinks,
90         const vector<sp<LogMatchingTracker>>& allAtomMatchers,
91         vector<sp<ConditionTracker>>& allConditionTrackers,
92         std::vector<sp<MetricProducer>>& allMetricProducers,
93         std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
94         std::unordered_map<int, std::vector<int>>& trackerToMetricMap,
95         std::set<int64_t>& noReportMetricIds);
96 
97 // Initialize MetricsManager from StatsdConfig.
98 // Parameters are the members of MetricsManager. See MetricsManager for declaration.
99 bool initStatsdConfig(const ConfigKey& key, const StatsdConfig& config, UidMap& uidMap,
100                       const sp<AlarmMonitor>& anomalyAlarmMonitor,
101                       const sp<AlarmMonitor>& periodicAlarmMonitor,
102                       const int64_t timeBaseNs, const int64_t currentTimeNs,
103                       std::set<int>& allTagIds,
104                       std::vector<sp<LogMatchingTracker>>& allAtomMatchers,
105                       std::vector<sp<ConditionTracker>>& allConditionTrackers,
106                       std::vector<sp<MetricProducer>>& allMetricProducers,
107                       vector<sp<AnomalyTracker>>& allAnomalyTrackers,
108                       vector<sp<AlarmTracker>>& allPeriodicAlarmTrackers,
109                       std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
110                       std::unordered_map<int, std::vector<int>>& trackerToMetricMap,
111                       std::unordered_map<int, std::vector<int>>& trackerToConditionMap,
112                       std::set<int64_t>& noReportMetricIds);
113 
114 bool isStateTracker(const SimplePredicate& simplePredicate, std::vector<Matcher>* primaryKeys);
115 
116 }  // namespace statsd
117 }  // namespace os
118 }  // namespace android
119