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 | |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 20 | #include <android/os/IStatsCompanionService.h> |
Tej Singh | a0c89dd | 2019-01-25 16:39:18 -0800 | [diff] [blame] | 21 | #include <android/os/IStatsPullerCallback.h> |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 22 | #include <cutils/log.h> |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 23 | #include <math.h> |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 24 | #include <stdint.h> |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 25 | #include <algorithm> |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 26 | #include "../StatsService.h" |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 27 | #include "../logd/LogEvent.h" |
| 28 | #include "../stats_log_util.h" |
| 29 | #include "../statscompanion_util.h" |
Bookatz | 92da283 | 2018-11-01 18:10:03 -0700 | [diff] [blame] | 30 | #include "PowerStatsPuller.h" |
Tej Singh | 4029831 | 2018-02-16 00:15:09 -0800 | [diff] [blame] | 31 | #include "ResourceHealthManagerPuller.h" |
Tej Singh | a0c89dd | 2019-01-25 16:39:18 -0800 | [diff] [blame] | 32 | #include "StatsCallbackPuller.h" |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 33 | #include "StatsCompanionServicePuller.h" |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 34 | #include "StatsPullerManager.h" |
Tej Singh | bf972d9 | 2018-01-10 20:51:13 -0800 | [diff] [blame] | 35 | #include "SubsystemSleepStatePuller.h" |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 36 | #include "TrainInfoPuller.h" |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 37 | #include "statslog.h" |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 38 | |
| 39 | #include <iostream> |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 40 | |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 41 | using std::make_shared; |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 42 | using std::map; |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 43 | using std::shared_ptr; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 44 | using std::string; |
| 45 | using std::vector; |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 46 | using std::list; |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 47 | |
| 48 | namespace android { |
| 49 | namespace os { |
| 50 | namespace statsd { |
| 51 | |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 52 | // Values smaller than this may require to update the alarm. |
| 53 | const int64_t NO_ALARM_UPDATE = INT64_MAX; |
| 54 | |
Tej Singh | a0c89dd | 2019-01-25 16:39:18 -0800 | [diff] [blame] | 55 | std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = { |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 56 | // wifi_bytes_transfer |
| 57 | {android::util::WIFI_BYTES_TRANSFER, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 58 | {.additiveFields = {2, 3, 4, 5}, |
| 59 | .puller = new StatsCompanionServicePuller(android::util::WIFI_BYTES_TRANSFER)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 60 | // wifi_bytes_transfer_by_fg_bg |
| 61 | {android::util::WIFI_BYTES_TRANSFER_BY_FG_BG, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 62 | {.additiveFields = {3, 4, 5, 6}, |
| 63 | .puller = new StatsCompanionServicePuller(android::util::WIFI_BYTES_TRANSFER_BY_FG_BG)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 64 | // mobile_bytes_transfer |
| 65 | {android::util::MOBILE_BYTES_TRANSFER, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 66 | {.additiveFields = {2, 3, 4, 5}, |
| 67 | .puller = new StatsCompanionServicePuller(android::util::MOBILE_BYTES_TRANSFER)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 68 | // mobile_bytes_transfer_by_fg_bg |
| 69 | {android::util::MOBILE_BYTES_TRANSFER_BY_FG_BG, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 70 | {.additiveFields = {3, 4, 5, 6}, |
| 71 | .puller = |
| 72 | new StatsCompanionServicePuller(android::util::MOBILE_BYTES_TRANSFER_BY_FG_BG)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 73 | // bluetooth_bytes_transfer |
| 74 | {android::util::BLUETOOTH_BYTES_TRANSFER, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 75 | {.additiveFields = {2, 3}, |
| 76 | .puller = new StatsCompanionServicePuller(android::util::BLUETOOTH_BYTES_TRANSFER)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 77 | // kernel_wakelock |
| 78 | {android::util::KERNEL_WAKELOCK, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 79 | {.puller = new StatsCompanionServicePuller(android::util::KERNEL_WAKELOCK)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 80 | // subsystem_sleep_state |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 81 | {android::util::SUBSYSTEM_SLEEP_STATE, {.puller = new SubsystemSleepStatePuller()}}, |
Bookatz | 92da283 | 2018-11-01 18:10:03 -0700 | [diff] [blame] | 82 | // on_device_power_measurement |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 83 | {android::util::ON_DEVICE_POWER_MEASUREMENT, {.puller = new PowerStatsPuller()}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 84 | // cpu_time_per_freq |
| 85 | {android::util::CPU_TIME_PER_FREQ, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 86 | {.additiveFields = {3}, |
| 87 | .puller = new StatsCompanionServicePuller(android::util::CPU_TIME_PER_FREQ)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 88 | // cpu_time_per_uid |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 89 | {android::util::CPU_TIME_PER_UID, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 90 | {.additiveFields = {2, 3}, |
| 91 | .puller = new StatsCompanionServicePuller(android::util::CPU_TIME_PER_UID)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 92 | // cpu_time_per_uid_freq |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 93 | // the throttling is 3sec, handled in |
| 94 | // frameworks/base/core/java/com/android/internal/os/KernelCpuProcReader |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 95 | {android::util::CPU_TIME_PER_UID_FREQ, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 96 | {.additiveFields = {4}, |
| 97 | .puller = new StatsCompanionServicePuller(android::util::CPU_TIME_PER_UID_FREQ)}}, |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 98 | // cpu_active_time |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 99 | // the throttling is 3sec, handled in |
| 100 | // frameworks/base/core/java/com/android/internal/os/KernelCpuProcReader |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 101 | {android::util::CPU_ACTIVE_TIME, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 102 | {.additiveFields = {2}, |
| 103 | .puller = new StatsCompanionServicePuller(android::util::CPU_ACTIVE_TIME)}}, |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 104 | // cpu_cluster_time |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 105 | // the throttling is 3sec, handled in |
| 106 | // frameworks/base/core/java/com/android/internal/os/KernelCpuProcReader |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 107 | {android::util::CPU_CLUSTER_TIME, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 108 | {.additiveFields = {3}, |
| 109 | .puller = new StatsCompanionServicePuller(android::util::CPU_CLUSTER_TIME)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 110 | // wifi_activity_energy_info |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 111 | {android::util::WIFI_ACTIVITY_INFO, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 112 | {.puller = new StatsCompanionServicePuller(android::util::WIFI_ACTIVITY_INFO)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 113 | // modem_activity_info |
| 114 | {android::util::MODEM_ACTIVITY_INFO, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 115 | {.puller = new StatsCompanionServicePuller(android::util::MODEM_ACTIVITY_INFO)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 116 | // bluetooth_activity_info |
| 117 | {android::util::BLUETOOTH_ACTIVITY_INFO, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 118 | {.puller = new StatsCompanionServicePuller(android::util::BLUETOOTH_ACTIVITY_INFO)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 119 | // system_elapsed_realtime |
| 120 | {android::util::SYSTEM_ELAPSED_REALTIME, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 121 | {.pullTimeoutNs = NS_PER_SEC / 2, |
| 122 | .coolDownNs = NS_PER_SEC, |
| 123 | .puller = new StatsCompanionServicePuller(android::util::SYSTEM_ELAPSED_REALTIME)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 124 | // system_uptime |
| 125 | {android::util::SYSTEM_UPTIME, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 126 | {.puller = new StatsCompanionServicePuller(android::util::SYSTEM_UPTIME)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 127 | // remaining_battery_capacity |
| 128 | {android::util::REMAINING_BATTERY_CAPACITY, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 129 | {.puller = new ResourceHealthManagerPuller(android::util::REMAINING_BATTERY_CAPACITY)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 130 | // full_battery_capacity |
| 131 | {android::util::FULL_BATTERY_CAPACITY, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 132 | {.puller = new ResourceHealthManagerPuller(android::util::FULL_BATTERY_CAPACITY)}}, |
Bookatz | 17f0d8a | 2018-09-13 12:56:32 -0700 | [diff] [blame] | 133 | // battery_voltage |
| 134 | {android::util::BATTERY_VOLTAGE, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 135 | {.puller = new ResourceHealthManagerPuller(android::util::BATTERY_VOLTAGE)}}, |
Maggie White | 8735b85 | 2019-01-18 11:40:49 -0800 | [diff] [blame] | 136 | // battery_level |
Tej Singh | b1dbc8b | 2018-11-19 15:49:47 -0800 | [diff] [blame] | 137 | {android::util::BATTERY_LEVEL, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 138 | {.puller = new ResourceHealthManagerPuller(android::util::BATTERY_LEVEL)}}, |
Maggie White | 8735b85 | 2019-01-18 11:40:49 -0800 | [diff] [blame] | 139 | // battery_cycle_count |
| 140 | {android::util::BATTERY_CYCLE_COUNT, |
| 141 | {.puller = new ResourceHealthManagerPuller(android::util::BATTERY_CYCLE_COUNT)}}, |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 142 | // process_memory_state |
| 143 | {android::util::PROCESS_MEMORY_STATE, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 144 | {.additiveFields = {4, 5, 6, 7, 8, 9}, |
| 145 | .puller = new StatsCompanionServicePuller(android::util::PROCESS_MEMORY_STATE)}}, |
Rafal Slawik | 0862158 | 2018-10-15 14:53:07 +0100 | [diff] [blame] | 146 | // native_process_memory_state |
| 147 | {android::util::NATIVE_PROCESS_MEMORY_STATE, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 148 | {.additiveFields = {3, 4, 5, 6}, |
| 149 | .puller = new StatsCompanionServicePuller(android::util::NATIVE_PROCESS_MEMORY_STATE)}}, |
Rafal Slawik | 3bea895 | 2018-11-15 12:39:33 +0000 | [diff] [blame] | 150 | {android::util::PROCESS_MEMORY_HIGH_WATER_MARK, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 151 | {.additiveFields = {3}, |
| 152 | .puller = |
| 153 | new StatsCompanionServicePuller(android::util::PROCESS_MEMORY_HIGH_WATER_MARK)}}, |
Tej Singh | 4029831 | 2018-02-16 00:15:09 -0800 | [diff] [blame] | 154 | // temperature |
Tej Singh | 9876a3b | 2019-01-11 14:28:35 -0800 | [diff] [blame] | 155 | {android::util::TEMPERATURE, |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 156 | {.puller = new StatsCompanionServicePuller(android::util::TEMPERATURE)}}, |
Olivier Gaillard | 00bfb1b | 2018-07-10 11:25:09 +0100 | [diff] [blame] | 157 | // binder_calls |
| 158 | {android::util::BINDER_CALLS, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 159 | {.additiveFields = {4, 5, 6, 8, 12}, |
| 160 | .puller = new StatsCompanionServicePuller(android::util::BINDER_CALLS)}}, |
Olivier Gaillard | 6f52d15 | 2018-07-25 12:13:12 +0100 | [diff] [blame] | 161 | // binder_calls_exceptions |
| 162 | {android::util::BINDER_CALLS_EXCEPTIONS, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 163 | {.puller = new StatsCompanionServicePuller(android::util::BINDER_CALLS_EXCEPTIONS)}}, |
Marcin Oczeretko | d8cc859 | 2018-08-22 16:07:36 +0100 | [diff] [blame] | 164 | // looper_stats |
| 165 | {android::util::LOOPER_STATS, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 166 | {.additiveFields = {5, 6, 7, 8, 9}, |
| 167 | .puller = new StatsCompanionServicePuller(android::util::LOOPER_STATS)}}, |
Tej Singh | 86dc9db | 2018-09-06 00:39:57 +0000 | [diff] [blame] | 168 | // Disk Stats |
| 169 | {android::util::DISK_STATS, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 170 | {.puller = new StatsCompanionServicePuller(android::util::DISK_STATS)}}, |
Tej Singh | 86dc9db | 2018-09-06 00:39:57 +0000 | [diff] [blame] | 171 | // Directory usage |
| 172 | {android::util::DIRECTORY_USAGE, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 173 | {.puller = new StatsCompanionServicePuller(android::util::DIRECTORY_USAGE)}}, |
Tej Singh | 86dc9db | 2018-09-06 00:39:57 +0000 | [diff] [blame] | 174 | // Size of app's code, data, and cache |
| 175 | {android::util::APP_SIZE, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 176 | {.puller = new StatsCompanionServicePuller(android::util::APP_SIZE)}}, |
Tej Singh | 86dc9db | 2018-09-06 00:39:57 +0000 | [diff] [blame] | 177 | // Size of specific categories of files. Eg. Music. |
| 178 | {android::util::CATEGORY_SIZE, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 179 | {.puller = new StatsCompanionServicePuller(android::util::CATEGORY_SIZE)}}, |
Kevin Chyn | 6ecc570 | 2019-01-28 12:00:37 -0800 | [diff] [blame] | 180 | // Number of fingerprints enrolled for each user. |
Kevin Chyn | 1741a07 | 2019-01-17 11:54:40 -0800 | [diff] [blame] | 181 | {android::util::NUM_FINGERPRINTS_ENROLLED, |
| 182 | {.puller = new StatsCompanionServicePuller(android::util::NUM_FINGERPRINTS_ENROLLED)}}, |
Kevin Chyn | 6ecc570 | 2019-01-28 12:00:37 -0800 | [diff] [blame] | 183 | // Number of faces enrolled for each user. |
| 184 | {android::util::NUM_FACES_ENROLLED, |
| 185 | {.puller = new StatsCompanionServicePuller(android::util::NUM_FACES_ENROLLED)}}, |
Chenjie Yu | 2c0d83d | 2018-09-02 06:37:08 -0700 | [diff] [blame] | 186 | // ProcStats. |
| 187 | {android::util::PROC_STATS, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 188 | {.puller = new StatsCompanionServicePuller(android::util::PROC_STATS)}}, |
Chenjie Yu | b52779e | 2018-10-05 12:03:36 -0700 | [diff] [blame] | 189 | // ProcStatsPkgProc. |
| 190 | {android::util::PROC_STATS_PKG_PROC, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 191 | {.puller = new StatsCompanionServicePuller(android::util::PROC_STATS_PKG_PROC)}}, |
Tej Singh | e7726dc | 2018-09-21 11:42:12 -0700 | [diff] [blame] | 192 | // Disk I/O stats per uid. |
| 193 | {android::util::DISK_IO, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 194 | {.additiveFields = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, |
| 195 | .coolDownNs = 3 * NS_PER_SEC, |
| 196 | .puller = new StatsCompanionServicePuller(android::util::DISK_IO)}}, |
Chenjie Yu | ab53020 | 2018-09-26 12:39:20 -0700 | [diff] [blame] | 197 | // PowerProfile constants for power model calculations. |
| 198 | {android::util::POWER_PROFILE, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 199 | {.puller = new StatsCompanionServicePuller(android::util::POWER_PROFILE)}}, |
Yangster-mac | 308ea0c | 2018-10-22 13:10:25 -0700 | [diff] [blame] | 200 | // Process cpu stats. Min cool-down is 5 sec, inline with what AcitivityManagerService uses. |
| 201 | {android::util::PROCESS_CPU_TIME, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 202 | {.coolDownNs = 5 * NS_PER_SEC /* min cool-down in seconds*/, |
| 203 | .puller = new StatsCompanionServicePuller(android::util::PROCESS_CPU_TIME)}}, |
Misha Wagner | 5a51e00 | 2018-10-03 15:04:09 +0100 | [diff] [blame] | 204 | {android::util::CPU_TIME_PER_THREAD_FREQ, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 205 | {.additiveFields = {7, 9, 11, 13, 15, 17, 19, 21}, |
| 206 | .puller = new StatsCompanionServicePuller(android::util::CPU_TIME_PER_THREAD_FREQ)}}, |
Bookatz | 75ee604 | 2018-11-09 12:27:37 -0800 | [diff] [blame] | 207 | // DeviceCalculatedPowerUse. |
| 208 | {android::util::DEVICE_CALCULATED_POWER_USE, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 209 | {.puller = new StatsCompanionServicePuller(android::util::DEVICE_CALCULATED_POWER_USE)}}, |
Bookatz | 75ee604 | 2018-11-09 12:27:37 -0800 | [diff] [blame] | 210 | // DeviceCalculatedPowerBlameUid. |
| 211 | {android::util::DEVICE_CALCULATED_POWER_BLAME_UID, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 212 | {.puller = new StatsCompanionServicePuller( |
| 213 | android::util::DEVICE_CALCULATED_POWER_BLAME_UID)}}, |
Bookatz | 75ee604 | 2018-11-09 12:27:37 -0800 | [diff] [blame] | 214 | // DeviceCalculatedPowerBlameOther. |
| 215 | {android::util::DEVICE_CALCULATED_POWER_BLAME_OTHER, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 216 | {.puller = new StatsCompanionServicePuller( |
| 217 | android::util::DEVICE_CALCULATED_POWER_BLAME_OTHER)}}, |
Olivier Gaillard | 18d45220 | 2019-01-22 15:03:41 +0000 | [diff] [blame] | 218 | // DebugElapsedClock. |
| 219 | {android::util::DEBUG_ELAPSED_CLOCK, |
| 220 | {.additiveFields = {1, 2, 3, 4}, |
| 221 | .puller = new StatsCompanionServicePuller(android::util::DEBUG_ELAPSED_CLOCK)}}, |
| 222 | // DebugFailingElapsedClock. |
| 223 | {android::util::DEBUG_FAILING_ELAPSED_CLOCK, |
| 224 | {.additiveFields = {1, 2, 3, 4}, |
| 225 | .puller = new StatsCompanionServicePuller(android::util::DEBUG_FAILING_ELAPSED_CLOCK)}}, |
Bookatz | 366a443 | 2018-11-20 09:42:33 -0800 | [diff] [blame] | 226 | // BuildInformation. |
| 227 | {android::util::BUILD_INFORMATION, |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 228 | {.puller = new StatsCompanionServicePuller(android::util::BUILD_INFORMATION)}}, |
Philip P. Moltmann | 70b42ae | 2019-01-29 16:24:19 -0800 | [diff] [blame] | 229 | // RoleHolder. |
| 230 | {android::util::ROLE_HOLDER, |
| 231 | {.puller = new StatsCompanionServicePuller(android::util::ROLE_HOLDER)}}, |
Philip P. Moltmann | f21a350 | 2019-01-30 09:53:04 -0800 | [diff] [blame] | 232 | // PermissionState. |
| 233 | {android::util::DANGEROUS_PERMISSION_STATE, |
| 234 | {.puller = new StatsCompanionServicePuller(android::util::DANGEROUS_PERMISSION_STATE)}}, |
Chenjie Yu | 97dbb20 | 2019-02-13 16:42:04 -0800 | [diff] [blame] | 235 | // TrainInfo. |
| 236 | {android::util::TRAIN_INFO, {.puller = new TrainInfoPuller()}}, |
Neil Fuller | db14b48 | 2019-02-05 19:44:44 +0000 | [diff] [blame] | 237 | // TimeZoneDataInfo. |
| 238 | {android::util::TIME_ZONE_DATA_INFO, |
| 239 | {.puller = new StatsCompanionServicePuller(android::util::TIME_ZONE_DATA_INFO)}}, |
Carmen Agimof | 35f7f6f | 2019-02-05 18:19:21 +0000 | [diff] [blame] | 240 | // SDCardInfo |
| 241 | {android::util::SDCARD_INFO, |
| 242 | {.puller = new StatsCompanionServicePuller(android::util::SDCARD_INFO)}}, |
Chenjie Yu | 2c0d83d | 2018-09-02 06:37:08 -0700 | [diff] [blame] | 243 | }; |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 244 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 245 | StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) { |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 248 | bool StatsPullerManager::Pull(int tagId, vector<shared_ptr<LogEvent>>* data) { |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 249 | VLOG("Initiating pulling %d", tagId); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 250 | |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 251 | if (kAllPullAtomInfo.find(tagId) != kAllPullAtomInfo.end()) { |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 252 | bool ret = kAllPullAtomInfo.find(tagId)->second.puller->Pull(data); |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 253 | VLOG("pulled %d items", (int)data->size()); |
Misha Wagner | 1eee221 | 2019-01-22 11:47:11 +0000 | [diff] [blame] | 254 | if (!ret) { |
| 255 | StatsdStats::getInstance().notePullFailed(tagId); |
| 256 | } |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 257 | return ret; |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 258 | } else { |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 259 | VLOG("Unknown tagId %d", tagId); |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 260 | return false; // Return early since we don't know what to pull. |
| 261 | } |
| 262 | } |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 263 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 264 | bool StatsPullerManager::PullerForMatcherExists(int tagId) const { |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 265 | return kAllPullAtomInfo.find(tagId) != kAllPullAtomInfo.end(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 266 | } |
| 267 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 268 | void StatsPullerManager::updateAlarmLocked() { |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 269 | if (mNextPullTimeNs == NO_ALARM_UPDATE) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 270 | VLOG("No need to set alarms. Skipping"); |
| 271 | return; |
| 272 | } |
| 273 | |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 274 | sp<IStatsCompanionService> statsCompanionServiceCopy = mStatsCompanionService; |
| 275 | if (statsCompanionServiceCopy != nullptr) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 276 | statsCompanionServiceCopy->setPullingAlarm(mNextPullTimeNs / 1000000); |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 277 | } else { |
| 278 | VLOG("StatsCompanionService not available. Alarm not set."); |
| 279 | } |
| 280 | return; |
| 281 | } |
| 282 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 283 | void StatsPullerManager::SetStatsCompanionService( |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 284 | sp<IStatsCompanionService> statsCompanionService) { |
| 285 | AutoMutex _l(mLock); |
| 286 | sp<IStatsCompanionService> tmpForLock = mStatsCompanionService; |
| 287 | mStatsCompanionService = statsCompanionService; |
| 288 | for (const auto& pulledAtom : kAllPullAtomInfo) { |
| 289 | pulledAtom.second.puller->SetStatsCompanionService(statsCompanionService); |
| 290 | } |
| 291 | if (mStatsCompanionService != nullptr) { |
| 292 | updateAlarmLocked(); |
| 293 | } |
| 294 | } |
| 295 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 296 | void StatsPullerManager::RegisterReceiver(int tagId, wp<PullDataReceiver> receiver, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 297 | int64_t nextPullTimeNs, int64_t intervalNs) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 298 | AutoMutex _l(mLock); |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 299 | auto& receivers = mReceivers[tagId]; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 300 | for (auto it = receivers.begin(); it != receivers.end(); it++) { |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 301 | if (it->receiver == receiver) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 302 | VLOG("Receiver already registered of %d", (int)receivers.size()); |
| 303 | return; |
| 304 | } |
| 305 | } |
| 306 | ReceiverInfo receiverInfo; |
| 307 | receiverInfo.receiver = receiver; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 308 | |
Chenjie Yu | 85ed838 | 2017-12-14 16:48:54 -0800 | [diff] [blame] | 309 | // 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] | 310 | // In practice, we should always have larger buckets. |
| 311 | int64_t roundedIntervalNs = intervalNs / NS_PER_SEC / 60 * NS_PER_SEC * 60; |
Chenjie Yu | 83baaa1 | 2018-03-19 10:41:35 -0700 | [diff] [blame] | 312 | // Scheduled pulling should be at least 1 min apart. |
| 313 | // 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] | 314 | if (roundedIntervalNs < 60 * (int64_t)NS_PER_SEC) { |
| 315 | roundedIntervalNs = 60 * (int64_t)NS_PER_SEC; |
Chenjie Yu | 83baaa1 | 2018-03-19 10:41:35 -0700 | [diff] [blame] | 316 | } |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 317 | |
| 318 | receiverInfo.intervalNs = roundedIntervalNs; |
| 319 | receiverInfo.nextPullTimeNs = nextPullTimeNs; |
| 320 | receivers.push_back(receiverInfo); |
| 321 | |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 322 | // 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] | 323 | if (nextPullTimeNs < mNextPullTimeNs) { |
| 324 | VLOG("Updating next pull time %lld", (long long)mNextPullTimeNs); |
| 325 | mNextPullTimeNs = nextPullTimeNs; |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 326 | updateAlarmLocked(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 327 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 328 | VLOG("Puller for tagId %d registered of %d", tagId, (int)receivers.size()); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 329 | } |
| 330 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 331 | void StatsPullerManager::UnRegisterReceiver(int tagId, wp<PullDataReceiver> receiver) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 332 | AutoMutex _l(mLock); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 333 | if (mReceivers.find(tagId) == mReceivers.end()) { |
| 334 | VLOG("Unknown pull code or no receivers: %d", tagId); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 335 | return; |
| 336 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 337 | auto& receivers = mReceivers.find(tagId)->second; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 338 | for (auto it = receivers.begin(); it != receivers.end(); it++) { |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 339 | if (receiver == it->receiver) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 340 | receivers.erase(it); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 341 | VLOG("Puller for tagId %d unregistered of %d", tagId, (int)receivers.size()); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 342 | return; |
| 343 | } |
| 344 | } |
| 345 | } |
| 346 | |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 347 | void StatsPullerManager::OnAlarmFired(int64_t elapsedTimeNs) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 348 | AutoMutex _l(mLock); |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 349 | int64_t wallClockNs = getWallClockNs(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 350 | |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 351 | int64_t minNextPullTimeNs = NO_ALARM_UPDATE; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 352 | |
| 353 | vector<pair<int, vector<ReceiverInfo*>>> needToPull = |
| 354 | vector<pair<int, vector<ReceiverInfo*>>>(); |
| 355 | for (auto& pair : mReceivers) { |
| 356 | vector<ReceiverInfo*> receivers = vector<ReceiverInfo*>(); |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 357 | if (pair.second.size() != 0) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 358 | for (ReceiverInfo& receiverInfo : pair.second) { |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 359 | if (receiverInfo.nextPullTimeNs <= elapsedTimeNs) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 360 | receivers.push_back(&receiverInfo); |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 361 | } else { |
| 362 | if (receiverInfo.nextPullTimeNs < minNextPullTimeNs) { |
| 363 | minNextPullTimeNs = receiverInfo.nextPullTimeNs; |
| 364 | } |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 365 | } |
| 366 | } |
| 367 | if (receivers.size() > 0) { |
| 368 | needToPull.push_back(make_pair(pair.first, receivers)); |
| 369 | } |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | for (const auto& pullInfo : needToPull) { |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 374 | vector<shared_ptr<LogEvent>> data; |
Olivier Gaillard | c5f11c4 | 2019-02-05 12:44:58 +0000 | [diff] [blame] | 375 | bool pullSuccess = Pull(pullInfo.first, &data); |
| 376 | if (pullSuccess) { |
| 377 | StatsdStats::getInstance().notePullDelay( |
| 378 | pullInfo.first, getElapsedRealtimeNs() - elapsedTimeNs); |
| 379 | } else { |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 380 | VLOG("pull failed at %lld, will try again later", (long long)elapsedTimeNs); |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 381 | } |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 382 | |
| 383 | // Convention is to mark pull atom timestamp at request time. |
| 384 | // If we pull at t0, puller starts at t1, finishes at t2, and send back |
| 385 | // at t3, we mark t0 as its timestamp, which should correspond to its |
| 386 | // triggering event, such as condition change at t0. |
| 387 | // Here the triggering event is alarm fired from AlarmManager. |
| 388 | // In ValueMetricProducer and GaugeMetricProducer we do same thing |
| 389 | // when pull on condition change, etc. |
| 390 | for (auto& event : data) { |
| 391 | event->setElapsedTimestampNs(elapsedTimeNs); |
| 392 | event->setLogdWallClockTimestampNs(wallClockNs); |
| 393 | } |
| 394 | |
| 395 | for (const auto& receiverInfo : pullInfo.second) { |
| 396 | sp<PullDataReceiver> receiverPtr = receiverInfo->receiver.promote(); |
| 397 | if (receiverPtr != nullptr) { |
Olivier Gaillard | 11203df | 2019-02-06 13:18:09 +0000 | [diff] [blame] | 398 | receiverPtr->onDataPulled(data, pullSuccess, elapsedTimeNs); |
Olivier Gaillard | c5f11c4 | 2019-02-05 12:44:58 +0000 | [diff] [blame] | 399 | // 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] | 400 | int numBucketsAhead = |
| 401 | (elapsedTimeNs - receiverInfo->nextPullTimeNs) / receiverInfo->intervalNs; |
| 402 | receiverInfo->nextPullTimeNs += (numBucketsAhead + 1) * receiverInfo->intervalNs; |
| 403 | if (receiverInfo->nextPullTimeNs < minNextPullTimeNs) { |
| 404 | minNextPullTimeNs = receiverInfo->nextPullTimeNs; |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 405 | } |
Chenjie Yu | 0bd73db | 2018-12-16 07:37:04 -0800 | [diff] [blame] | 406 | } else { |
| 407 | VLOG("receiver already gone."); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 408 | } |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 409 | } |
| 410 | } |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 411 | |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 412 | VLOG("mNextPullTimeNs: %lld updated to %lld", (long long)mNextPullTimeNs, |
| 413 | (long long)minNextPullTimeNs); |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 414 | mNextPullTimeNs = minNextPullTimeNs; |
| 415 | updateAlarmLocked(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 416 | } |
| 417 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 418 | int StatsPullerManager::ForceClearPullerCache() { |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 419 | int totalCleared = 0; |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 420 | for (const auto& pulledAtom : kAllPullAtomInfo) { |
| 421 | totalCleared += pulledAtom.second.puller->ForceClearCache(); |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 422 | } |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 423 | return totalCleared; |
| 424 | } |
| 425 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 426 | int StatsPullerManager::ClearPullerCacheIfNecessary(int64_t timestampNs) { |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 427 | int totalCleared = 0; |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 428 | for (const auto& pulledAtom : kAllPullAtomInfo) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 429 | totalCleared += pulledAtom.second.puller->ClearCacheIfNecessary(timestampNs); |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 430 | } |
| 431 | return totalCleared; |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 432 | } |
| 433 | |
Tej Singh | a0c89dd | 2019-01-25 16:39:18 -0800 | [diff] [blame] | 434 | void StatsPullerManager::RegisterPullerCallback(int32_t atomTag, |
| 435 | const sp<IStatsPullerCallback>& callback) { |
| 436 | AutoMutex _l(mLock); |
| 437 | // Platform pullers cannot be changed. |
| 438 | if (atomTag < StatsdStats::kMaxPlatformAtomTag) { |
| 439 | VLOG("RegisterPullerCallback: atom tag %d is less than min tag %d", |
| 440 | atomTag, StatsdStats::kMaxPlatformAtomTag); |
| 441 | return; |
| 442 | } |
| 443 | VLOG("RegisterPullerCallback: adding puller for tag %d", atomTag); |
| 444 | StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/true); |
| 445 | kAllPullAtomInfo[atomTag] = {.puller = new StatsCallbackPuller(atomTag, callback)}; |
| 446 | } |
| 447 | |
| 448 | void StatsPullerManager::UnregisterPullerCallback(int32_t atomTag) { |
| 449 | AutoMutex _l(mLock); |
| 450 | // Platform pullers cannot be changed. |
| 451 | if (atomTag < StatsdStats::kMaxPlatformAtomTag) { |
| 452 | return; |
| 453 | } |
| 454 | StatsdStats::getInstance().notePullerCallbackRegistrationChanged(atomTag, /*registered=*/false); |
| 455 | kAllPullAtomInfo.erase(atomTag); |
| 456 | } |
| 457 | |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 458 | } // namespace statsd |
| 459 | } // namespace os |
| 460 | } // namespace android |