Yao Chen | ab273e2 | 2017-09-06 12:53:50 -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 | */ |
Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 16 | |
Yangster-mac | 2087716 | 2017-12-22 17:19:39 -0800 | [diff] [blame] | 17 | #pragma once |
| 18 | |
| 19 | #include <gtest/gtest_prod.h> |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 20 | #include "config/ConfigListener.h" |
Jonathan Nguyen | 703c42f | 2020-02-04 15:54:26 -0800 | [diff] [blame] | 21 | #include "logd/LogEvent.h" |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 22 | #include "metrics/MetricsManager.h" |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 23 | #include "packages/UidMap.h" |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 24 | #include "external/StatsPullerManager.h" |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 25 | |
| 26 | #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" |
Jeffrey Huang | b8f5403 | 2020-03-23 13:42:42 -0700 | [diff] [blame] | 27 | #include "frameworks/base/cmds/statsd/src/statsd_metadata.pb.h" |
Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 28 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 29 | #include <stdio.h> |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 30 | #include <unordered_map> |
| 31 | |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 32 | namespace android { |
| 33 | namespace os { |
| 34 | namespace statsd { |
Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 35 | |
Chenjie Yu | e36018b | 2018-04-16 15:18:30 -0700 | [diff] [blame] | 36 | |
Tej Singh | 9ec159a | 2019-11-14 11:59:48 -0800 | [diff] [blame] | 37 | class StatsLogProcessor : public ConfigListener, public virtual PackageInfoListener { |
Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 38 | public: |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 39 | StatsLogProcessor(const sp<UidMap>& uidMap, const sp<StatsPullerManager>& pullerManager, |
| 40 | const sp<AlarmMonitor>& anomalyAlarmMonitor, |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 41 | const sp<AlarmMonitor>& subscriberTriggerAlarmMonitor, |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 42 | const int64_t timeBaseNs, |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 43 | const std::function<bool(const ConfigKey&)>& sendBroadcast, |
| 44 | const std::function<bool(const int&, |
| 45 | const vector<int64_t>&)>& sendActivationBroadcast); |
Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 46 | virtual ~StatsLogProcessor(); |
| 47 | |
Yangster-mac | d40053e | 2018-01-09 16:29:22 -0800 | [diff] [blame] | 48 | void OnLogEvent(LogEvent* event); |
Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 49 | |
Yangster-mac | c04feba | 2018-04-02 14:37:33 -0700 | [diff] [blame] | 50 | void OnConfigUpdated(const int64_t timestampNs, const ConfigKey& key, |
| 51 | const StatsdConfig& config); |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 52 | void OnConfigRemoved(const ConfigKey& key); |
David Chen | 0656b7a | 2017-09-13 15:53:39 -0700 | [diff] [blame] | 53 | |
Yangster | 7c334a1 | 2017-11-22 14:24:24 -0800 | [diff] [blame] | 54 | size_t GetMetricsSize(const ConfigKey& key) const; |
| 55 | |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 56 | void GetActiveConfigs(const int uid, vector<int64_t>& outActiveConfigs); |
| 57 | |
Yangster-mac | e68f3a5 | 2018-04-04 00:01:43 -0700 | [diff] [blame] | 58 | void onDumpReport(const ConfigKey& key, const int64_t dumpTimeNs, |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 59 | const bool include_current_partial_bucket, const bool erase_data, |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 60 | const DumpReportReason dumpReportReason, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 61 | const DumpLatency dumpLatency, |
| 62 | vector<uint8_t>* outData); |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 63 | void onDumpReport(const ConfigKey& key, const int64_t dumpTimeNs, |
| 64 | const bool include_current_partial_bucket, const bool erase_data, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 65 | const DumpReportReason dumpReportReason, |
| 66 | const DumpLatency dumpLatency, |
| 67 | ProtoOutputStream* proto); |
Bookatz | cc5adef2 | 2017-11-21 14:36:23 -0800 | [diff] [blame] | 68 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 69 | /* Tells MetricsManager that the alarms in alarmSet have fired. Modifies periodic alarmSet. */ |
| 70 | void onPeriodicAlarmFired( |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 71 | const int64_t& timestampNs, |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 72 | unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 73 | |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 74 | /* Flushes data to disk. Data on memory will be gone after written to disk. */ |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 75 | void WriteDataToDisk(const DumpReportReason dumpReportReason, |
| 76 | const DumpLatency dumpLatency); |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 77 | |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 78 | /* Persist configs containing metrics with active activations to disk. */ |
| 79 | void SaveActiveConfigsToDisk(int64_t currentTimeNs); |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 80 | |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame] | 81 | /* Writes the current active status/ttl for all configs and metrics to ProtoOutputStream. */ |
| 82 | void WriteActiveConfigsToProtoOutputStream( |
| 83 | int64_t currentTimeNs, const DumpReportReason reason, ProtoOutputStream* proto); |
| 84 | |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 85 | /* Load configs containing metrics with active activations from disk. */ |
| 86 | void LoadActiveConfigsFromDisk(); |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 87 | |
Jeffrey Huang | b8f5403 | 2020-03-23 13:42:42 -0700 | [diff] [blame] | 88 | /* Persist metadata for configs and metrics to disk. */ |
| 89 | void SaveMetadataToDisk(int64_t currentWallClockTimeNs, int64_t systemElapsedTimeNs); |
| 90 | |
| 91 | /* Writes the statsd metadata for all configs and metrics to StatsMetadataList. */ |
| 92 | void WriteMetadataToProto(int64_t currentWallClockTimeNs, |
| 93 | int64_t systemElapsedTimeNs, |
| 94 | metadata::StatsMetadataList* metadataList); |
| 95 | |
Jeffrey Huang | 475677e | 2020-03-30 19:52:07 -0700 | [diff] [blame] | 96 | /* Load stats metadata for configs and metrics from disk. */ |
| 97 | void LoadMetadataFromDisk(int64_t currentWallClockTimeNs, |
| 98 | int64_t systemElapsedTimeNs); |
| 99 | |
| 100 | /* Sets the metadata for all configs and metrics */ |
| 101 | void SetMetadataState(const metadata::StatsMetadataList& statsMetadataList, |
| 102 | int64_t currentWallClockTimeNs, |
| 103 | int64_t systemElapsedTimeNs); |
| 104 | |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame] | 105 | /* Sets the active status/ttl for all configs and metrics to the status in ActiveConfigList. */ |
| 106 | void SetConfigsActiveState(const ActiveConfigList& activeConfigList, int64_t currentTimeNs); |
| 107 | |
Tej Singh | 9ec159a | 2019-11-14 11:59:48 -0800 | [diff] [blame] | 108 | /* Notify all MetricsManagers of app upgrades */ |
| 109 | void notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid, |
| 110 | const int64_t version) override; |
| 111 | |
| 112 | /* Notify all MetricsManagers of app removals */ |
| 113 | void notifyAppRemoved(const int64_t& eventTimeNs, const string& apk, const int uid) override; |
| 114 | |
| 115 | /* Notify all MetricsManagers of uid map snapshots received */ |
| 116 | void onUidMapReceived(const int64_t& eventTimeNs) override; |
| 117 | |
Tej Singh | e678cb7 | 2020-04-14 16:23:30 -0700 | [diff] [blame] | 118 | /* Notify all metrics managers of boot completed |
| 119 | * This will force a bucket split when the boot is finished. |
| 120 | */ |
| 121 | void onStatsdInitCompleted(const int64_t& elapsedTimeNs); |
| 122 | |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 123 | // Reset all configs. |
| 124 | void resetConfigs(); |
yro | 947fbce | 2017-11-15 22:50:23 -0800 | [diff] [blame] | 125 | |
Yangster-mac | b5bc741 | 2018-01-06 23:17:45 -0800 | [diff] [blame] | 126 | inline sp<UidMap> getUidMap() { |
| 127 | return mUidMap; |
| 128 | } |
| 129 | |
Yao Chen | a80e5c0 | 2018-09-04 13:55:29 -0700 | [diff] [blame] | 130 | void dumpStates(int outFd, bool verbose); |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 131 | |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 132 | void informPullAlarmFired(const int64_t timestampNs); |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 133 | |
David Chen | d37bc23 | 2018-04-12 18:05:11 -0700 | [diff] [blame] | 134 | int64_t getLastReportTimeNs(const ConfigKey& key); |
| 135 | |
Yao Chen | 876889c | 2018-05-02 11:16:16 -0700 | [diff] [blame] | 136 | inline void setPrintLogs(bool enabled) { |
| 137 | #ifdef VERY_VERBOSE_PRINTING |
| 138 | std::lock_guard<std::mutex> lock(mMetricsMutex); |
| 139 | mPrintAllLogs = enabled; |
| 140 | #endif |
| 141 | } |
| 142 | |
David Chen | 4894490 | 2018-05-03 10:29:11 -0700 | [diff] [blame] | 143 | // Add a specific config key to the possible configs to dump ASAP. |
| 144 | void noteOnDiskData(const ConfigKey& key); |
| 145 | |
Tej Singh | 8b914c0 | 2020-07-14 23:16:24 -0700 | [diff] [blame] | 146 | void setAnomalyAlarm(const int64_t timeMillis); |
| 147 | |
| 148 | void cancelAnomalyAlarm(); |
| 149 | |
Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 150 | private: |
Yangster-mac | be10ddf | 2018-03-13 15:39:51 -0700 | [diff] [blame] | 151 | // For testing only. |
| 152 | inline sp<AlarmMonitor> getAnomalyAlarmMonitor() const { |
| 153 | return mAnomalyAlarmMonitor; |
| 154 | } |
| 155 | |
Yangster-mac | 684d195 | 2018-03-24 16:47:16 -0700 | [diff] [blame] | 156 | inline sp<AlarmMonitor> getPeriodicAlarmMonitor() const { |
| 157 | return mPeriodicAlarmMonitor; |
| 158 | } |
| 159 | |
Yangster-mac | b0d0628 | 2018-01-05 15:44:07 -0800 | [diff] [blame] | 160 | mutable mutex mMetricsMutex; |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 161 | |
Tej Singh | 8b914c0 | 2020-07-14 23:16:24 -0700 | [diff] [blame] | 162 | // Guards mNextAnomalyAlarmTime. A separate mutex is needed because alarms are set/cancelled |
| 163 | // in the onLogEvent code path, which is locked by mMetricsMutex. |
| 164 | // DO NOT acquire mMetricsMutex while holding mAnomalyAlarmMutex. This can lead to a deadlock. |
| 165 | mutable mutex mAnomalyAlarmMutex; |
| 166 | |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 167 | std::unordered_map<ConfigKey, sp<MetricsManager>> mMetricsManagers; |
David Chen | de70169 | 2017-10-05 13:16:02 -0700 | [diff] [blame] | 168 | |
Tej Singh | 5a801c8 | 2019-11-01 10:45:22 -0700 | [diff] [blame] | 169 | std::unordered_map<ConfigKey, int64_t> mLastBroadcastTimes; |
yro | 69007c8 | 2017-10-26 20:42:57 -0700 | [diff] [blame] | 170 | |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 171 | // Last time we sent a broadcast to this uid that the active configs had changed. |
Tej Singh | 5a801c8 | 2019-11-01 10:45:22 -0700 | [diff] [blame] | 172 | std::unordered_map<int, int64_t> mLastActivationBroadcastTimes; |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 173 | |
David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 174 | // Tracks when we last checked the bytes consumed for each config key. |
Tej Singh | 5a801c8 | 2019-11-01 10:45:22 -0700 | [diff] [blame] | 175 | std::unordered_map<ConfigKey, int64_t> mLastByteSizeTimes; |
David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 176 | |
David Chen | 4894490 | 2018-05-03 10:29:11 -0700 | [diff] [blame] | 177 | // Tracks which config keys has metric reports on disk |
| 178 | std::set<ConfigKey> mOnDiskDataConfigs; |
| 179 | |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 180 | sp<UidMap> mUidMap; // Reference to the UidMap to lookup app name and version for each uid. |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 181 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 182 | sp<StatsPullerManager> mPullerManager; // Reference to StatsPullerManager |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 183 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 184 | sp<AlarmMonitor> mAnomalyAlarmMonitor; |
| 185 | |
| 186 | sp<AlarmMonitor> mPeriodicAlarmMonitor; |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 187 | |
Tej Singh | 480392f | 2019-10-23 15:53:46 -0700 | [diff] [blame] | 188 | void OnLogEvent(LogEvent* event, int64_t elapsedRealtimeNs); |
| 189 | |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 190 | void resetIfConfigTtlExpiredLocked(const int64_t timestampNs); |
| 191 | |
| 192 | void OnConfigUpdatedLocked( |
| 193 | const int64_t currentTimestampNs, const ConfigKey& key, const StatsdConfig& config); |
| 194 | |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 195 | void GetActiveConfigsLocked(const int uid, vector<int64_t>& outActiveConfigs); |
| 196 | |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame] | 197 | void WriteActiveConfigsToProtoOutputStreamLocked( |
| 198 | int64_t currentTimeNs, const DumpReportReason reason, ProtoOutputStream* proto); |
| 199 | |
| 200 | void SetConfigsActiveStateLocked(const ActiveConfigList& activeConfigList, |
| 201 | int64_t currentTimeNs); |
| 202 | |
Jeffrey Huang | 475677e | 2020-03-30 19:52:07 -0700 | [diff] [blame] | 203 | void SetMetadataStateLocked(const metadata::StatsMetadataList& statsMetadataList, |
| 204 | int64_t currentWallClockTimeNs, |
| 205 | int64_t systemElapsedTimeNs); |
| 206 | |
Jeffrey Huang | b8f5403 | 2020-03-23 13:42:42 -0700 | [diff] [blame] | 207 | void WriteMetadataToProtoLocked(int64_t currentWallClockTimeNs, |
| 208 | int64_t systemElapsedTimeNs, |
| 209 | metadata::StatsMetadataList* metadataList); |
| 210 | |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 211 | void WriteDataToDiskLocked(const DumpReportReason dumpReportReason, |
| 212 | const DumpLatency dumpLatency); |
Jeffrey Huang | b8f5403 | 2020-03-23 13:42:42 -0700 | [diff] [blame] | 213 | |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 214 | void WriteDataToDiskLocked(const ConfigKey& key, const int64_t timestampNs, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 215 | const DumpReportReason dumpReportReason, |
| 216 | const DumpLatency dumpLatency); |
Yangster-mac | e68f3a5 | 2018-04-04 00:01:43 -0700 | [diff] [blame] | 217 | |
Yao Chen | 9a43b4f | 2019-04-10 10:43:20 -0700 | [diff] [blame] | 218 | void onConfigMetricsReportLocked( |
| 219 | const ConfigKey& key, const int64_t dumpTimeStampNs, |
| 220 | const bool include_current_partial_bucket, const bool erase_data, |
| 221 | const DumpReportReason dumpReportReason, const DumpLatency dumpLatency, |
| 222 | /*if dataSavedToDisk is true, it indicates the caller will write the data to disk |
| 223 | (e.g., before reboot). So no need to further persist local history.*/ |
| 224 | const bool dataSavedToDisk, vector<uint8_t>* proto); |
Yangster-mac | 8617950 | 2018-01-23 15:47:15 -0800 | [diff] [blame] | 225 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 226 | /* Check if we should send a broadcast if approaching memory limits and if we're over, we |
| 227 | * actually delete the data. */ |
Tej Singh | 480392f | 2019-10-23 15:53:46 -0700 | [diff] [blame] | 228 | void flushIfNecessaryLocked(const ConfigKey& key, MetricsManager& metricsManager); |
yro | 31eb67b | 2017-10-24 13:33:21 -0700 | [diff] [blame] | 229 | |
Yangster-mac | d40053e | 2018-01-09 16:29:22 -0800 | [diff] [blame] | 230 | // Maps the isolated uid in the log event to host uid if the log event contains uid fields. |
| 231 | void mapIsolatedUidToHostUidIfNecessaryLocked(LogEvent* event) const; |
| 232 | |
| 233 | // Handler over the isolated uid change event. |
| 234 | void onIsolatedUidChangedEventLocked(const LogEvent& event); |
| 235 | |
Jonathan Nguyen | a0e6de1 | 2020-01-28 18:33:55 -0800 | [diff] [blame] | 236 | // Handler over the binary push state changed event. |
| 237 | void onBinaryPushStateChangedEventLocked(LogEvent* event); |
| 238 | |
Jonathan Nguyen | 703c42f | 2020-02-04 15:54:26 -0800 | [diff] [blame] | 239 | // Handler over the watchdog rollback occurred event. |
| 240 | void onWatchdogRollbackOccurredLocked(LogEvent* event); |
| 241 | |
Jonathan Nguyen | a0e6de1 | 2020-01-28 18:33:55 -0800 | [diff] [blame] | 242 | // Updates train info on disk based on binary push state changed info and |
| 243 | // write disk info into parameters. |
Jonathan Nguyen | 703c42f | 2020-02-04 15:54:26 -0800 | [diff] [blame] | 244 | void getAndUpdateTrainInfoOnDisk(bool is_rollback, InstallTrainInfo* trainInfoIn); |
| 245 | |
| 246 | // Gets experiment ids on disk for associated train and updates them |
| 247 | // depending on rollback type. Then writes them back to disk and returns |
| 248 | // them. |
| 249 | std::vector<int64_t> processWatchdogRollbackOccurred(const int32_t rollbackTypeIn, |
| 250 | const string& packageName); |
Jonathan Nguyen | a0e6de1 | 2020-01-28 18:33:55 -0800 | [diff] [blame] | 251 | |
Yangster-mac | 892f3d3 | 2018-05-02 14:16:48 -0700 | [diff] [blame] | 252 | // Reset all configs. |
| 253 | void resetConfigsLocked(const int64_t timestampNs); |
| 254 | // Reset the specified configs. |
Yao Chen | 163d260 | 2018-04-10 10:39:53 -0700 | [diff] [blame] | 255 | void resetConfigsLocked(const int64_t timestampNs, const std::vector<ConfigKey>& configs); |
| 256 | |
Tej Singh | 8b914c0 | 2020-07-14 23:16:24 -0700 | [diff] [blame] | 257 | // An anomaly alarm should have fired. |
| 258 | // Check with anomaly alarm manager to find the alarms and process the result. |
| 259 | void informAnomalyAlarmFiredLocked(const int64_t elapsedTimeMillis); |
| 260 | |
| 261 | /* Tells MetricsManager that the alarms in alarmSet have fired. Modifies anomaly alarmSet. */ |
| 262 | void processFiredAnomalyAlarmsLocked( |
| 263 | const int64_t& timestampNs, |
| 264 | unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>> alarmSet); |
| 265 | |
David Chen | 1d7b0cd | 2017-11-15 14:20:04 -0800 | [diff] [blame] | 266 | // Function used to send a broadcast so that receiver for the config key can call getData |
| 267 | // to retrieve the stored data. |
David Chen | 4894490 | 2018-05-03 10:29:11 -0700 | [diff] [blame] | 268 | std::function<bool(const ConfigKey& key)> mSendBroadcast; |
yro | 69007c8 | 2017-10-26 20:42:57 -0700 | [diff] [blame] | 269 | |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 270 | // Function used to send a broadcast so that receiver can be notified of which configs |
| 271 | // are currently active. |
| 272 | std::function<bool(const int& uid, const vector<int64_t>& configIds)> mSendActivationBroadcast; |
| 273 | |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 274 | const int64_t mTimeBaseNs; |
Chenjie Yu | 85ed838 | 2017-12-14 16:48:54 -0800 | [diff] [blame] | 275 | |
Yao Chen | 163d260 | 2018-04-10 10:39:53 -0700 | [diff] [blame] | 276 | // Largest timestamp of the events that we have processed. |
| 277 | int64_t mLargestTimestampSeen = 0; |
| 278 | |
| 279 | int64_t mLastTimestampSeen = 0; |
| 280 | |
Tej Singh | 5a801c8 | 2019-11-01 10:45:22 -0700 | [diff] [blame] | 281 | int64_t mLastPullerCacheClearTimeSec = 0; |
Chenjie Yu | fa22d65 | 2018-02-05 14:37:48 -0800 | [diff] [blame] | 282 | |
Tej Singh | 42f9e06 | 2018-11-09 10:01:00 -0800 | [diff] [blame] | 283 | // Last time we wrote data to disk. |
| 284 | int64_t mLastWriteTimeNs = 0; |
| 285 | |
jianjin | 996f40d | 2019-03-29 13:53:48 -0700 | [diff] [blame] | 286 | // Last time we wrote active metrics to disk. |
| 287 | int64_t mLastActiveMetricsWriteNs = 0; |
| 288 | |
Jeffrey Huang | b8f5403 | 2020-03-23 13:42:42 -0700 | [diff] [blame] | 289 | //Last time we wrote metadata to disk. |
| 290 | int64_t mLastMetadataWriteNs = 0; |
| 291 | |
Tej Singh | 8b914c0 | 2020-07-14 23:16:24 -0700 | [diff] [blame] | 292 | // The time for the next anomaly alarm for alerts. |
| 293 | int64_t mNextAnomalyAlarmTime = 0; |
| 294 | |
Yao Chen | 876889c | 2018-05-02 11:16:16 -0700 | [diff] [blame] | 295 | #ifdef VERY_VERBOSE_PRINTING |
| 296 | bool mPrintAllLogs = false; |
| 297 | #endif |
| 298 | |
Yao Chen | 163d260 | 2018-04-10 10:39:53 -0700 | [diff] [blame] | 299 | FRIEND_TEST(StatsLogProcessorTest, TestOutOfOrderLogs); |
David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 300 | FRIEND_TEST(StatsLogProcessorTest, TestRateLimitByteSize); |
| 301 | FRIEND_TEST(StatsLogProcessorTest, TestRateLimitBroadcast); |
| 302 | FRIEND_TEST(StatsLogProcessorTest, TestDropWhenByteSizeTooLarge); |
Tej Singh | 5a4727d | 2020-06-09 18:13:12 -0700 | [diff] [blame] | 303 | FRIEND_TEST(StatsLogProcessorTest, InvalidConfigRemoved); |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 304 | FRIEND_TEST(StatsLogProcessorTest, TestActiveConfigMetricDiskWriteRead); |
Chenjie Yu | a9a310e | 2019-02-06 13:40:10 -0800 | [diff] [blame] | 305 | FRIEND_TEST(StatsLogProcessorTest, TestActivationOnBoot); |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 306 | FRIEND_TEST(StatsLogProcessorTest, TestActivationOnBootMultipleActivations); |
Muhammad Qureshi | 15f8da9 | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 307 | FRIEND_TEST(StatsLogProcessorTest, |
| 308 | TestActivationOnBootMultipleActivationsDifferentActivationTypes); |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame] | 309 | FRIEND_TEST(StatsLogProcessorTest, TestActivationsPersistAcrossSystemServerRestart); |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 310 | |
Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 311 | FRIEND_TEST(WakelockDurationE2eTest, TestAggregatedPredicateDimensionsForSumDuration1); |
| 312 | FRIEND_TEST(WakelockDurationE2eTest, TestAggregatedPredicateDimensionsForSumDuration2); |
| 313 | FRIEND_TEST(WakelockDurationE2eTest, TestAggregatedPredicateDimensionsForSumDuration3); |
| 314 | FRIEND_TEST(WakelockDurationE2eTest, TestAggregatedPredicateDimensionsForMaxDuration1); |
| 315 | FRIEND_TEST(WakelockDurationE2eTest, TestAggregatedPredicateDimensionsForMaxDuration2); |
| 316 | FRIEND_TEST(WakelockDurationE2eTest, TestAggregatedPredicateDimensionsForMaxDuration3); |
| 317 | FRIEND_TEST(MetricConditionLinkE2eTest, TestMultiplePredicatesAndLinks1); |
| 318 | FRIEND_TEST(MetricConditionLinkE2eTest, TestMultiplePredicatesAndLinks2); |
Yangster-mac | e06cfd7 | 2018-03-10 23:22:59 -0800 | [diff] [blame] | 319 | FRIEND_TEST(AttributionE2eTest, TestAttributionMatchAndSliceByFirstUid); |
| 320 | FRIEND_TEST(AttributionE2eTest, TestAttributionMatchAndSliceByChain); |
Yangster-mac | 87718e2 | 2018-01-11 16:16:26 -0800 | [diff] [blame] | 321 | FRIEND_TEST(GaugeMetricE2eTest, TestMultipleFieldsForPushedEvent); |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 322 | FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvents); |
| 323 | FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEvent_LateAlarm); |
Tej Singh | 597c716 | 2019-04-17 16:41:45 -0700 | [diff] [blame] | 324 | FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEventsWithActivation); |
| 325 | FRIEND_TEST(GaugeMetricE2eTest, TestRandomSamplePulledEventsNoCondition); |
Yangster-mac | 32f07af | 2018-10-13 17:08:11 -0700 | [diff] [blame] | 326 | FRIEND_TEST(GaugeMetricE2eTest, TestConditionChangeToTrueSamplePulledEvents); |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 327 | |
Yangster-mac | be10ddf | 2018-03-13 15:39:51 -0700 | [diff] [blame] | 328 | FRIEND_TEST(AnomalyDetectionE2eTest, TestSlicedCountMetric_single_bucket); |
| 329 | FRIEND_TEST(AnomalyDetectionE2eTest, TestSlicedCountMetric_multiple_buckets); |
Jeffrey Huang | b8f5403 | 2020-03-23 13:42:42 -0700 | [diff] [blame] | 330 | FRIEND_TEST(AnomalyDetectionE2eTest, TestCountMetric_save_refractory_to_disk_no_data_written); |
| 331 | FRIEND_TEST(AnomalyDetectionE2eTest, TestCountMetric_save_refractory_to_disk); |
Jeffrey Huang | 475677e | 2020-03-30 19:52:07 -0700 | [diff] [blame] | 332 | FRIEND_TEST(AnomalyDetectionE2eTest, TestCountMetric_load_refractory_from_disk); |
Yangster-mac | be10ddf | 2018-03-13 15:39:51 -0700 | [diff] [blame] | 333 | FRIEND_TEST(AnomalyDetectionE2eTest, TestDurationMetric_SUM_single_bucket); |
| 334 | FRIEND_TEST(AnomalyDetectionE2eTest, TestDurationMetric_SUM_multiple_buckets); |
| 335 | FRIEND_TEST(AnomalyDetectionE2eTest, TestDurationMetric_SUM_long_refractory_period); |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 336 | |
Yangster-mac | 684d195 | 2018-03-24 16:47:16 -0700 | [diff] [blame] | 337 | FRIEND_TEST(AlarmE2eTest, TestMultipleAlarms); |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 338 | FRIEND_TEST(ConfigTtlE2eTest, TestCountMetric); |
Yangster-mac | 849dfdc2 | 2018-10-12 15:41:45 -0700 | [diff] [blame] | 339 | FRIEND_TEST(MetricActivationE2eTest, TestCountMetric); |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 340 | FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithOneDeactivation); |
| 341 | FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithTwoDeactivations); |
Tej Singh | ee4495e | 2019-06-03 18:37:35 -0700 | [diff] [blame] | 342 | FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithSameDeactivation); |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 343 | FRIEND_TEST(MetricActivationE2eTest, TestCountMetricWithTwoMetricsTwoDeactivations); |
Muhammad Qureshi | 18e4692 | 2019-05-24 16:38:49 -0700 | [diff] [blame] | 344 | |
tsaichristine | 70a7ee5 | 2020-05-18 10:05:09 -0700 | [diff] [blame] | 345 | FRIEND_TEST(CountMetricE2eTest, TestInitialConditionChanges); |
tsaichristine | 69000e6 | 2019-10-18 17:34:52 -0700 | [diff] [blame] | 346 | FRIEND_TEST(CountMetricE2eTest, TestSlicedState); |
| 347 | FRIEND_TEST(CountMetricE2eTest, TestSlicedStateWithMap); |
| 348 | FRIEND_TEST(CountMetricE2eTest, TestMultipleSlicedStates); |
| 349 | FRIEND_TEST(CountMetricE2eTest, TestSlicedStateWithPrimaryFields); |
tsaichristine | d21aacf | 2019-10-07 14:47:38 -0700 | [diff] [blame] | 350 | |
Muhammad Qureshi | 18e4692 | 2019-05-24 16:38:49 -0700 | [diff] [blame] | 351 | FRIEND_TEST(DurationMetricE2eTest, TestOneBucket); |
| 352 | FRIEND_TEST(DurationMetricE2eTest, TestTwoBuckets); |
| 353 | FRIEND_TEST(DurationMetricE2eTest, TestWithActivation); |
| 354 | FRIEND_TEST(DurationMetricE2eTest, TestWithCondition); |
| 355 | FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedCondition); |
| 356 | FRIEND_TEST(DurationMetricE2eTest, TestWithActivationAndSlicedCondition); |
tsaichristine | 1449fa4 | 2020-01-02 12:12:05 -0800 | [diff] [blame] | 357 | FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedState); |
| 358 | FRIEND_TEST(DurationMetricE2eTest, TestWithConditionAndSlicedState); |
| 359 | FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedStateMapped); |
| 360 | FRIEND_TEST(DurationMetricE2eTest, TestSlicedStatePrimaryFieldsNotSubsetDimInWhat); |
| 361 | FRIEND_TEST(DurationMetricE2eTest, TestWithSlicedStatePrimaryFieldsSubset); |
tsaichristine | c876b49 | 2019-12-10 13:47:05 -0800 | [diff] [blame] | 362 | |
tsaichristine | 70a7ee5 | 2020-05-18 10:05:09 -0700 | [diff] [blame] | 363 | FRIEND_TEST(ValueMetricE2eTest, TestInitialConditionChanges); |
| 364 | FRIEND_TEST(ValueMetricE2eTest, TestPulledEvents); |
| 365 | FRIEND_TEST(ValueMetricE2eTest, TestPulledEvents_LateAlarm); |
| 366 | FRIEND_TEST(ValueMetricE2eTest, TestPulledEvents_WithActivation); |
tsaichristine | c876b49 | 2019-12-10 13:47:05 -0800 | [diff] [blame] | 367 | FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState); |
| 368 | FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithDimensions); |
| 369 | FRIEND_TEST(ValueMetricE2eTest, TestInitWithSlicedState_WithIncorrectDimensions); |
Yao Chen | ab273e2 | 2017-09-06 12:53:50 -0700 | [diff] [blame] | 370 | }; |
Bookatz | 906a35c | 2017-09-20 15:26:44 -0700 | [diff] [blame] | 371 | |
Yao Chen | ef99c4f | 2017-09-22 16:26:54 -0700 | [diff] [blame] | 372 | } // namespace statsd |
| 373 | } // namespace os |
| 374 | } // namespace android |