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