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