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 "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: 36 EventMetricProducer(const ConfigKey& key, const EventMetric& eventMetric, 37 const int conditionIndex, const sp<ConditionWizard>& wizard, 38 const int64_t startTimeNs); 39 40 virtual ~EventMetricProducer(); 41 42 private: 43 void onMatchedLogEventInternalLocked( 44 const size_t matcherIndex, const MetricDimensionKey& eventKey, 45 const ConditionKey& conditionKey, bool condition, 46 const LogEvent& event) override; 47 48 void onDumpReportLocked(const int64_t dumpTimeNs, 49 const bool include_current_partial_bucket, 50 const bool erase_data, 51 const DumpLatency dumpLatency, 52 std::set<string> *str_set, 53 android::util::ProtoOutputStream* protoOutput) override; 54 void clearPastBucketsLocked(const int64_t dumpTimeNs) override; 55 56 // Internal interface to handle condition change. 57 void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override; 58 59 // Internal interface to handle sliced condition change. 60 void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override; 61 62 void dropDataLocked(const int64_t dropTimeNs) override; 63 64 // Internal function to calculate the current used bytes. 65 size_t byteSizeLocked() const override; 66 67 void dumpStatesLocked(FILE* out, bool verbose) const override{}; 68 69 // Maps to a EventMetricDataWrapper. Storing atom events in ProtoOutputStream 70 // is more space efficient than storing LogEvent. 71 std::unique_ptr<android::util::ProtoOutputStream> mProto; 72 }; 73 74 } // namespace statsd 75 } // namespace os 76 } // namespace android 77 #endif // EVENT_METRIC_PRODUCER_H 78