blob: 7502320410ac4762eefc4b964c0f91e818bff94a [file] [log] [blame]
Yao Chen44cf27c2017-09-14 22:32:50 -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 COUNT_METRIC_PRODUCER_H
18#define COUNT_METRIC_PRODUCER_H
19
20#include <mutex>
21#include <thread>
22#include <unordered_map>
23#include "../matchers/LogEntryMatcherManager.h"
Bookatza4bc9c42017-10-04 11:45:57 -070024#include "CountAnomalyTracker.h"
Yao Chen44cf27c2017-09-14 22:32:50 -070025#include "ConditionTracker.h"
26#include "DropboxWriter.h"
27#include "MetricProducer.h"
28#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"
29#include "frameworks/base/cmds/statsd/src/statsd_config.pb.h"
30
31namespace android {
32namespace os {
33namespace statsd {
34
35class CountMetricProducer : public MetricProducer {
36public:
37 CountMetricProducer(const CountMetric& countMetric, const sp<ConditionTracker> condition);
38
39 CountMetricProducer(const CountMetric& countMetric);
40
41 virtual ~CountMetricProducer();
42
43 void onMatchedLogEvent(const LogEventWrapper& event) override;
44
45 void finish() override;
46
47 void onDumpReport() override;
48
49private:
50 const CountMetric mMetric;
51
52 const sp<ConditionTracker> mConditionTracker;
53
54 const time_t mStartTime;
55 // TODO: Add dimensions.
Bookatza4bc9c42017-10-04 11:45:57 -070056 // Counter value for the current bucket.
Yao Chen44cf27c2017-09-14 22:32:50 -070057 int mCounter;
58
59 time_t mCurrentBucketStartTime;
60
61 long mBucketSize_sec;
62
Bookatza4bc9c42017-10-04 11:45:57 -070063 CountAnomalyTracker mAnomalyTracker;
64
Yao Chen44cf27c2017-09-14 22:32:50 -070065 void flushCounterIfNeeded(const time_t& newEventTime);
66};
67
68} // namespace statsd
69} // namespace os
70} // namespace android
71#endif // COUNT_METRIC_PRODUCER_H