Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 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 | #ifndef COUNT_METRIC_PRODUCER_H |
| 18 | #define COUNT_METRIC_PRODUCER_H |
| 19 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 20 | #include <unordered_map> |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame^] | 21 | |
Bookatz | a4bc9c4 | 2017-10-04 11:45:57 -0700 | [diff] [blame] | 22 | #include "CountAnomalyTracker.h" |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame^] | 23 | #include "../condition/ConditionTracker.h" |
| 24 | #include "../matchers/matcher_util.h" |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 25 | #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 | |
| 29 | namespace android { |
| 30 | namespace os { |
| 31 | namespace statsd { |
| 32 | |
| 33 | class CountMetricProducer : public MetricProducer { |
| 34 | public: |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame^] | 35 | CountMetricProducer(const CountMetric& countMetric, const bool hasCondition); |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 36 | |
| 37 | virtual ~CountMetricProducer(); |
| 38 | |
| 39 | void onMatchedLogEvent(const LogEventWrapper& event) override; |
| 40 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame^] | 41 | void onConditionChanged(const bool conditionMet) override; |
| 42 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 43 | void finish() override; |
| 44 | |
| 45 | void onDumpReport() override; |
| 46 | |
| 47 | private: |
| 48 | const CountMetric mMetric; |
| 49 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 50 | const time_t mStartTime; |
| 51 | // TODO: Add dimensions. |
Bookatz | a4bc9c4 | 2017-10-04 11:45:57 -0700 | [diff] [blame] | 52 | // Counter value for the current bucket. |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 53 | int mCounter; |
| 54 | |
| 55 | time_t mCurrentBucketStartTime; |
| 56 | |
| 57 | long mBucketSize_sec; |
| 58 | |
Bookatz | a4bc9c4 | 2017-10-04 11:45:57 -0700 | [diff] [blame] | 59 | CountAnomalyTracker mAnomalyTracker; |
| 60 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame^] | 61 | bool mCondition; |
| 62 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 63 | void flushCounterIfNeeded(const time_t& newEventTime); |
| 64 | }; |
| 65 | |
| 66 | } // namespace statsd |
| 67 | } // namespace os |
| 68 | } // namespace android |
| 69 | #endif // COUNT_METRIC_PRODUCER_H |