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> |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 21 | #include <cutils/log.h> |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 22 | #include <math.h> |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 23 | #include <stdint.h> |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 24 | #include <algorithm> |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 25 | #include "../StatsService.h" |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 26 | #include "../logd/LogEvent.h" |
| 27 | #include "../stats_log_util.h" |
| 28 | #include "../statscompanion_util.h" |
Bookatz | 92da283 | 2018-11-01 18:10:03 -0700 | [diff] [blame] | 29 | #include "PowerStatsPuller.h" |
Tej Singh | 4029831 | 2018-02-16 00:15:09 -0800 | [diff] [blame] | 30 | #include "ResourceHealthManagerPuller.h" |
| 31 | #include "ResourceThermalManagerPuller.h" |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 32 | #include "StatsCompanionServicePuller.h" |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 33 | #include "StatsPullerManager.h" |
Tej Singh | bf972d9 | 2018-01-10 20:51:13 -0800 | [diff] [blame] | 34 | #include "SubsystemSleepStatePuller.h" |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 35 | #include "statslog.h" |
David Chen | 1481fe1 | 2017-10-16 13:16:34 -0700 | [diff] [blame] | 36 | |
| 37 | #include <iostream> |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 38 | |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 39 | using std::make_shared; |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 40 | using std::map; |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 41 | using std::shared_ptr; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 42 | using std::string; |
| 43 | using std::vector; |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 44 | using std::list; |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 45 | |
| 46 | namespace android { |
| 47 | namespace os { |
| 48 | namespace statsd { |
| 49 | |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 50 | // Values smaller than this may require to update the alarm. |
| 51 | const int64_t NO_ALARM_UPDATE = INT64_MAX; |
| 52 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 53 | const std::map<int, PullAtomInfo> StatsPullerManager::kAllPullAtomInfo = { |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 54 | // wifi_bytes_transfer |
| 55 | {android::util::WIFI_BYTES_TRANSFER, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 56 | {{2, 3, 4, 5}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 57 | 1 * NS_PER_SEC, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 58 | new StatsCompanionServicePuller(android::util::WIFI_BYTES_TRANSFER)}}, |
| 59 | // wifi_bytes_transfer_by_fg_bg |
| 60 | {android::util::WIFI_BYTES_TRANSFER_BY_FG_BG, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 61 | {{3, 4, 5, 6}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 62 | 1 * NS_PER_SEC, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 63 | new StatsCompanionServicePuller(android::util::WIFI_BYTES_TRANSFER_BY_FG_BG)}}, |
| 64 | // mobile_bytes_transfer |
| 65 | {android::util::MOBILE_BYTES_TRANSFER, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 66 | {{2, 3, 4, 5}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 67 | 1 * NS_PER_SEC, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 68 | new StatsCompanionServicePuller(android::util::MOBILE_BYTES_TRANSFER)}}, |
| 69 | // mobile_bytes_transfer_by_fg_bg |
| 70 | {android::util::MOBILE_BYTES_TRANSFER_BY_FG_BG, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 71 | {{3, 4, 5, 6}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 72 | 1 * NS_PER_SEC, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 73 | new StatsCompanionServicePuller(android::util::MOBILE_BYTES_TRANSFER_BY_FG_BG)}}, |
| 74 | // bluetooth_bytes_transfer |
| 75 | {android::util::BLUETOOTH_BYTES_TRANSFER, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 76 | {{2, 3}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 77 | 1 * NS_PER_SEC, |
| 78 | new StatsCompanionServicePuller(android::util::BLUETOOTH_BYTES_TRANSFER)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 79 | // kernel_wakelock |
| 80 | {android::util::KERNEL_WAKELOCK, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 81 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::KERNEL_WAKELOCK)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 82 | // subsystem_sleep_state |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 83 | {android::util::SUBSYSTEM_SLEEP_STATE, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 84 | {{}, 1 * NS_PER_SEC, new SubsystemSleepStatePuller()}}, |
Bookatz | 92da283 | 2018-11-01 18:10:03 -0700 | [diff] [blame] | 85 | // on_device_power_measurement |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 86 | {android::util::ON_DEVICE_POWER_MEASUREMENT, {{}, 1 * NS_PER_SEC, new PowerStatsPuller()}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 87 | // cpu_time_per_freq |
| 88 | {android::util::CPU_TIME_PER_FREQ, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 89 | {{3}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::CPU_TIME_PER_FREQ)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 90 | // cpu_time_per_uid |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 91 | {android::util::CPU_TIME_PER_UID, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 92 | {{2, 3}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 93 | 1 * NS_PER_SEC, |
| 94 | new StatsCompanionServicePuller(android::util::CPU_TIME_PER_UID)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 95 | // cpu_time_per_uid_freq |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 96 | // the throttling is 3sec, handled in |
| 97 | // frameworks/base/core/java/com/android/internal/os/KernelCpuProcReader |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 98 | {android::util::CPU_TIME_PER_UID_FREQ, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 99 | {{4}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 100 | 1 * NS_PER_SEC, |
| 101 | new StatsCompanionServicePuller(android::util::CPU_TIME_PER_UID_FREQ)}}, |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 102 | // cpu_active_time |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 103 | // the throttling is 3sec, handled in |
| 104 | // frameworks/base/core/java/com/android/internal/os/KernelCpuProcReader |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 105 | {android::util::CPU_ACTIVE_TIME, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 106 | {{2}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::CPU_ACTIVE_TIME)}}, |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 107 | // cpu_cluster_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 |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 110 | {android::util::CPU_CLUSTER_TIME, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 111 | {{3}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::CPU_CLUSTER_TIME)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 112 | // wifi_activity_energy_info |
Chenjie Yu | 5caaa9d | 2018-03-06 15:48:54 -0800 | [diff] [blame] | 113 | {android::util::WIFI_ACTIVITY_INFO, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 114 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::WIFI_ACTIVITY_INFO)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 115 | // modem_activity_info |
| 116 | {android::util::MODEM_ACTIVITY_INFO, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 117 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::MODEM_ACTIVITY_INFO)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 118 | // bluetooth_activity_info |
| 119 | {android::util::BLUETOOTH_ACTIVITY_INFO, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 120 | {{}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 121 | 1 * NS_PER_SEC, |
| 122 | new StatsCompanionServicePuller(android::util::BLUETOOTH_ACTIVITY_INFO)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 123 | // system_elapsed_realtime |
| 124 | {android::util::SYSTEM_ELAPSED_REALTIME, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 125 | {{}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 126 | 1 * NS_PER_SEC, |
| 127 | new StatsCompanionServicePuller(android::util::SYSTEM_ELAPSED_REALTIME)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 128 | // system_uptime |
| 129 | {android::util::SYSTEM_UPTIME, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 130 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::SYSTEM_UPTIME)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 131 | // remaining_battery_capacity |
| 132 | {android::util::REMAINING_BATTERY_CAPACITY, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 133 | {{}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 134 | 1 * NS_PER_SEC, |
| 135 | new ResourceHealthManagerPuller(android::util::REMAINING_BATTERY_CAPACITY)}}, |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 136 | // full_battery_capacity |
| 137 | {android::util::FULL_BATTERY_CAPACITY, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 138 | {{}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 139 | 1 * NS_PER_SEC, |
| 140 | new ResourceHealthManagerPuller(android::util::FULL_BATTERY_CAPACITY)}}, |
Bookatz | 17f0d8a | 2018-09-13 12:56:32 -0700 | [diff] [blame] | 141 | // battery_voltage |
| 142 | {android::util::BATTERY_VOLTAGE, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 143 | {{}, 1 * NS_PER_SEC, new ResourceHealthManagerPuller(android::util::BATTERY_VOLTAGE)}}, |
| 144 | // battery_level |
Tej Singh | b1dbc8b | 2018-11-19 15:49:47 -0800 | [diff] [blame] | 145 | {android::util::BATTERY_LEVEL, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 146 | {{}, 1 * NS_PER_SEC, new ResourceHealthManagerPuller(android::util::BATTERY_LEVEL)}}, |
Rajeev Kumar | 22d92b7 | 2018-02-07 18:38:36 -0800 | [diff] [blame] | 147 | // process_memory_state |
| 148 | {android::util::PROCESS_MEMORY_STATE, |
Rafal Slawik | aaf6089 | 2018-09-12 13:04:30 +0100 | [diff] [blame] | 149 | {{4, 5, 6, 7, 8, 9}, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 150 | 1 * NS_PER_SEC, |
Chenjie Yu | ec67661 | 2018-03-07 09:19:17 -0800 | [diff] [blame] | 151 | new StatsCompanionServicePuller(android::util::PROCESS_MEMORY_STATE)}}, |
Rafal Slawik | 0862158 | 2018-10-15 14:53:07 +0100 | [diff] [blame] | 152 | // native_process_memory_state |
| 153 | {android::util::NATIVE_PROCESS_MEMORY_STATE, |
Rafal Slawik | 272a816 | 2018-11-01 15:12:28 +0000 | [diff] [blame] | 154 | {{3, 4, 5, 6}, |
Rafal Slawik | 0862158 | 2018-10-15 14:53:07 +0100 | [diff] [blame] | 155 | 1 * NS_PER_SEC, |
| 156 | new StatsCompanionServicePuller(android::util::NATIVE_PROCESS_MEMORY_STATE)}}, |
Rafal Slawik | 3bea895 | 2018-11-15 12:39:33 +0000 | [diff] [blame] | 157 | {android::util::PROCESS_MEMORY_HIGH_WATER_MARK, |
| 158 | {{3}, |
Rafal Slawik | 3bea895 | 2018-11-15 12:39:33 +0000 | [diff] [blame] | 159 | 1 * NS_PER_SEC, |
| 160 | new StatsCompanionServicePuller(android::util::PROCESS_MEMORY_HIGH_WATER_MARK)}}, |
Tej Singh | 4029831 | 2018-02-16 00:15:09 -0800 | [diff] [blame] | 161 | // temperature |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 162 | {android::util::TEMPERATURE, {{}, 1 * NS_PER_SEC, new ResourceThermalManagerPuller()}}, |
Olivier Gaillard | 00bfb1b | 2018-07-10 11:25:09 +0100 | [diff] [blame] | 163 | // binder_calls |
| 164 | {android::util::BINDER_CALLS, |
Olivier Gaillard | 6f52d15 | 2018-07-25 12:13:12 +0100 | [diff] [blame] | 165 | {{4, 5, 6, 8, 12}, |
Olivier Gaillard | 00bfb1b | 2018-07-10 11:25:09 +0100 | [diff] [blame] | 166 | 1 * NS_PER_SEC, |
Olivier Gaillard | 6f52d15 | 2018-07-25 12:13:12 +0100 | [diff] [blame] | 167 | new StatsCompanionServicePuller(android::util::BINDER_CALLS)}}, |
| 168 | // binder_calls_exceptions |
| 169 | {android::util::BINDER_CALLS_EXCEPTIONS, |
| 170 | {{}, |
Olivier Gaillard | 6f52d15 | 2018-07-25 12:13:12 +0100 | [diff] [blame] | 171 | 1 * NS_PER_SEC, |
Marcin Oczeretko | d8cc859 | 2018-08-22 16:07:36 +0100 | [diff] [blame] | 172 | new StatsCompanionServicePuller(android::util::BINDER_CALLS_EXCEPTIONS)}}, |
| 173 | // looper_stats |
| 174 | {android::util::LOOPER_STATS, |
| 175 | {{5, 6, 7, 8, 9}, |
Marcin Oczeretko | d8cc859 | 2018-08-22 16:07:36 +0100 | [diff] [blame] | 176 | 1 * NS_PER_SEC, |
Tej Singh | 86dc9db | 2018-09-06 00:39:57 +0000 | [diff] [blame] | 177 | new StatsCompanionServicePuller(android::util::LOOPER_STATS)}}, |
| 178 | // Disk Stats |
| 179 | {android::util::DISK_STATS, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 180 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::DISK_STATS)}}, |
Tej Singh | 86dc9db | 2018-09-06 00:39:57 +0000 | [diff] [blame] | 181 | // Directory usage |
| 182 | {android::util::DIRECTORY_USAGE, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 183 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::DIRECTORY_USAGE)}}, |
Tej Singh | 86dc9db | 2018-09-06 00:39:57 +0000 | [diff] [blame] | 184 | // Size of app's code, data, and cache |
| 185 | {android::util::APP_SIZE, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 186 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::APP_SIZE)}}, |
Tej Singh | 86dc9db | 2018-09-06 00:39:57 +0000 | [diff] [blame] | 187 | // Size of specific categories of files. Eg. Music. |
| 188 | {android::util::CATEGORY_SIZE, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 189 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::CATEGORY_SIZE)}}, |
Tej Singh | d6d6d77 | 2018-09-05 17:41:25 -0700 | [diff] [blame] | 190 | // Number of fingerprints registered to each user. |
| 191 | {android::util::NUM_FINGERPRINTS, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 192 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::NUM_FINGERPRINTS)}}, |
Chenjie Yu | 2c0d83d | 2018-09-02 06:37:08 -0700 | [diff] [blame] | 193 | // ProcStats. |
| 194 | {android::util::PROC_STATS, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 195 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::PROC_STATS)}}, |
Chenjie Yu | b52779e | 2018-10-05 12:03:36 -0700 | [diff] [blame] | 196 | // ProcStatsPkgProc. |
| 197 | {android::util::PROC_STATS_PKG_PROC, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 198 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::PROC_STATS_PKG_PROC)}}, |
Tej Singh | e7726dc | 2018-09-21 11:42:12 -0700 | [diff] [blame] | 199 | // Disk I/O stats per uid. |
| 200 | {android::util::DISK_IO, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 201 | {{2, 3, 4, 5, 6, 7, 8, 9, 10, 11}, |
Tej Singh | e7726dc | 2018-09-21 11:42:12 -0700 | [diff] [blame] | 202 | 3 * NS_PER_SEC, |
| 203 | new StatsCompanionServicePuller(android::util::DISK_IO)}}, |
Chenjie Yu | ab53020 | 2018-09-26 12:39:20 -0700 | [diff] [blame] | 204 | // PowerProfile constants for power model calculations. |
| 205 | {android::util::POWER_PROFILE, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 206 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::POWER_PROFILE)}}, |
Yangster-mac | 308ea0c | 2018-10-22 13:10:25 -0700 | [diff] [blame] | 207 | // Process cpu stats. Min cool-down is 5 sec, inline with what AcitivityManagerService uses. |
| 208 | {android::util::PROCESS_CPU_TIME, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 209 | {{} /* additive fields */, |
| 210 | 5 * NS_PER_SEC /* min cool-down in seconds*/, |
| 211 | new StatsCompanionServicePuller(android::util::PROCESS_CPU_TIME)}}, |
Misha Wagner | 5a51e00 | 2018-10-03 15:04:09 +0100 | [diff] [blame] | 212 | {android::util::CPU_TIME_PER_THREAD_FREQ, |
Misha Wagner | fde6958 | 2018-11-28 13:26:32 +0000 | [diff] [blame] | 213 | {{7, 9, 11, 13, 15, 17, 19, 21}, |
Misha Wagner | 5a51e00 | 2018-10-03 15:04:09 +0100 | [diff] [blame] | 214 | 1 * NS_PER_SEC, |
| 215 | new StatsCompanionServicePuller(android::util::CPU_TIME_PER_THREAD_FREQ)}}, |
Bookatz | 75ee6042 | 2018-11-09 12:27:37 -0800 | [diff] [blame] | 216 | // DeviceCalculatedPowerUse. |
| 217 | {android::util::DEVICE_CALCULATED_POWER_USE, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 218 | {{}, |
| 219 | 1 * NS_PER_SEC, |
Bookatz | 75ee6042 | 2018-11-09 12:27:37 -0800 | [diff] [blame] | 220 | new StatsCompanionServicePuller(android::util::DEVICE_CALCULATED_POWER_USE)}}, |
| 221 | // DeviceCalculatedPowerBlameUid. |
| 222 | {android::util::DEVICE_CALCULATED_POWER_BLAME_UID, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 223 | {{}, // BatteryStats already merged isolated with host ids so it's unnecessary here. |
Bookatz | 75ee6042 | 2018-11-09 12:27:37 -0800 | [diff] [blame] | 224 | 1 * NS_PER_SEC, |
| 225 | new StatsCompanionServicePuller(android::util::DEVICE_CALCULATED_POWER_BLAME_UID)}}, |
| 226 | // DeviceCalculatedPowerBlameOther. |
| 227 | {android::util::DEVICE_CALCULATED_POWER_BLAME_OTHER, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 228 | {{}, |
Bookatz | 75ee6042 | 2018-11-09 12:27:37 -0800 | [diff] [blame] | 229 | 1 * NS_PER_SEC, |
| 230 | new StatsCompanionServicePuller(android::util::DEVICE_CALCULATED_POWER_BLAME_OTHER)}}, |
Bookatz | 366a443 | 2018-11-20 09:42:33 -0800 | [diff] [blame] | 231 | // BuildInformation. |
| 232 | {android::util::BUILD_INFORMATION, |
Chenjie Yu | d7e3a22 | 2018-11-28 21:29:44 +0000 | [diff] [blame] | 233 | {{}, 1 * NS_PER_SEC, new StatsCompanionServicePuller(android::util::BUILD_INFORMATION)}}, |
Chenjie Yu | 2c0d83d | 2018-09-02 06:37:08 -0700 | [diff] [blame] | 234 | }; |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 235 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 236 | StatsPullerManager::StatsPullerManager() : mNextPullTimeNs(NO_ALARM_UPDATE) { |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 237 | } |
| 238 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 239 | bool StatsPullerManager::Pull(const int tagId, const int64_t timeNs, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 240 | vector<shared_ptr<LogEvent>>* data) { |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 241 | VLOG("Initiating pulling %d", tagId); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 242 | |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 243 | if (kAllPullAtomInfo.find(tagId) != kAllPullAtomInfo.end()) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 244 | bool ret = kAllPullAtomInfo.find(tagId)->second.puller->Pull(timeNs, data); |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 245 | VLOG("pulled %d items", (int)data->size()); |
| 246 | return ret; |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 247 | } else { |
Tej Singh | 484524a | 2018-02-01 15:10:05 -0800 | [diff] [blame] | 248 | VLOG("Unknown tagId %d", tagId); |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 249 | return false; // Return early since we don't know what to pull. |
| 250 | } |
| 251 | } |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 252 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 253 | bool StatsPullerManager::PullerForMatcherExists(int tagId) const { |
Chenjie Yu | feba309 | 2018-02-08 14:33:37 -0800 | [diff] [blame] | 254 | return kAllPullAtomInfo.find(tagId) != kAllPullAtomInfo.end(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 255 | } |
| 256 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 257 | void StatsPullerManager::updateAlarmLocked() { |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 258 | if (mNextPullTimeNs == NO_ALARM_UPDATE) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 259 | VLOG("No need to set alarms. Skipping"); |
| 260 | return; |
| 261 | } |
| 262 | |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 263 | sp<IStatsCompanionService> statsCompanionServiceCopy = mStatsCompanionService; |
| 264 | if (statsCompanionServiceCopy != nullptr) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 265 | statsCompanionServiceCopy->setPullingAlarm(mNextPullTimeNs / 1000000); |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 266 | } else { |
| 267 | VLOG("StatsCompanionService not available. Alarm not set."); |
| 268 | } |
| 269 | return; |
| 270 | } |
| 271 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 272 | void StatsPullerManager::SetStatsCompanionService( |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 273 | sp<IStatsCompanionService> statsCompanionService) { |
| 274 | AutoMutex _l(mLock); |
| 275 | sp<IStatsCompanionService> tmpForLock = mStatsCompanionService; |
| 276 | mStatsCompanionService = statsCompanionService; |
| 277 | for (const auto& pulledAtom : kAllPullAtomInfo) { |
| 278 | pulledAtom.second.puller->SetStatsCompanionService(statsCompanionService); |
| 279 | } |
| 280 | if (mStatsCompanionService != nullptr) { |
| 281 | updateAlarmLocked(); |
| 282 | } |
| 283 | } |
| 284 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 285 | void StatsPullerManager::RegisterReceiver(int tagId, wp<PullDataReceiver> receiver, |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 286 | int64_t nextPullTimeNs, int64_t intervalNs) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 287 | AutoMutex _l(mLock); |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 288 | auto& receivers = mReceivers[tagId]; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 289 | for (auto it = receivers.begin(); it != receivers.end(); it++) { |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 290 | if (it->receiver == receiver) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 291 | VLOG("Receiver already registered of %d", (int)receivers.size()); |
| 292 | return; |
| 293 | } |
| 294 | } |
| 295 | ReceiverInfo receiverInfo; |
| 296 | receiverInfo.receiver = receiver; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 297 | |
Chenjie Yu | 85ed838 | 2017-12-14 16:48:54 -0800 | [diff] [blame] | 298 | // 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] | 299 | // In practice, we should always have larger buckets. |
| 300 | int64_t roundedIntervalNs = intervalNs / NS_PER_SEC / 60 * NS_PER_SEC * 60; |
Chenjie Yu | 83baaa1 | 2018-03-19 10:41:35 -0700 | [diff] [blame] | 301 | // Scheduled pulling should be at least 1 min apart. |
| 302 | // 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] | 303 | if (roundedIntervalNs < 60 * (int64_t)NS_PER_SEC) { |
| 304 | roundedIntervalNs = 60 * (int64_t)NS_PER_SEC; |
Chenjie Yu | 83baaa1 | 2018-03-19 10:41:35 -0700 | [diff] [blame] | 305 | } |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 306 | |
| 307 | receiverInfo.intervalNs = roundedIntervalNs; |
| 308 | receiverInfo.nextPullTimeNs = nextPullTimeNs; |
| 309 | receivers.push_back(receiverInfo); |
| 310 | |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 311 | // 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] | 312 | if (nextPullTimeNs < mNextPullTimeNs) { |
| 313 | VLOG("Updating next pull time %lld", (long long)mNextPullTimeNs); |
| 314 | mNextPullTimeNs = nextPullTimeNs; |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 315 | updateAlarmLocked(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 316 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 317 | VLOG("Puller for tagId %d registered of %d", tagId, (int)receivers.size()); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 318 | } |
| 319 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 320 | void StatsPullerManager::UnRegisterReceiver(int tagId, wp<PullDataReceiver> receiver) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 321 | AutoMutex _l(mLock); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 322 | if (mReceivers.find(tagId) == mReceivers.end()) { |
| 323 | VLOG("Unknown pull code or no receivers: %d", tagId); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 324 | return; |
| 325 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 326 | auto& receivers = mReceivers.find(tagId)->second; |
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 (receiver == it->receiver) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 329 | receivers.erase(it); |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 330 | VLOG("Puller for tagId %d unregistered of %d", tagId, (int)receivers.size()); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 331 | return; |
| 332 | } |
| 333 | } |
| 334 | } |
| 335 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 336 | void StatsPullerManager::OnAlarmFired(const int64_t currentTimeNs) { |
Chenjie Yu | aa5b201 | 2018-03-21 13:53:15 -0700 | [diff] [blame] | 337 | AutoMutex _l(mLock); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 338 | |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 339 | int64_t minNextPullTimeNs = NO_ALARM_UPDATE; |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 340 | |
| 341 | vector<pair<int, vector<ReceiverInfo*>>> needToPull = |
| 342 | vector<pair<int, vector<ReceiverInfo*>>>(); |
| 343 | for (auto& pair : mReceivers) { |
| 344 | vector<ReceiverInfo*> receivers = vector<ReceiverInfo*>(); |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 345 | if (pair.second.size() != 0) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 346 | for (ReceiverInfo& receiverInfo : pair.second) { |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 347 | if (receiverInfo.nextPullTimeNs <= currentTimeNs) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 348 | receivers.push_back(&receiverInfo); |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 349 | } else { |
| 350 | if (receiverInfo.nextPullTimeNs < minNextPullTimeNs) { |
| 351 | minNextPullTimeNs = receiverInfo.nextPullTimeNs; |
| 352 | } |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 353 | } |
| 354 | } |
| 355 | if (receivers.size() > 0) { |
| 356 | needToPull.push_back(make_pair(pair.first, receivers)); |
| 357 | } |
| 358 | } |
| 359 | } |
| 360 | |
| 361 | for (const auto& pullInfo : needToPull) { |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 362 | vector<shared_ptr<LogEvent>> data; |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 363 | if (Pull(pullInfo.first, currentTimeNs, &data)) { |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 364 | for (const auto& receiverInfo : pullInfo.second) { |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 365 | sp<PullDataReceiver> receiverPtr = receiverInfo->receiver.promote(); |
| 366 | if (receiverPtr != nullptr) { |
| 367 | receiverPtr->onDataPulled(data); |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 368 | // we may have just come out of a coma, compute next pull time |
| 369 | receiverInfo->nextPullTimeNs = |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 370 | (currentTimeNs - receiverInfo->nextPullTimeNs) / |
| 371 | receiverInfo->intervalNs * receiverInfo->intervalNs + |
| 372 | receiverInfo->intervalNs + receiverInfo->nextPullTimeNs; |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 373 | if (receiverInfo->nextPullTimeNs < minNextPullTimeNs) { |
| 374 | minNextPullTimeNs = receiverInfo->nextPullTimeNs; |
| 375 | } |
Chenjie Yu | 6736c89 | 2017-11-09 10:50:09 -0800 | [diff] [blame] | 376 | } else { |
| 377 | VLOG("receiver already gone."); |
| 378 | } |
Chenjie Yu | 5305e1d | 2017-10-31 13:49:36 -0700 | [diff] [blame] | 379 | } |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 380 | } |
| 381 | } |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 382 | |
Chenjie Yu | 3b3adcd | 2018-04-18 16:25:36 -0700 | [diff] [blame] | 383 | VLOG("mNextPullTimeNs: %lld updated to %lld", (long long)mNextPullTimeNs, |
| 384 | (long long)minNextPullTimeNs); |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 385 | mNextPullTimeNs = minNextPullTimeNs; |
| 386 | updateAlarmLocked(); |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 389 | int StatsPullerManager::ForceClearPullerCache() { |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 390 | int totalCleared = 0; |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 391 | for (const auto& pulledAtom : kAllPullAtomInfo) { |
| 392 | totalCleared += pulledAtom.second.puller->ForceClearCache(); |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 393 | } |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 394 | return totalCleared; |
| 395 | } |
| 396 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 397 | int StatsPullerManager::ClearPullerCacheIfNecessary(int64_t timestampNs) { |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 398 | int totalCleared = 0; |
Chenjie Yu | 80f9112 | 2018-01-31 20:24:50 -0800 | [diff] [blame] | 399 | for (const auto& pulledAtom : kAllPullAtomInfo) { |
Chenjie Yu | 1a0a941 | 2018-03-28 10:07:22 -0700 | [diff] [blame] | 400 | totalCleared += pulledAtom.second.puller->ClearCacheIfNecessary(timestampNs); |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 401 | } |
| 402 | return totalCleared; |
Chenjie Yu | e72252b | 2018-02-01 13:19:35 -0800 | [diff] [blame] | 403 | } |
| 404 | |
Chenjie Yu | 1a317ba | 2017-10-05 16:05:32 -0700 | [diff] [blame] | 405 | } // namespace statsd |
| 406 | } // namespace os |
| 407 | } // namespace android |