Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 24 | namespace android { |
| 25 | namespace os { |
| 26 | namespace 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. |
| 31 | class MaxDurationTracker : public DurationTracker { |
| 32 | public: |
| 33 | MaxDurationTracker(sp<ConditionWizard> wizard, int conditionIndex, |
| 34 | uint64_t currentBucketStartNs, uint64_t bucketSizeNs, |
yro | 2b0f886 | 2017-11-06 14:27:31 -0800 | [diff] [blame^] | 35 | std::vector<DurationBucket>& bucket); |
Yao Chen | 5154a37 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 36 | 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 | |
| 44 | private: |
| 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 |