blob: de53d626c65dde00c8d1e1555f91747990c8a1d7 [file] [log] [blame]
Yao Chen5154a372017-10-30 22:57:06 -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 MAX_DURATION_TRACKER_H
18#define MAX_DURATION_TRACKER_H
19
20#include "DurationTracker.h"
21
22#include "frameworks/base/cmds/statsd/src/stats_log.pb.h"
23
24namespace android {
25namespace os {
26namespace statsd {
27
28// Tracks a pool of atom durations, and output the max duration for each bucket.
29// To get max duration, we need to keep track of each individual durations, and compare them when
30// they stop or bucket expires.
31class MaxDurationTracker : public DurationTracker {
32public:
33 MaxDurationTracker(sp<ConditionWizard> wizard, int conditionIndex,
34 uint64_t currentBucketStartNs, uint64_t bucketSizeNs,
yro2b0f8862017-11-06 14:27:31 -080035 std::vector<DurationBucket>& bucket);
Yao Chen5154a372017-10-30 22:57:06 -070036 void noteStart(const HashableDimensionKey& key, bool condition, const uint64_t eventTime,
37 const ConditionKey& conditionKey) override;
38 void noteStop(const HashableDimensionKey& key, const uint64_t eventTime) override;
39 void noteStopAll(const uint64_t eventTime) override;
40 bool flushIfNeeded(uint64_t timestampNs) override;
41 void onSlicedConditionMayChange(const uint64_t timestamp) override;
42 void onConditionChanged(bool condition, const uint64_t timestamp) override;
43
44private:
45 std::map<HashableDimensionKey, DurationInfo> mInfos;
46
47 void noteConditionChanged(const HashableDimensionKey& key, bool conditionMet,
48 const uint64_t timestamp);
49};
50
51} // namespace statsd
52} // namespace os
53} // namespace android
54
55#endif // MAX_DURATION_TRACKER_H