blob: 0729e2c45f58c99c83513f2b2a6008f939d63a7c [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
29namespace android {
30namespace os {
31namespace statsd {
32
33class CountMetricProducer : public MetricProducer {
34public:
Yao Chencaf339d2017-10-06 16:01:10 -070035 CountMetricProducer(const CountMetric& countMetric, const bool hasCondition);
Yao Chen44cf27c2017-09-14 22:32:50 -070036
37 virtual ~CountMetricProducer();
38
39 void onMatchedLogEvent(const LogEventWrapper& event) override;
40
Yao Chencaf339d2017-10-06 16:01:10 -070041 void onConditionChanged(const bool conditionMet) override;
42
Yao Chen44cf27c2017-09-14 22:32:50 -070043 void finish() override;
44
45 void onDumpReport() override;
46
47private:
48 const CountMetric mMetric;
49
Yao Chen44cf27c2017-09-14 22:32:50 -070050 const time_t mStartTime;
51 // TODO: Add dimensions.
Bookatza4bc9c42017-10-04 11:45:57 -070052 // Counter value for the current bucket.
Yao Chen44cf27c2017-09-14 22:32:50 -070053 int mCounter;
54
55 time_t mCurrentBucketStartTime;
56
57 long mBucketSize_sec;
58
Bookatza4bc9c42017-10-04 11:45:57 -070059 CountAnomalyTracker mAnomalyTracker;
60
Yao Chencaf339d2017-10-06 16:01:10 -070061 bool mCondition;
62
Yao Chen44cf27c2017-09-14 22:32:50 -070063 void flushCounterIfNeeded(const time_t& newEventTime);
64};
65
66} // namespace statsd
67} // namespace os
68} // namespace android
69#endif // COUNT_METRIC_PRODUCER_H