Yao Chen | 5110bed | 2017-10-23 12:50:02 -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 EVENT_METRIC_PRODUCER_H |
| 18 | #define EVENT_METRIC_PRODUCER_H |
| 19 | |
| 20 | #include <unordered_map> |
| 21 | |
| 22 | #include <android/util/ProtoOutputStream.h> |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame^] | 23 | |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 24 | #include "../condition/ConditionTracker.h" |
| 25 | #include "../matchers/matcher_util.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 | #include "stats_util.h" |
| 30 | |
| 31 | namespace android { |
| 32 | namespace os { |
| 33 | namespace statsd { |
| 34 | |
| 35 | class EventMetricProducer : public MetricProducer { |
| 36 | public: |
| 37 | // TODO: Pass in the start time from MetricsManager, it should be consistent for all metrics. |
| 38 | EventMetricProducer(const EventMetric& eventMetric, const int conditionIndex, |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame^] | 39 | const sp<ConditionWizard>& wizard, const uint64_t startTimeNs); |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 40 | |
| 41 | virtual ~EventMetricProducer(); |
| 42 | |
| 43 | void onMatchedLogEventInternal(const size_t matcherIndex, const HashableDimensionKey& eventKey, |
| 44 | const std::map<std::string, HashableDimensionKey>& conditionKey, |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame^] | 45 | bool condition, const LogEvent& event, |
| 46 | bool scheduledPull) override; |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 47 | |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 48 | void onConditionChanged(const bool conditionMet, const uint64_t eventTime) override; |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 49 | |
| 50 | void finish() override; |
| 51 | |
| 52 | StatsLogReport onDumpReport() override; |
| 53 | |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 54 | void onSlicedConditionMayChange(const uint64_t eventTime) override; |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 55 | |
yro | 69007c8 | 2017-10-26 20:42:57 -0700 | [diff] [blame] | 56 | size_t byteSize() override; |
| 57 | |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 58 | // TODO: Implement this later. |
| 59 | virtual void notifyAppUpgrade(const string& apk, const int uid, const int version) override{}; |
David Chen | d689689 | 2017-10-25 11:49:03 -0700 | [diff] [blame] | 60 | // TODO: Implement this later. |
| 61 | virtual void notifyAppRemoved(const string& apk, const int uid) override{}; |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 62 | |
| 63 | private: |
| 64 | const EventMetric mMetric; |
| 65 | |
| 66 | std::unique_ptr<android::util::ProtoOutputStream> mProto; |
| 67 | |
| 68 | long long mProtoToken; |
| 69 | |
| 70 | void startNewProtoOutputStream(long long timestamp); |
| 71 | }; |
| 72 | |
| 73 | } // namespace statsd |
| 74 | } // namespace os |
| 75 | } // namespace android |
| 76 | #endif // EVENT_METRIC_PRODUCER_H |