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