• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 private:
54     void onMatchedLogEventInternalLocked(
55             const size_t matcherIndex, const MetricDimensionKey& eventKey,
56             const ConditionKey& conditionKey, bool condition, const LogEvent& event,
57             const std::map<int, HashableDimensionKey>& statePrimaryKeys) override;
58 
59     void onDumpReportLocked(const int64_t dumpTimeNs,
60                             const bool include_current_partial_bucket,
61                             const bool erase_data,
62                             const DumpLatency dumpLatency,
63                             std::set<string> *str_set,
64                             android::util::ProtoOutputStream* protoOutput) override;
65     void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
66 
67     // Internal interface to handle condition change.
68     void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
69 
70     // Internal interface to handle sliced condition change.
71     void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override;
72 
73     bool onConfigUpdatedLocked(
74             const StatsdConfig& config, const int configIndex, const int metricIndex,
75             const std::vector<sp<AtomMatchingTracker>>& allAtomMatchingTrackers,
76             const std::unordered_map<int64_t, int>& oldAtomMatchingTrackerMap,
77             const std::unordered_map<int64_t, int>& newAtomMatchingTrackerMap,
78             const sp<EventMatcherWizard>& matcherWizard,
79             const std::vector<sp<ConditionTracker>>& allConditionTrackers,
80             const std::unordered_map<int64_t, int>& conditionTrackerMap,
81             const sp<ConditionWizard>& wizard,
82             const std::unordered_map<int64_t, int>& metricToActivationMap,
83             std::unordered_map<int, std::vector<int>>& trackerToMetricMap,
84             std::unordered_map<int, std::vector<int>>& conditionToMetricMap,
85             std::unordered_map<int, std::vector<int>>& activationAtomTrackerToMetricMap,
86             std::unordered_map<int, std::vector<int>>& deactivationAtomTrackerToMetricMap,
87             std::vector<int>& metricsWithActivation) override;
88 
89     void dropDataLocked(const int64_t dropTimeNs) override;
90 
91     // Internal function to calculate the current used bytes.
92     size_t byteSizeLocked() const override;
93 
dumpStatesLocked(FILE * out,bool verbose)94     void dumpStatesLocked(FILE* out, bool verbose) const override{};
95 
96     // Maps the field/value pairs of an atom to a list of timestamps used to deduplicate atoms.
97     std::unordered_map<AtomDimensionKey, std::vector<int64_t>> mAggregatedAtoms;
98 
99     size_t mTotalSize;
100 };
101 
102 }  // namespace statsd
103 }  // namespace os
104 }  // namespace android
105 #endif  // EVENT_METRIC_PRODUCER_H
106