blob: 394ed234f02e08208ef607c7c70fce3af0b4c96a [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:
36 // TODO: Pass in the start time from MetricsManager, it should be consistent for all metrics.
Yao Chenb3561512017-11-21 18:07:17 -080037 EventMetricProducer(const ConfigKey& key, const EventMetric& eventMetric,
38 const int conditionIndex, const sp<ConditionWizard>& wizard,
39 const uint64_t startTimeNs);
Yao Chen5110bed2017-10-23 12:50:02 -070040
41 virtual ~EventMetricProducer();
42
Yao Chen5110bed2017-10-23 12:50:02 -070043private:
Yangsterf2bee6f2017-11-29 12:01:05 -080044 void onMatchedLogEventInternalLocked(
Yangster-mac93694462018-01-22 20:49:31 -080045 const size_t matcherIndex, const MetricDimensionKey& eventKey,
Yangster-mac20877162017-12-22 17:19:39 -080046 const ConditionKey& conditionKey, bool condition,
Chenjie Yua7259ab2017-12-10 08:31:05 -080047 const LogEvent& event) override;
Yangsterf2bee6f2017-11-29 12:01:05 -080048
Yao Chen288c6002017-12-12 13:43:18 -080049 void onDumpReportLocked(const uint64_t dumpTimeNs,
50 android::util::ProtoOutputStream* protoOutput) override;
Yangster-mac20877162017-12-22 17:19:39 -080051 void onDumpReportLocked(const uint64_t dumpTimeNs, StatsLogReport* report) override;
Yangsterf2bee6f2017-11-29 12:01:05 -080052
53 // Internal interface to handle condition change.
54 void onConditionChangedLocked(const bool conditionMet, const uint64_t eventTime) override;
55
56 // Internal interface to handle sliced condition change.
57 void onSlicedConditionMayChangeLocked(const uint64_t eventTime) override;
58
59 // Internal function to calculate the current used bytes.
60 size_t byteSizeLocked() const override;
61
Yao Chen884c8c12018-01-26 10:36:25 -080062 void dumpStatesLocked(FILE* out, bool verbose) const override{};
63
Yao Chen288c6002017-12-12 13:43:18 -080064 // Maps to a EventMetricDataWrapper. Storing atom events in ProtoOutputStream
65 // is more space efficient than storing LogEvent.
66 std::unique_ptr<android::util::ProtoOutputStream> mProto;
Yao Chen5110bed2017-10-23 12:50:02 -070067};
68
69} // namespace statsd
70} // namespace os
71} // namespace android
72#endif // EVENT_METRIC_PRODUCER_H