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> 23 24 #include "../condition/ConditionTracker.h" 25 #include "../matchers/matcher_util.h" 26 #include "MetricProducer.h" 27 #include "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: 36 EventMetricProducer( 37 const ConfigKey& key, const EventMetric& eventMetric, const int conditionIndex, 38 const vector<ConditionState>& initialConditionCache, const sp<ConditionWizard>& wizard, 39 const uint64_t protoHash, const int64_t startTimeNs, 40 const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {}, 41 const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>& 42 eventDeactivationMap = {}, 43 const vector<int>& slicedStateAtoms = {}, 44 const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap = {}); 45 46 virtual ~EventMetricProducer(); 47 48 MetricType getMetricType() const override { 49 return METRIC_TYPE_EVENT; 50 } 51 52 private: 53 void onMatchedLogEventInternalLocked( 54 const size_t matcherIndex, const MetricDimensionKey& eventKey, 55 const ConditionKey& conditionKey, bool condition, const LogEvent& event, 56 const std::map<int, HashableDimensionKey>& statePrimaryKeys) override; 57 58 void onDumpReportLocked(const int64_t dumpTimeNs, 59 const bool include_current_partial_bucket, 60 const bool erase_data, 61 const DumpLatency dumpLatency, 62 std::set<string> *str_set, 63 android::util::ProtoOutputStream* protoOutput) override; 64 void clearPastBucketsLocked(const int64_t dumpTimeNs) override; 65 66 // Internal interface to handle condition change. 67 void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override; 68 69 // Internal interface to handle sliced condition change. 70 void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override; 71 72 bool onConfigUpdatedLocked( 73 const StatsdConfig& config, const int configIndex, const int metricIndex, 74 const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers, 75 const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap, 76 const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap, 77 const sp<EventMatcherWizard>& matcherWizard, 78 const std::vector<sp<ConditionTracker>>& allConditionTrackers, 79 const std::unordered_map<int64_t, int>& conditionTrackerMap, 80 const sp<ConditionWizard>& wizard, 81 const std::unordered_map<int64_t, int>& metricToActivationMap, 82 std::unordered_map<int, std::vector<int>>& trackerToMetricMap, 83 std::unordered_map<int, std::vector<int>>& conditionToMetricMap, 84 std::unordered_map<int, std::vector<int>>& activationAtomTrackerToMetricMap, 85 std::unordered_map<int, std::vector<int>>& deactivationAtomTrackerToMetricMap, 86 std::vector<int>& metricsWithActivation) override; 87 88 void dropDataLocked(const int64_t dropTimeNs) override; 89 90 // Internal function to calculate the current used bytes. 91 size_t byteSizeLocked() const override; 92 93 void dumpStatesLocked(FILE* out, bool verbose) const override{}; 94 95 // Maps to a EventMetricDataWrapper. Storing atom events in ProtoOutputStream 96 // is more space efficient than storing LogEvent. 97 std::unique_ptr<android::util::ProtoOutputStream> mProto; 98 }; 99 100 } // namespace statsd 101 } // namespace os 102 } // namespace android 103 #endif // EVENT_METRIC_PRODUCER_H 104