blob: e8f2119a170c4987fc48dd1923f755b834f481ed [file] [log] [blame]
Yao Chen5110bed2017-10-23 12:50:02 -07001/*
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 Chen93fe3a32017-11-02 13:52:59 -070023
Yao Chen5110bed2017-10-23 12:50:02 -070024#include "../condition/ConditionTracker.h"
25#include "../matchers/matcher_util.h"
26#include "MetricProducer.h"
Yao Chen5110bed2017-10-23 12:50:02 -070027#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
28#include "stats_util.h"
29
30namespace android {
31namespace os {
32namespace statsd {
33
34class EventMetricProducer : public MetricProducer {
35public:
tsaichristined21aacf2019-10-07 14:47:38 -070036 EventMetricProducer(
37 const ConfigKey& key, const EventMetric& eventMetric, const int conditionIndex,
38 const sp<ConditionWizard>& wizard, const int64_t startTimeNs,
39 const std::unordered_map<int, std::shared_ptr<Activation>>& eventActivationMap = {},
40 const std::unordered_map<int, std::vector<std::shared_ptr<Activation>>>&
41 eventDeactivationMap = {},
42 const vector<int>& slicedStateAtoms = {},
43 const unordered_map<int, unordered_map<int, int64_t>>& stateGroupMap = {});
Yao Chen5110bed2017-10-23 12:50:02 -070044
45 virtual ~EventMetricProducer();
46
Yao Chen5110bed2017-10-23 12:50:02 -070047private:
Yangsterf2bee6f2017-11-29 12:01:05 -080048 void onMatchedLogEventInternalLocked(
Yangster-mac93694462018-01-22 20:49:31 -080049 const size_t matcherIndex, const MetricDimensionKey& eventKey,
tsaichristinec876b492019-12-10 13:47:05 -080050 const ConditionKey& conditionKey, bool condition, const LogEvent& event,
51 const std::map<int, HashableDimensionKey>& statePrimaryKeys) override;
Yangsterf2bee6f2017-11-29 12:01:05 -080052
Yangster-macb142cc82018-03-30 15:22:08 -070053 void onDumpReportLocked(const int64_t dumpTimeNs,
Yangster-mace68f3a52018-04-04 00:01:43 -070054 const bool include_current_partial_bucket,
Bookatzff71cad2018-09-20 17:17:49 -070055 const bool erase_data,
Olivier Gaillard6c75ecd2019-02-20 09:57:33 +000056 const DumpLatency dumpLatency,
Yangster-mac9def8e32018-04-17 13:55:51 -070057 std::set<string> *str_set,
Yao Chen288c6002017-12-12 13:43:18 -080058 android::util::ProtoOutputStream* protoOutput) override;
Yangster-maca802d732018-04-24 07:50:38 -070059 void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
Yangsterf2bee6f2017-11-29 12:01:05 -080060
61 // Internal interface to handle condition change.
Yangster-macb142cc82018-03-30 15:22:08 -070062 void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
Yangsterf2bee6f2017-11-29 12:01:05 -080063
64 // Internal interface to handle sliced condition change.
Yangster-macb142cc82018-03-30 15:22:08 -070065 void onSlicedConditionMayChangeLocked(bool overallCondition, const int64_t eventTime) override;
Yangsterf2bee6f2017-11-29 12:01:05 -080066
Yangster-macb142cc82018-03-30 15:22:08 -070067 void dropDataLocked(const int64_t dropTimeNs) override;
Yao Chen06dba5d2018-01-26 13:38:16 -080068
Yangsterf2bee6f2017-11-29 12:01:05 -080069 // Internal function to calculate the current used bytes.
70 size_t byteSizeLocked() const override;
71
Yao Chen884c8c12018-01-26 10:36:25 -080072 void dumpStatesLocked(FILE* out, bool verbose) const override{};
73
Yao Chen288c6002017-12-12 13:43:18 -080074 // Maps to a EventMetricDataWrapper. Storing atom events in ProtoOutputStream
75 // is more space efficient than storing LogEvent.
76 std::unique_ptr<android::util::ProtoOutputStream> mProto;
Yao Chen5110bed2017-10-23 12:50:02 -070077};
78
79} // namespace statsd
80} // namespace os
81} // namespace android
82#endif // EVENT_METRIC_PRODUCER_H