blob: 77d7535a1ba19916d4071cc7084ba00f8fc5f0d2 [file] [log] [blame]
Yao Chen44cf27c2017-09-14 22:32:50 -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
17#ifndef METRICS_MANAGER_H
18#define METRICS_MANAGER_H
19
20#include <cutils/log.h>
21#include <log/logprint.h>
22#include <unordered_map>
23#include "../matchers/LogEntryMatcherManager.h"
24#include "ConditionTracker.h"
25#include "MetricProducer.h"
26#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
27
28namespace android {
29namespace os {
30namespace statsd {
31
32// A MetricsManager is responsible for managing metrics from one single config source.
33class MetricsManager {
34public:
35 MetricsManager(const StatsdConfig& config);
36
37 ~MetricsManager();
38
39 // Consume the stats log if it's interesting to this metric.
40 void onLogEvent(const log_msg& logMsg);
41
42 void finish();
43
44private:
45 const StatsdConfig mConfig;
46
47 // All event tags that are interesting to my metrics.
48 std::set<int> mTagIds;
49
50 // The matchers that my metrics share.
51 std::vector<LogEntryMatcher> mMatchers;
52
53 // The conditions that my metrics share.
54 std::vector<sp<ConditionTracker>> mConditionTracker;
55
56 // the map from LogEntryMatcher names to the metrics that use this matcher.
57 std::unordered_map<std::string, std::vector<std::unique_ptr<MetricProducer>>> mLogMatchers;
58};
59
60} // namespace statsd
61} // namespace os
62} // namespace android
63
64#endif // METRICS_MANAGER_H