blob: 33a951035dca100af94dd92921218f8f056a5ed3 [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
43 void onMatchedLogEventInternal(const size_t matcherIndex, const HashableDimensionKey& eventKey,
44 const std::map<std::string, HashableDimensionKey>& conditionKey,
Yao Chen93fe3a32017-11-02 13:52:59 -070045 bool condition, const LogEvent& event,
46 bool scheduledPull) override;
Yao Chen5110bed2017-10-23 12:50:02 -070047
Yao Chen5154a372017-10-30 22:57:06 -070048 void onConditionChanged(const bool conditionMet, const uint64_t eventTime) override;
Yao Chen5110bed2017-10-23 12:50:02 -070049
50 void finish() override;
Yangster-mace2cd6d52017-11-09 20:38:30 -080051 void flushIfNeeded(const uint64_t newEventTime) override {
52 }
Yao Chen5110bed2017-10-23 12:50:02 -070053
yro2b0f8862017-11-06 14:27:31 -080054 // TODO: Pass a timestamp as a parameter in onDumpReport.
yro17adac92017-11-08 23:16:29 -080055 std::unique_ptr<std::vector<uint8_t>> onDumpReport() override;
Yao Chen5110bed2017-10-23 12:50:02 -070056
Yao Chen5154a372017-10-30 22:57:06 -070057 void onSlicedConditionMayChange(const uint64_t eventTime) override;
Yao Chen5110bed2017-10-23 12:50:02 -070058
Yangster7c334a12017-11-22 14:24:24 -080059 size_t byteSize() const override;
yro69007c82017-10-26 20:42:57 -070060
Yao Chen5110bed2017-10-23 12:50:02 -070061 // TODO: Implement this later.
62 virtual void notifyAppUpgrade(const string& apk, const int uid, const int version) override{};
David Chend6896892017-10-25 11:49:03 -070063 // TODO: Implement this later.
64 virtual void notifyAppRemoved(const string& apk, const int uid) override{};
Yao Chen5110bed2017-10-23 12:50:02 -070065
yro2b0f8862017-11-06 14:27:31 -080066protected:
67 void startNewProtoOutputStream(long long timestamp) override;
68
Yao Chen5110bed2017-10-23 12:50:02 -070069private:
70 const EventMetric mMetric;
Yao Chen5110bed2017-10-23 12:50:02 -070071};
72
73} // namespace statsd
74} // namespace os
75} // namespace android
76#endif // EVENT_METRIC_PRODUCER_H