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" |
| 24 | #include "ConditionTracker.h" |
| 25 | #include "DropboxWriter.h" |
| 26 | #include "MetricProducer.h" |
| 27 | #include "frameworks/base/cmds/statsd/src/stats_log.pb.h" |
| 28 | #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" |
| 29 | |
| 30 | namespace android { |
| 31 | namespace os { |
| 32 | namespace statsd { |
| 33 | |
| 34 | class CountMetricProducer : public MetricProducer { |
| 35 | public: |
| 36 | CountMetricProducer(const CountMetric& countMetric, const sp<ConditionTracker> condition); |
| 37 | |
| 38 | CountMetricProducer(const CountMetric& countMetric); |
| 39 | |
| 40 | virtual ~CountMetricProducer(); |
| 41 | |
| 42 | void onMatchedLogEvent(const LogEventWrapper& event) override; |
| 43 | |
| 44 | void finish() override; |
| 45 | |
| 46 | void onDumpReport() override; |
| 47 | |
| 48 | private: |
| 49 | const CountMetric mMetric; |
| 50 | |
| 51 | const sp<ConditionTracker> mConditionTracker; |
| 52 | |
| 53 | const time_t mStartTime; |
| 54 | // TODO: Add dimensions. |
| 55 | int mCounter; |
| 56 | |
| 57 | time_t mCurrentBucketStartTime; |
| 58 | |
| 59 | long mBucketSize_sec; |
| 60 | |
| 61 | void flushCounterIfNeeded(const time_t& newEventTime); |
| 62 | }; |
| 63 | |
| 64 | } // namespace statsd |
| 65 | } // namespace os |
| 66 | } // namespace android |
| 67 | #endif // COUNT_METRIC_PRODUCER_H |