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