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 METRIC_PRODUCER_H |
| 18 | #define METRIC_PRODUCER_H |
| 19 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame^] | 20 | #include "matchers/matcher_util.h" |
| 21 | #include "packages/PackageInfoListener.h" |
| 22 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 23 | #include <log/logprint.h> |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 24 | #include <utils/RefBase.h> |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 25 | |
| 26 | namespace android { |
| 27 | namespace os { |
| 28 | namespace statsd { |
| 29 | |
| 30 | // A MetricProducer is responsible for compute one single metrics, creating stats log report, and |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 31 | // writing the report to dropbox. MetricProducers should respond to package changes as required in |
| 32 | // PackageInfoListener, but if none of the metrics are slicing by package name, then the update can |
| 33 | // be a no-op. |
David Chen | f12b5c6 | 2017-10-13 15:54:03 -0700 | [diff] [blame] | 34 | class MetricProducer : public virtual PackageInfoListener { |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 35 | public: |
| 36 | virtual ~MetricProducer(){}; |
| 37 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 38 | // Consume the parsed stats log entry that already matched the "what" of the metric. |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 39 | virtual void onMatchedLogEvent(const LogEventWrapper& event) = 0; |
| 40 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 41 | virtual void onConditionChanged(const bool condition) = 0; |
| 42 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 43 | // This is called when the metric collecting is done, e.g., when there is a new configuration |
| 44 | // coming. MetricProducer should do the clean up, and dump existing data to dropbox. |
| 45 | virtual void finish() = 0; |
| 46 | |
| 47 | virtual void onDumpReport() = 0; |
| 48 | }; |
| 49 | |
| 50 | } // namespace statsd |
| 51 | } // namespace os |
| 52 | } // namespace android |
| 53 | #endif // METRIC_PRODUCER_H |