blob: 94abd6211ac57b60433fb42617dc699b1c7d7e02 [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 COUNT_METRIC_PRODUCER_H
18#define COUNT_METRIC_PRODUCER_H
19
Yao Chen44cf27c2017-09-14 22:32:50 -070020#include <unordered_map>
Yao Chencaf339d2017-10-06 16:01:10 -070021
Bookatza4bc9c42017-10-04 11:45:57 -070022#include "CountAnomalyTracker.h"
Yao Chencaf339d2017-10-06 16:01:10 -070023#include "../condition/ConditionTracker.h"
24#include "../matchers/matcher_util.h"
Yao Chen44cf27c2017-09-14 22:32:50 -070025#include "MetricProducer.h"
26#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"
27#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
28
David Chende701692017-10-05 13:16:02 -070029using namespace std;
30
Yao Chen44cf27c2017-09-14 22:32:50 -070031namespace android {
32namespace os {
33namespace statsd {
34
35class CountMetricProducer : public MetricProducer {
36public:
Yao Chencaf339d2017-10-06 16:01:10 -070037 CountMetricProducer(const CountMetric& countMetric, const bool hasCondition);
Yao Chen44cf27c2017-09-14 22:32:50 -070038
39 virtual ~CountMetricProducer();
40
Joe Onoratoc4dfae52017-10-17 23:38:21 -070041 void onMatchedLogEvent(const LogEvent& event) override;
Yao Chen44cf27c2017-09-14 22:32:50 -070042
Yao Chencaf339d2017-10-06 16:01:10 -070043 void onConditionChanged(const bool conditionMet) override;
44
Yao Chen44cf27c2017-09-14 22:32:50 -070045 void finish() override;
46
47 void onDumpReport() override;
48
David Chende701692017-10-05 13:16:02 -070049 // TODO: Implement this later.
50 virtual void notifyAppUpgrade(const string& apk, const int uid, const int version) override {};
51
Yao Chen44cf27c2017-09-14 22:32:50 -070052private:
53 const CountMetric mMetric;
54
Yao Chen44cf27c2017-09-14 22:32:50 -070055 const time_t mStartTime;
56 // TODO: Add dimensions.
Bookatza4bc9c42017-10-04 11:45:57 -070057 // Counter value for the current bucket.
Yao Chen44cf27c2017-09-14 22:32:50 -070058 int mCounter;
59
60 time_t mCurrentBucketStartTime;
61
62 long mBucketSize_sec;
63
Bookatza4bc9c42017-10-04 11:45:57 -070064 CountAnomalyTracker mAnomalyTracker;
65
Yao Chencaf339d2017-10-06 16:01:10 -070066 bool mCondition;
67
Yao Chen44cf27c2017-09-14 22:32:50 -070068 void flushCounterIfNeeded(const time_t& newEventTime);
69};
70
71} // namespace statsd
72} // namespace os
73} // namespace android
74#endif // COUNT_METRIC_PRODUCER_H