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: |
| 36 | // TODO: Pass in the start time from MetricsManager, it should be consistent for all metrics. |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 37 | EventMetricProducer(const ConfigKey& key, const EventMetric& eventMetric, |
| 38 | const int conditionIndex, const sp<ConditionWizard>& wizard, |
| 39 | const uint64_t startTimeNs); |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 40 | |
| 41 | virtual ~EventMetricProducer(); |
| 42 | |
yro | 2b0f886 | 2017-11-06 14:27:31 -0800 | [diff] [blame] | 43 | protected: |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 44 | void startNewProtoOutputStreamLocked(); |
yro | 2b0f886 | 2017-11-06 14:27:31 -0800 | [diff] [blame] | 45 | |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 46 | private: |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 47 | void onMatchedLogEventInternalLocked( |
| 48 | const size_t matcherIndex, const HashableDimensionKey& eventKey, |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame^] | 49 | const ConditionKey& conditionKey, bool condition, |
Chenjie Yu | a7259ab | 2017-12-10 08:31:05 -0800 | [diff] [blame] | 50 | const LogEvent& event) override; |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 51 | |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 52 | void onDumpReportLocked(const uint64_t dumpTimeNs, |
| 53 | android::util::ProtoOutputStream* protoOutput) override; |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame^] | 54 | void onDumpReportLocked(const uint64_t dumpTimeNs, StatsLogReport* report) override; |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 55 | |
| 56 | // Internal interface to handle condition change. |
| 57 | void onConditionChangedLocked(const bool conditionMet, const uint64_t eventTime) override; |
| 58 | |
| 59 | // Internal interface to handle sliced condition change. |
| 60 | void onSlicedConditionMayChangeLocked(const uint64_t eventTime) override; |
| 61 | |
| 62 | // Internal function to calculate the current used bytes. |
| 63 | size_t byteSizeLocked() const override; |
| 64 | |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 65 | // Maps to a EventMetricDataWrapper. Storing atom events in ProtoOutputStream |
| 66 | // is more space efficient than storing LogEvent. |
| 67 | std::unique_ptr<android::util::ProtoOutputStream> mProto; |
Yao Chen | 5110bed | 2017-10-23 12:50:02 -0700 | [diff] [blame] | 68 | }; |
| 69 | |
| 70 | } // namespace statsd |
| 71 | } // namespace os |
| 72 | } // namespace android |
| 73 | #endif // EVENT_METRIC_PRODUCER_H |