Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -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 | |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 17 | #define DEBUG false |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 18 | #include "Log.h" |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 19 | |
Alec Mouri | 1dc5f1e | 2019-09-18 21:13:01 -0700 | [diff] [blame] | 20 | #include "StatsPullerManager.h" |
| 21 | |
Tej Singh | 6a5c943 | 2019-10-11 11:07:06 -0700 | [diff] [blame] | 22 | #include <android/os/IPullAtomCallback.h> |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 23 | #include <android/os/IStatsCompanionService.h> |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 24 | #include <cutils/log.h> |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 25 | #include <math.h> |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 26 | #include <stdint.h> |
Alec Mouri | 1dc5f1e | 2019-09-18 21:13:01 -0700 | [diff] [blame] | 27 | |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 28 | #include <algorithm> |
Alec Mouri | 1dc5f1e | 2019-09-18 21:13:01 -0700 | [diff] [blame] | 29 | #include <iostream> |
| 30 | |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 31 | #include "../StatsService.h" |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 32 | #include "../logd/LogEvent.h" |
| 33 | #include "../stats_log_util.h" |
| 34 | #include "../statscompanion_util.h" |
Yiwei Zhang | 7e63303 | 2019-03-01 17:25:27 -0800 | [diff] [blame] | 35 | #include "GpuStatsPuller.h" |
Tej Singh | a0c89dd | 2019-01-25 16:39:18 -0800 | [diff] [blame] | 36 | #include "StatsCallbackPuller.h" |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 37 | #include "TrainInfoPuller.h" |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 38 | #include "statslog.h" |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 39 | |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 40 | using std::make_shared; |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 41 | using std::map; |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 42 | using std::shared_ptr; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 43 | using std::string; |
| 44 | using std::vector; |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 45 | using std::list; |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 46 | |
| 47 | namespace android { |
| 48 | namespace os { |
| 49 | namespace statsd { |
| 50 | |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 51 | // Values smaller than this may require to update the alarm. |
| 52 | const int64_t NO_ALARM_UPDATE = INT64_MAX; |
| 53 | |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 54 | StatsPullerManager::StatsPullerManager() |
| 55 | : kAllPullAtomInfo({ |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 56 | // TrainInfo. |
| 57 | {{.atomTag = android::util::TRAIN_INFO}, new TrainInfoPuller()}, |
Jeffrey Huang | fdd3c7c | 2020-01-09 13:54:24 -0800 | [diff] [blame] | 58 | |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 59 | // GpuStatsGlobalInfo |
| 60 | {{.atomTag = android::util::GPU_STATS_GLOBAL_INFO}, |
| 61 | new GpuStatsPuller(android::util::GPU_STATS_GLOBAL_INFO)}, |
Jeffrey Huang | fdd3c7c | 2020-01-09 13:54:24 -0800 | [diff] [blame] | 62 | |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 63 | // GpuStatsAppInfo |
| 64 | {{.atomTag = android::util::GPU_STATS_APP_INFO}, |
| 65 | new GpuStatsPuller(android::util::GPU_STATS_APP_INFO)}, |
Jeffrey Huang | fdd3c7c | 2020-01-09 13:54:24 -0800 | [diff] [blame] | 66 | |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 67 | }), |
| 68 | mNextPullTimeNs(NO_ALARM_UPDATE) { |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 71 | bool StatsPullerManager::Pull(int tagId, vector<shared_ptr<LogEvent>>* data) { |
Tej Singh | fa1c137 | 2019-12-05 20:36:54 -0800 | [diff] [blame] | 72 | AutoMutex _l(mLock); |
| 73 | return PullLocked(tagId, data); |
| 74 | } |
| 75 | |
| 76 | bool StatsPullerManager::PullLocked(int tagId, vector<shared_ptr<LogEvent>>* data) { |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 77 | VLOG("Initiating pulling %d", tagId); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 78 | |
Tej Singh | 6a5c943 | 2019-10-11 11:07:06 -0700 | [diff] [blame] | 79 | if (kAllPullAtomInfo.find({.atomTag = tagId}) != kAllPullAtomInfo.end()) { |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 80 | bool ret = kAllPullAtomInfo.find({.atomTag = tagId})->second->Pull(data); |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 81 | VLOG("pulled %d items", (int)data->size()); |
Misha Wagner | 1eee221 | 2019-01-22 11:47:11 +0000 | [diff] [blame] | 82 | if (!ret) { |
| 83 | StatsdStats::getInstance().notePullFailed(tagId); |
| 84 | } |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 85 | return ret; |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 86 | } else { |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 87 | VLOG("Unknown tagId %d", tagId); |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 88 | return false; // Return early since we don't know what to pull. |
| 89 | } |
| 90 | } |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 91 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 92 | bool StatsPullerManager::PullerForMatcherExists(int tagId) const { |
Tej Singh | 97db3ff | 2020-01-27 16:52:17 -0800 | [diff] [blame] | 93 | // Pulled atoms might be registered after we parse the config, so just make sure the id is in |
| 94 | // an appropriate range. |
| 95 | return isVendorPulledAtom(tagId) || isPulledAtom(tagId); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 96 | } |
| 97 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 98 | void StatsPullerManager::updateAlarmLocked() { |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 99 | if (mNextPullTimeNs == NO_ALARM_UPDATE) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 100 | VLOG("No need to set alarms. Skipping"); |
| 101 | return; |
| 102 | } |
| 103 | |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 104 | sp<IStatsCompanionService> statsCompanionServiceCopy = mStatsCompanionService; |
| 105 | if (statsCompanionServiceCopy != nullptr) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 106 | statsCompanionServiceCopy->setPullingAlarm(mNextPullTimeNs / 1000000); |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 107 | } else { |
| 108 | VLOG("StatsCompanionService not available. Alarm not set."); |
| 109 | } |
| 110 | return; |
| 111 | } |
| 112 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 113 | void StatsPullerManager::SetStatsCompanionService( |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 114 | sp<IStatsCompanionService> statsCompanionService) { |
| 115 | AutoMutex _l(mLock); |
| 116 | sp<IStatsCompanionService> tmpForLock = mStatsCompanionService; |
| 117 | mStatsCompanionService = statsCompanionService; |
| 118 | for (const auto& pulledAtom : kAllPullAtomInfo) { |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 119 | pulledAtom.second->SetStatsCompanionService(statsCompanionService); |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 120 | } |
| 121 | if (mStatsCompanionService != nullptr) { |
| 122 | updateAlarmLocked(); |
| 123 | } |
| 124 | } |
| 125 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 126 | void StatsPullerManager::RegisterReceiver(int tagId, wp<PullDataReceiver> receiver, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 127 | int64_t nextPullTimeNs, int64_t intervalNs) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 128 | AutoMutex _l(mLock); |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 129 | auto& receivers = mReceivers[tagId]; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 130 | for (auto it = receivers.begin(); it != receivers.end(); it++) { |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 131 | if (it->receiver == receiver) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 132 | VLOG("Receiver already registered of %d", (int)receivers.size()); |
| 133 | return; |
| 134 | } |
| 135 | } |
| 136 | ReceiverInfo receiverInfo; |
| 137 | receiverInfo.receiver = receiver; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 138 | |
Chenjie Yu | 85ed838 | 2017-12-14 16:48:54 -0800 | [diff] [blame] | 139 | // Round it to the nearest minutes. This is the limit of alarm manager. |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 140 | // In practice, we should always have larger buckets. |
| 141 | int64_t roundedIntervalNs = intervalNs / NS_PER_SEC / 60 * NS_PER_SEC * 60; |
Chenjie Yu | 83baaa1 | 2018-03-19 10:41:35 -0700 | [diff] [blame] | 142 | // Scheduled pulling should be at least 1 min apart. |
| 143 | // This can be lower in cts tests, in which case we round it to 1 min. |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 144 | if (roundedIntervalNs < 60 * (int64_t)NS_PER_SEC) { |
| 145 | roundedIntervalNs = 60 * (int64_t)NS_PER_SEC; |
Chenjie Yu | 83baaa1 | 2018-03-19 10:41:35 -0700 | [diff] [blame] | 146 | } |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 147 | |
| 148 | receiverInfo.intervalNs = roundedIntervalNs; |
| 149 | receiverInfo.nextPullTimeNs = nextPullTimeNs; |
| 150 | receivers.push_back(receiverInfo); |
| 151 | |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 152 | // There is only one alarm for all pulled events. So only set it to the smallest denom. |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 153 | if (nextPullTimeNs < mNextPullTimeNs) { |
| 154 | VLOG("Updating next pull time %lld", (long long)mNextPullTimeNs); |
| 155 | mNextPullTimeNs = nextPullTimeNs; |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 156 | updateAlarmLocked(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 157 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 158 | VLOG("Puller for tagId %d registered of %d", tagId, (int)receivers.size()); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 161 | void StatsPullerManager::UnRegisterReceiver(int tagId, wp<PullDataReceiver> receiver) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 162 | AutoMutex _l(mLock); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 163 | if (mReceivers.find(tagId) == mReceivers.end()) { |
| 164 | VLOG("Unknown pull code or no receivers: %d", tagId); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 165 | return; |
| 166 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 167 | auto& receivers = mReceivers.find(tagId)->second; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 168 | for (auto it = receivers.begin(); it != receivers.end(); it++) { |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 169 | if (receiver == it->receiver) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 170 | receivers.erase(it); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 171 | VLOG("Puller for tagId %d unregistered of %d", tagId, (int)receivers.size()); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 172 | return; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 177 | void StatsPullerManager::OnAlarmFired(int64_t elapsedTimeNs) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 178 | AutoMutex _l(mLock); |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 179 | int64_t wallClockNs = getWallClockNs(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 180 | |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 181 | int64_t minNextPullTimeNs = NO_ALARM_UPDATE; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 182 | |
| 183 | vector<pair<int, vector<ReceiverInfo*>>> needToPull = |
| 184 | vector<pair<int, vector<ReceiverInfo*>>>(); |
| 185 | for (auto& pair : mReceivers) { |
| 186 | vector<ReceiverInfo*> receivers = vector<ReceiverInfo*>(); |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 187 | if (pair.second.size() != 0) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 188 | for (ReceiverInfo& receiverInfo : pair.second) { |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 189 | if (receiverInfo.nextPullTimeNs <= elapsedTimeNs) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 190 | receivers.push_back(&receiverInfo); |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 191 | } else { |
| 192 | if (receiverInfo.nextPullTimeNs < minNextPullTimeNs) { |
| 193 | minNextPullTimeNs = receiverInfo.nextPullTimeNs; |
| 194 | } |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | if (receivers.size() > 0) { |
| 198 | needToPull.push_back(make_pair(pair.first, receivers)); |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | for (const auto& pullInfo : needToPull) { |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 204 | vector<shared_ptr<LogEvent>> data; |
Tej Singh | fa1c137 | 2019-12-05 20:36:54 -0800 | [diff] [blame] | 205 | bool pullSuccess = PullLocked(pullInfo.first, &data); |
Olivier Gaillard | c5f11c4 | 2019-02-05 12:44:58 +0000 | [diff] [blame] | 206 | if (pullSuccess) { |
| 207 | StatsdStats::getInstance().notePullDelay( |
| 208 | pullInfo.first, getElapsedRealtimeNs() - elapsedTimeNs); |
| 209 | } else { |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 210 | VLOG("pull failed at %lld, will try again later", (long long)elapsedTimeNs); |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 211 | } |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 212 | |
| 213 | // Convention is to mark pull atom timestamp at request time. |
| 214 | // If we pull at t0, puller starts at t1, finishes at t2, and send back |
| 215 | // at t3, we mark t0 as its timestamp, which should correspond to its |
| 216 | // triggering event, such as condition change at t0. |
| 217 | // Here the triggering event is alarm fired from AlarmManager. |
| 218 | // In ValueMetricProducer and GaugeMetricProducer we do same thing |
| 219 | // when pull on condition change, etc. |
| 220 | for (auto& event : data) { |
| 221 | event->setElapsedTimestampNs(elapsedTimeNs); |
| 222 | event->setLogdWallClockTimestampNs(wallClockNs); |
| 223 | } |
| 224 | |
| 225 | for (const auto& receiverInfo : pullInfo.second) { |
| 226 | sp<PullDataReceiver> receiverPtr = receiverInfo->receiver.promote(); |
| 227 | if (receiverPtr != nullptr) { |
Olivier Gaillard | 11203df | 2019-02-06 13:18:09 +0000 | [diff] [blame] | 228 | receiverPtr->onDataPulled(data, pullSuccess, elapsedTimeNs); |
Olivier Gaillard | c5f11c4 | 2019-02-05 12:44:58 +0000 | [diff] [blame] | 229 | // We may have just come out of a coma, compute next pull time. |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 230 | int numBucketsAhead = |
| 231 | (elapsedTimeNs - receiverInfo->nextPullTimeNs) / receiverInfo->intervalNs; |
| 232 | receiverInfo->nextPullTimeNs += (numBucketsAhead + 1) * receiverInfo->intervalNs; |
| 233 | if (receiverInfo->nextPullTimeNs < minNextPullTimeNs) { |
| 234 | minNextPullTimeNs = receiverInfo->nextPullTimeNs; |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 235 | } |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 236 | } else { |
| 237 | VLOG("receiver already gone."); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 238 | } |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 239 | } |
| 240 | } |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 241 | |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 242 | VLOG("mNextPullTimeNs: %lld updated to %lld", (long long)mNextPullTimeNs, |
| 243 | (long long)minNextPullTimeNs); |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 244 | mNextPullTimeNs = minNextPullTimeNs; |
| 245 | updateAlarmLocked(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 248 | int StatsPullerManager::ForceClearPullerCache() { |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 249 | int totalCleared = 0; |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 250 | for (const auto& pulledAtom : kAllPullAtomInfo) { |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 251 | totalCleared += pulledAtom.second->ForceClearCache(); |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 252 | } |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 253 | return totalCleared; |
| 254 | } |
| 255 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 256 | int StatsPullerManager::ClearPullerCacheIfNecessary(int64_t timestampNs) { |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 257 | int totalCleared = 0; |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 258 | for (const auto& pulledAtom : kAllPullAtomInfo) { |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 259 | totalCleared += pulledAtom.second->ClearCacheIfNecessary(timestampNs); |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 260 | } |
| 261 | return totalCleared; |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 262 | } |
| 263 | |
Tej Singh | 6a5c943 | 2019-10-11 11:07:06 -0700 | [diff] [blame] | 264 | void StatsPullerManager::RegisterPullAtomCallback(const int uid, const int32_t atomTag, |
| 265 | const int64_t coolDownNs, const int64_t timeoutNs, |
| 266 | const vector<int32_t>& additiveFields, |
| 267 | const sp<IPullAtomCallback>& callback) { |
| 268 | AutoMutex _l(mLock); |
| 269 | VLOG("RegisterPullerCallback: adding puller for tag %d", atomTag); |
| 270 | // TODO: linkToDeath with the callback so that we can remove it and delete the puller. |
| 271 | StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/true); |
Tej Singh | 5b4951b | 2020-01-24 13:23:56 -0800 | [diff] [blame] | 272 | kAllPullAtomInfo[{.atomTag = atomTag}] = |
| 273 | new StatsCallbackPuller(atomTag, callback, coolDownNs, timeoutNs, additiveFields); |
Tej Singh | a0c89dd | 2019-01-25 16:39:18 -0800 | [diff] [blame] | 274 | } |
| 275 | |
Tej Singh | fa1c137 | 2019-12-05 20:36:54 -0800 | [diff] [blame] | 276 | void StatsPullerManager::UnregisterPullAtomCallback(const int uid, const int32_t atomTag) { |
| 277 | AutoMutex _l(mLock); |
| 278 | StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/false); |
| 279 | kAllPullAtomInfo.erase({.atomTag = atomTag}); |
| 280 | } |
| 281 | |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 282 | } // namespace statsd |
| 283 | } // namespace os |
| 284 | } // namespace android |