blob: 79315eb170602afcf86a958f205cd7053cbd1213 [file] [log] [blame]
Chenjie Yu1a317ba2017-10-05 16:05:32 -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
Chenjie Yu80f91122018-01-31 20:24:50 -080017#define DEBUG false
Joe Onorato9fc9edf2017-10-15 20:08:52 -070018#include "Log.h"
Chenjie Yu1a317ba2017-10-05 16:05:32 -070019
Alec Mouri1dc5f1e2019-09-18 21:13:01 -070020#include "StatsPullerManager.h"
21
David Chen1481fe12017-10-16 13:16:34 -070022#include <cutils/log.h>
Chenjie Yu1a0a9412018-03-28 10:07:22 -070023#include <math.h>
Chenjie Yu3b3adcd2018-04-18 16:25:36 -070024#include <stdint.h>
Alec Mouri1dc5f1e2019-09-18 21:13:01 -070025
David Chen1481fe12017-10-16 13:16:34 -070026#include <algorithm>
Alec Mouri1dc5f1e2019-09-18 21:13:01 -070027#include <iostream>
28
Chenjie Yu1a0a9412018-03-28 10:07:22 -070029#include "../StatsService.h"
Chenjie Yuaa5b2012018-03-21 13:53:15 -070030#include "../logd/LogEvent.h"
31#include "../stats_log_util.h"
32#include "../statscompanion_util.h"
Tej Singha0c89dd2019-01-25 16:39:18 -080033#include "StatsCallbackPuller.h"
Chenjie Yu97dbb202019-02-13 16:42:04 -080034#include "TrainInfoPuller.h"
Jeffrey Huang74fc4352020-03-06 15:18:33 -080035#include "statslog_statsd.h"
David Chen1481fe12017-10-16 13:16:34 -070036
Yao Chen93fe3a32017-11-02 13:52:59 -070037using std::shared_ptr;
Chenjie Yub3dda412017-10-24 13:41:59 -070038using std::vector;
Chenjie Yu1a317ba2017-10-05 16:05:32 -070039
40namespace android {
41namespace os {
42namespace statsd {
43
Tej Singhdd25c822020-04-01 14:59:36 -070044// Stores the puller as a wp to avoid holding a reference in case it is unregistered and
45// pullAtomCallbackDied is never called.
46struct PullAtomCallbackDeathCookie {
47 PullAtomCallbackDeathCookie(sp<StatsPullerManager> pullerManager, const PullerKey& pullerKey,
48 const wp<StatsPuller>& puller)
49 : mPullerManager(pullerManager), mPullerKey(pullerKey), mPuller(puller) {
50 }
51
52 sp<StatsPullerManager> mPullerManager;
53 PullerKey mPullerKey;
54 wp<StatsPuller> mPuller;
55};
56
57void StatsPullerManager::pullAtomCallbackDied(void* cookie) {
58 PullAtomCallbackDeathCookie* cookie_ = static_cast<PullAtomCallbackDeathCookie*>(cookie);
59 sp<StatsPullerManager>& thiz = cookie_->mPullerManager;
60 const PullerKey& pullerKey = cookie_->mPullerKey;
61 wp<StatsPuller> puller = cookie_->mPuller;
62
63 // Erase the mapping from the puller key to the puller if the mapping still exists.
64 // Note that we are removing the StatsPuller object, which internally holds the binder
65 // IPullAtomCallback. However, each new registration creates a new StatsPuller, so this works.
66 lock_guard<mutex> lock(thiz->mLock);
67 const auto& it = thiz->kAllPullAtomInfo.find(pullerKey);
68 if (it != thiz->kAllPullAtomInfo.end() && puller != nullptr && puller == it->second) {
69 StatsdStats::getInstance().notePullerCallbackRegistrationChanged(pullerKey.atomTag,
70 /*registered=*/false);
71 thiz->kAllPullAtomInfo.erase(pullerKey);
72 }
73 // The death recipient corresponding to this specific IPullAtomCallback can never
74 // be triggered again, so free up resources.
75 delete cookie_;
76}
77
Chenjie Yu3b3adcd2018-04-18 16:25:36 -070078// Values smaller than this may require to update the alarm.
79const int64_t NO_ALARM_UPDATE = INT64_MAX;
80
Tej Singh5b4951b2020-01-24 13:23:56 -080081StatsPullerManager::StatsPullerManager()
82 : kAllPullAtomInfo({
Tej Singh5b4951b2020-01-24 13:23:56 -080083 // TrainInfo.
Tej Singh3be093b2020-03-04 20:08:38 -080084 {{.atomTag = util::TRAIN_INFO, .uid = -1}, new TrainInfoPuller()},
Tej Singh5b4951b2020-01-24 13:23:56 -080085 }),
Tej Singhdd25c822020-04-01 14:59:36 -070086 mNextPullTimeNs(NO_ALARM_UPDATE),
87 mPullAtomCallbackDeathRecipient(AIBinder_DeathRecipient_new(pullAtomCallbackDied)) {
Chenjie Yu1a317ba2017-10-05 16:05:32 -070088}
89
Tej Singh3be093b2020-03-04 20:08:38 -080090bool StatsPullerManager::Pull(int tagId, const ConfigKey& configKey,
91 vector<shared_ptr<LogEvent>>* data, bool useUids) {
92 std::lock_guard<std::mutex> _l(mLock);
93 return PullLocked(tagId, configKey, data, useUids);
Tej Singhfa1c1372019-12-05 20:36:54 -080094}
95
Tej Singh3be093b2020-03-04 20:08:38 -080096bool StatsPullerManager::Pull(int tagId, const vector<int32_t>& uids,
97 vector<std::shared_ptr<LogEvent>>* data, bool useUids) {
98 std::lock_guard<std::mutex> _l(mLock);
99 return PullLocked(tagId, uids, data, useUids);
100}
Chenjie Yub3dda412017-10-24 13:41:59 -0700101
Tej Singh3be093b2020-03-04 20:08:38 -0800102bool StatsPullerManager::PullLocked(int tagId, const ConfigKey& configKey,
103 vector<shared_ptr<LogEvent>>* data, bool useUids) {
104 vector<int32_t> uids;
105 if (useUids) {
106 auto uidProviderIt = mPullUidProviders.find(configKey);
107 if (uidProviderIt == mPullUidProviders.end()) {
108 ALOGE("Error pulling tag %d. No pull uid provider for config key %s", tagId,
109 configKey.ToString().c_str());
110 return false;
Misha Wagner1eee2212019-01-22 11:47:11 +0000111 }
Tej Singh3be093b2020-03-04 20:08:38 -0800112 sp<PullUidProvider> pullUidProvider = uidProviderIt->second.promote();
113 if (pullUidProvider == nullptr) {
114 ALOGE("Error pulling tag %d, pull uid provider for config %s is gone.", tagId,
115 configKey.ToString().c_str());
116 return false;
117 }
118 uids = pullUidProvider->getPullAtomUids(tagId);
119 }
120 return PullLocked(tagId, uids, data, useUids);
121}
122
123bool StatsPullerManager::PullLocked(int tagId, const vector<int32_t>& uids,
124 vector<shared_ptr<LogEvent>>* data, bool useUids) {
125 VLOG("Initiating pulling %d", tagId);
126 if (useUids) {
127 for (int32_t uid : uids) {
128 PullerKey key = {.atomTag = tagId, .uid = uid};
129 auto pullerIt = kAllPullAtomInfo.find(key);
130 if (pullerIt != kAllPullAtomInfo.end()) {
131 bool ret = pullerIt->second->Pull(data);
132 VLOG("pulled %zu items", data->size());
133 if (!ret) {
134 StatsdStats::getInstance().notePullFailed(tagId);
135 }
136 return ret;
137 }
138 }
139 ALOGW("StatsPullerManager: Unknown tagId %d", tagId);
140 return false; // Return early since we don't know what to pull.
Yao Chen93fe3a32017-11-02 13:52:59 -0700141 } else {
Tej Singh3be093b2020-03-04 20:08:38 -0800142 PullerKey key = {.atomTag = tagId, .uid = -1};
143 auto pullerIt = kAllPullAtomInfo.find(key);
144 if (pullerIt != kAllPullAtomInfo.end()) {
145 bool ret = pullerIt->second->Pull(data);
146 VLOG("pulled %zu items", data->size());
147 if (!ret) {
148 StatsdStats::getInstance().notePullFailed(tagId);
149 }
150 return ret;
151 }
Tej Singh730ed292020-02-03 17:24:27 -0800152 ALOGW("StatsPullerManager: Unknown tagId %d", tagId);
Yao Chen93fe3a32017-11-02 13:52:59 -0700153 return false; // Return early since we don't know what to pull.
154 }
155}
Chenjie Yub3dda412017-10-24 13:41:59 -0700156
Chenjie Yue2219202018-06-08 10:07:51 -0700157bool StatsPullerManager::PullerForMatcherExists(int tagId) const {
Tej Singh97db3ff2020-01-27 16:52:17 -0800158 // Pulled atoms might be registered after we parse the config, so just make sure the id is in
159 // an appropriate range.
160 return isVendorPulledAtom(tagId) || isPulledAtom(tagId);
Chenjie Yub3dda412017-10-24 13:41:59 -0700161}
162
Chenjie Yue2219202018-06-08 10:07:51 -0700163void StatsPullerManager::updateAlarmLocked() {
Chenjie Yu3b3adcd2018-04-18 16:25:36 -0700164 if (mNextPullTimeNs == NO_ALARM_UPDATE) {
Chenjie Yu1a0a9412018-03-28 10:07:22 -0700165 VLOG("No need to set alarms. Skipping");
166 return;
167 }
168
Ruchir Rastogi1497e8f2020-03-03 16:04:42 -0800169 // TODO(b/151045771): do not hold a lock while making a binder call
170 if (mStatsCompanionService != nullptr) {
171 mStatsCompanionService->setPullingAlarm(mNextPullTimeNs / 1000000);
Chenjie Yuaa5b2012018-03-21 13:53:15 -0700172 } else {
173 VLOG("StatsCompanionService not available. Alarm not set.");
174 }
175 return;
176}
177
Chenjie Yue2219202018-06-08 10:07:51 -0700178void StatsPullerManager::SetStatsCompanionService(
Ruchir Rastogie449b0c2020-02-10 17:40:09 -0800179 shared_ptr<IStatsCompanionService> statsCompanionService) {
Tej Singh3be093b2020-03-04 20:08:38 -0800180 std::lock_guard<std::mutex> _l(mLock);
Ruchir Rastogie449b0c2020-02-10 17:40:09 -0800181 shared_ptr<IStatsCompanionService> tmpForLock = mStatsCompanionService;
Chenjie Yuaa5b2012018-03-21 13:53:15 -0700182 mStatsCompanionService = statsCompanionService;
183 for (const auto& pulledAtom : kAllPullAtomInfo) {
Tej Singh5b4951b2020-01-24 13:23:56 -0800184 pulledAtom.second->SetStatsCompanionService(statsCompanionService);
Chenjie Yuaa5b2012018-03-21 13:53:15 -0700185 }
186 if (mStatsCompanionService != nullptr) {
187 updateAlarmLocked();
188 }
189}
190
Tej Singh3be093b2020-03-04 20:08:38 -0800191void StatsPullerManager::RegisterReceiver(int tagId, const ConfigKey& configKey,
192 wp<PullDataReceiver> receiver, int64_t nextPullTimeNs,
193 int64_t intervalNs) {
194 std::lock_guard<std::mutex> _l(mLock);
195 auto& receivers = mReceivers[{.atomTag = tagId, .configKey = configKey}];
Chenjie Yub3dda412017-10-24 13:41:59 -0700196 for (auto it = receivers.begin(); it != receivers.end(); it++) {
Chenjie Yu6736c892017-11-09 10:50:09 -0800197 if (it->receiver == receiver) {
Chenjie Yub3dda412017-10-24 13:41:59 -0700198 VLOG("Receiver already registered of %d", (int)receivers.size());
199 return;
200 }
201 }
202 ReceiverInfo receiverInfo;
203 receiverInfo.receiver = receiver;
Chenjie Yub3dda412017-10-24 13:41:59 -0700204
Chenjie Yu85ed8382017-12-14 16:48:54 -0800205 // Round it to the nearest minutes. This is the limit of alarm manager.
Chenjie Yu1a0a9412018-03-28 10:07:22 -0700206 // In practice, we should always have larger buckets.
207 int64_t roundedIntervalNs = intervalNs / NS_PER_SEC / 60 * NS_PER_SEC * 60;
Chenjie Yu83baaa12018-03-19 10:41:35 -0700208 // Scheduled pulling should be at least 1 min apart.
209 // This can be lower in cts tests, in which case we round it to 1 min.
Chenjie Yu1a0a9412018-03-28 10:07:22 -0700210 if (roundedIntervalNs < 60 * (int64_t)NS_PER_SEC) {
211 roundedIntervalNs = 60 * (int64_t)NS_PER_SEC;
Chenjie Yu83baaa12018-03-19 10:41:35 -0700212 }
Chenjie Yu1a0a9412018-03-28 10:07:22 -0700213
214 receiverInfo.intervalNs = roundedIntervalNs;
215 receiverInfo.nextPullTimeNs = nextPullTimeNs;
216 receivers.push_back(receiverInfo);
217
Chenjie Yub3dda412017-10-24 13:41:59 -0700218 // There is only one alarm for all pulled events. So only set it to the smallest denom.
Chenjie Yu1a0a9412018-03-28 10:07:22 -0700219 if (nextPullTimeNs < mNextPullTimeNs) {
220 VLOG("Updating next pull time %lld", (long long)mNextPullTimeNs);
221 mNextPullTimeNs = nextPullTimeNs;
Chenjie Yuaa5b2012018-03-21 13:53:15 -0700222 updateAlarmLocked();
Chenjie Yub3dda412017-10-24 13:41:59 -0700223 }
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700224 VLOG("Puller for tagId %d registered of %d", tagId, (int)receivers.size());
Chenjie Yub3dda412017-10-24 13:41:59 -0700225}
226
Tej Singh3be093b2020-03-04 20:08:38 -0800227void StatsPullerManager::UnRegisterReceiver(int tagId, const ConfigKey& configKey,
228 wp<PullDataReceiver> receiver) {
229 std::lock_guard<std::mutex> _l(mLock);
230 auto receiversIt = mReceivers.find({.atomTag = tagId, .configKey = configKey});
231 if (receiversIt == mReceivers.end()) {
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700232 VLOG("Unknown pull code or no receivers: %d", tagId);
Chenjie Yub3dda412017-10-24 13:41:59 -0700233 return;
234 }
Tej Singh3be093b2020-03-04 20:08:38 -0800235 std::list<ReceiverInfo>& receivers = receiversIt->second;
Chenjie Yub3dda412017-10-24 13:41:59 -0700236 for (auto it = receivers.begin(); it != receivers.end(); it++) {
Chenjie Yu6736c892017-11-09 10:50:09 -0800237 if (receiver == it->receiver) {
Chenjie Yub3dda412017-10-24 13:41:59 -0700238 receivers.erase(it);
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700239 VLOG("Puller for tagId %d unregistered of %d", tagId, (int)receivers.size());
Chenjie Yub3dda412017-10-24 13:41:59 -0700240 return;
241 }
242 }
243}
244
Tej Singh3be093b2020-03-04 20:08:38 -0800245void StatsPullerManager::RegisterPullUidProvider(const ConfigKey& configKey,
246 wp<PullUidProvider> provider) {
247 std::lock_guard<std::mutex> _l(mLock);
248 mPullUidProviders[configKey] = provider;
249}
250
251void StatsPullerManager::UnregisterPullUidProvider(const ConfigKey& configKey) {
252 std::lock_guard<std::mutex> _l(mLock);
253 mPullUidProviders.erase(configKey);
254}
255
Chenjie Yu0bd73db2018-12-16 07:37:04 -0800256void StatsPullerManager::OnAlarmFired(int64_t elapsedTimeNs) {
Tej Singh3be093b2020-03-04 20:08:38 -0800257 std::lock_guard<std::mutex> _l(mLock);
Chenjie Yu0bd73db2018-12-16 07:37:04 -0800258 int64_t wallClockNs = getWallClockNs();
Chenjie Yub3dda412017-10-24 13:41:59 -0700259
Chenjie Yu3b3adcd2018-04-18 16:25:36 -0700260 int64_t minNextPullTimeNs = NO_ALARM_UPDATE;
Chenjie Yub3dda412017-10-24 13:41:59 -0700261
Tej Singh3be093b2020-03-04 20:08:38 -0800262 vector<pair<const ReceiverKey*, vector<ReceiverInfo*>>> needToPull;
Chenjie Yub3dda412017-10-24 13:41:59 -0700263 for (auto& pair : mReceivers) {
Tej Singh3be093b2020-03-04 20:08:38 -0800264 vector<ReceiverInfo*> receivers;
Yao Chen93fe3a32017-11-02 13:52:59 -0700265 if (pair.second.size() != 0) {
Chenjie Yu1a0a9412018-03-28 10:07:22 -0700266 for (ReceiverInfo& receiverInfo : pair.second) {
Chenjie Yu0bd73db2018-12-16 07:37:04 -0800267 if (receiverInfo.nextPullTimeNs <= elapsedTimeNs) {
Chenjie Yub3dda412017-10-24 13:41:59 -0700268 receivers.push_back(&receiverInfo);
Chenjie Yu1a0a9412018-03-28 10:07:22 -0700269 } else {
270 if (receiverInfo.nextPullTimeNs < minNextPullTimeNs) {
271 minNextPullTimeNs = receiverInfo.nextPullTimeNs;
272 }
Chenjie Yub3dda412017-10-24 13:41:59 -0700273 }
274 }
275 if (receivers.size() > 0) {
Tej Singh3be093b2020-03-04 20:08:38 -0800276 needToPull.push_back(make_pair(&pair.first, receivers));
Chenjie Yub3dda412017-10-24 13:41:59 -0700277 }
278 }
279 }
Chenjie Yub3dda412017-10-24 13:41:59 -0700280 for (const auto& pullInfo : needToPull) {
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700281 vector<shared_ptr<LogEvent>> data;
Tej Singh3be093b2020-03-04 20:08:38 -0800282 bool pullSuccess = PullLocked(pullInfo.first->atomTag, pullInfo.first->configKey, &data);
Olivier Gaillardc5f11c42019-02-05 12:44:58 +0000283 if (pullSuccess) {
Tej Singh3be093b2020-03-04 20:08:38 -0800284 StatsdStats::getInstance().notePullDelay(pullInfo.first->atomTag,
285 getElapsedRealtimeNs() - elapsedTimeNs);
Olivier Gaillardc5f11c42019-02-05 12:44:58 +0000286 } else {
Chenjie Yu0bd73db2018-12-16 07:37:04 -0800287 VLOG("pull failed at %lld, will try again later", (long long)elapsedTimeNs);
Chenjie Yu0bd73db2018-12-16 07:37:04 -0800288 }
Chenjie Yu0bd73db2018-12-16 07:37:04 -0800289
290 // Convention is to mark pull atom timestamp at request time.
291 // If we pull at t0, puller starts at t1, finishes at t2, and send back
292 // at t3, we mark t0 as its timestamp, which should correspond to its
293 // triggering event, such as condition change at t0.
294 // Here the triggering event is alarm fired from AlarmManager.
295 // In ValueMetricProducer and GaugeMetricProducer we do same thing
296 // when pull on condition change, etc.
297 for (auto& event : data) {
298 event->setElapsedTimestampNs(elapsedTimeNs);
299 event->setLogdWallClockTimestampNs(wallClockNs);
300 }
301
302 for (const auto& receiverInfo : pullInfo.second) {
303 sp<PullDataReceiver> receiverPtr = receiverInfo->receiver.promote();
304 if (receiverPtr != nullptr) {
Olivier Gaillard11203df2019-02-06 13:18:09 +0000305 receiverPtr->onDataPulled(data, pullSuccess, elapsedTimeNs);
Olivier Gaillardc5f11c42019-02-05 12:44:58 +0000306 // We may have just come out of a coma, compute next pull time.
Chenjie Yu0bd73db2018-12-16 07:37:04 -0800307 int numBucketsAhead =
308 (elapsedTimeNs - receiverInfo->nextPullTimeNs) / receiverInfo->intervalNs;
309 receiverInfo->nextPullTimeNs += (numBucketsAhead + 1) * receiverInfo->intervalNs;
310 if (receiverInfo->nextPullTimeNs < minNextPullTimeNs) {
311 minNextPullTimeNs = receiverInfo->nextPullTimeNs;
Chenjie Yu6736c892017-11-09 10:50:09 -0800312 }
Chenjie Yu0bd73db2018-12-16 07:37:04 -0800313 } else {
314 VLOG("receiver already gone.");
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700315 }
Chenjie Yub3dda412017-10-24 13:41:59 -0700316 }
317 }
Chenjie Yu1a0a9412018-03-28 10:07:22 -0700318
Chenjie Yu3b3adcd2018-04-18 16:25:36 -0700319 VLOG("mNextPullTimeNs: %lld updated to %lld", (long long)mNextPullTimeNs,
320 (long long)minNextPullTimeNs);
Chenjie Yu1a0a9412018-03-28 10:07:22 -0700321 mNextPullTimeNs = minNextPullTimeNs;
322 updateAlarmLocked();
Chenjie Yub3dda412017-10-24 13:41:59 -0700323}
324
Chenjie Yue2219202018-06-08 10:07:51 -0700325int StatsPullerManager::ForceClearPullerCache() {
Chenjie Yufa22d652018-02-05 14:37:48 -0800326 int totalCleared = 0;
Chenjie Yu80f91122018-01-31 20:24:50 -0800327 for (const auto& pulledAtom : kAllPullAtomInfo) {
Tej Singh5b4951b2020-01-24 13:23:56 -0800328 totalCleared += pulledAtom.second->ForceClearCache();
Chenjie Yue72252b2018-02-01 13:19:35 -0800329 }
Chenjie Yufa22d652018-02-05 14:37:48 -0800330 return totalCleared;
331}
332
Chenjie Yue2219202018-06-08 10:07:51 -0700333int StatsPullerManager::ClearPullerCacheIfNecessary(int64_t timestampNs) {
Chenjie Yufa22d652018-02-05 14:37:48 -0800334 int totalCleared = 0;
Chenjie Yu80f91122018-01-31 20:24:50 -0800335 for (const auto& pulledAtom : kAllPullAtomInfo) {
Tej Singh5b4951b2020-01-24 13:23:56 -0800336 totalCleared += pulledAtom.second->ClearCacheIfNecessary(timestampNs);
Chenjie Yufa22d652018-02-05 14:37:48 -0800337 }
338 return totalCleared;
Chenjie Yue72252b2018-02-01 13:19:35 -0800339}
340
Tej Singh6a5c9432019-10-11 11:07:06 -0700341void StatsPullerManager::RegisterPullAtomCallback(const int uid, const int32_t atomTag,
342 const int64_t coolDownNs, const int64_t timeoutNs,
343 const vector<int32_t>& additiveFields,
Tej Singh3be093b2020-03-04 20:08:38 -0800344 const shared_ptr<IPullAtomCallback>& callback,
345 bool useUid) {
346 std::lock_guard<std::mutex> _l(mLock);
Tej Singh6a5c9432019-10-11 11:07:06 -0700347 VLOG("RegisterPullerCallback: adding puller for tag %d", atomTag);
Tej Singhdd25c822020-04-01 14:59:36 -0700348
Tej Singh6a5c9432019-10-11 11:07:06 -0700349 StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/true);
Tej Singhabc1b8de2020-03-30 17:19:36 -0700350 int64_t actualCoolDownNs = coolDownNs < kMinCoolDownNs ? kMinCoolDownNs : coolDownNs;
351 int64_t actualTimeoutNs = timeoutNs > kMaxTimeoutNs ? kMaxTimeoutNs : timeoutNs;
Tej Singhdd25c822020-04-01 14:59:36 -0700352
353 sp<StatsCallbackPuller> puller = new StatsCallbackPuller(atomTag, callback, actualCoolDownNs,
354 actualTimeoutNs, additiveFields);
355 PullerKey key = {.atomTag = atomTag, .uid = useUid ? uid : -1};
356 AIBinder_linkToDeath(callback->asBinder().get(), mPullAtomCallbackDeathRecipient.get(),
357 new PullAtomCallbackDeathCookie(this, key, puller));
358 kAllPullAtomInfo[key] = puller;
Tej Singha0c89dd2019-01-25 16:39:18 -0800359}
360
Tej Singhdd25c822020-04-01 14:59:36 -0700361void StatsPullerManager::UnregisterPullAtomCallback(const int uid, const int32_t atomTag,
362 bool useUids) {
Tej Singh3be093b2020-03-04 20:08:38 -0800363 std::lock_guard<std::mutex> _l(mLock);
Tej Singhdd25c822020-04-01 14:59:36 -0700364 PullerKey key = {.atomTag = atomTag, .uid = useUids ? uid : -1};
365 if (kAllPullAtomInfo.find(key) != kAllPullAtomInfo.end()) {
366 StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag,
367 /*registered=*/false);
368 kAllPullAtomInfo.erase(key);
369 }
Tej Singhfa1c1372019-12-05 20:36:54 -0800370}
371
Chenjie Yu1a317ba2017-10-05 16:05:32 -0700372} // namespace statsd
373} // namespace os
374} // namespace android