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" |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 27 | #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" |
| 28 | #include "stats_util.h" |
| 29 | |
| 30 | namespace android { |
| 31 | namespace os { |
| 32 | namespace statsd { |
| 33 | |
| 34 | class EventMetricProducer : public MetricProducer { |
| 35 | public: |
tsaichristine | d21aacf | 2019-10-07 14:47:38 -0700 | [diff] [blame] | 36 | EventMetricProducer( |
| 37 | const ConfigKey& key, const EventMetric& eventMetric, const int conditionIndex, |
| 38 | const sp<ConditionWizard>& wizard, const int64_t startTimeNs, |
| 39 | const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {}, |
| 40 | const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>& |
| 41 | eventDeactivationMap = {}, |
| 42 | const vector<int>& slicedStateAtoms = {}, |
| 43 | const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap = {}); |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 44 | |
| 45 | virtual ~EventMetricProducer(); |
| 46 | |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 47 | private: |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 48 | void onMatchedLogEventInternalLocked( |
Yangster-mac | 9369446 | 2018-01-22 20:49:31 -0800 | [diff] [blame] | 49 | const size_t matcherIndex, const MetricDimensionKey& eventKey, |
tsaichristine | c876b49 | 2019-12-10 13:47:05 -0800 | [diff] [blame] | 50 | const ConditionKey& conditionKey, bool condition, const LogEvent& event, |
| 51 | const std::map<int, HashableDimensionKey>& statePrimaryKeys) override; |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 52 | |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 53 | void onDumpReportLocked(const int64_t dumpTimeNs, |
Yangster-mac | e68f3a5 | 2018-04-04 00:01:43 -0700 | [diff] [blame] | 54 | const bool include_current_partial_bucket, |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 55 | const bool erase_data, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 56 | const DumpLatency dumpLatency, |
Yangster-mac | 9def8e3 | 2018-04-17 13:55:51 -0700 | [diff] [blame] | 57 | std::set<string> *str_set, |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 58 | android::util::ProtoOutputStream* protoOutput) override; |
Yangster-mac | a802d73 | 2018-04-24 07:50:38 -0700 | [diff] [blame] | 59 | void clearPastBucketsLocked(const int64_t dumpTimeNs) override; |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 60 | |
| 61 | // Internal interface to handle condition change. |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 62 | void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override; |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 63 | |
| 64 | // Internal interface to handle sliced condition change. |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 65 | void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override; |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 66 | |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 67 | void dropDataLocked(const int64_t dropTimeNs) override; |
Yao Chen | 06dba5d | 2018-01-26 13:38:16 -0800 | [diff] [blame] | 68 | |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 69 | // Internal function to calculate the current used bytes. |
| 70 | size_t byteSizeLocked() const override; |
| 71 | |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 72 | void dumpStatesLocked(FILE* out, bool verbose) const override{}; |
| 73 | |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 74 | // Maps to a EventMetricDataWrapper. Storing atom events in ProtoOutputStream |
| 75 | // is more space efficient than storing LogEvent. |
| 76 | std::unique_ptr<android::util::ProtoOutputStream> mProto; |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 77 | }; |
| 78 | |
| 79 | } // namespace statsd |
| 80 | } // namespace os |
| 81 | } // namespace android |
| 82 | #endif // EVENT_METRIC_PRODUCER_H |