Yao Chen | 44cf27c | 2017-09-14 22:32: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 | */ |
Yangster-mac | 754e29e | 2018-05-02 12:23:17 -0700 | [diff] [blame] | 16 | #define DEBUG false // STOPSHIP if true |
Joe Onorato | 9fc9edf | 2017-10-15 20:08:52 -0700 | [diff] [blame] | 17 | #include "Log.h" |
tsaichristine | d21aacf | 2019-10-07 14:47:38 -0700 | [diff] [blame] | 18 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 19 | #include "MetricsManager.h" |
tsaichristine | d21aacf | 2019-10-07 14:47:38 -0700 | [diff] [blame] | 20 | |
| 21 | #include <log/logprint.h> |
| 22 | #include <private/android_filesystem_config.h> |
| 23 | #include <utils/SystemClock.h> |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 24 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 25 | #include "CountMetricProducer.h" |
Muhammad Qureshi | c8e2266 | 2019-11-20 17:18:03 -0800 | [diff] [blame^] | 26 | #include "atoms_info.h" |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 27 | #include "condition/CombinationConditionTracker.h" |
| 28 | #include "condition/SimpleConditionTracker.h" |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 29 | #include "guardrail/StatsdStats.h" |
Yao Chen | 93fe3a3 | 2017-11-02 13:52:59 -0700 | [diff] [blame] | 30 | #include "matchers/CombinationLogMatchingTracker.h" |
| 31 | #include "matchers/SimpleLogMatchingTracker.h" |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 32 | #include "metrics_manager_util.h" |
tsaichristine | d21aacf | 2019-10-07 14:47:38 -0700 | [diff] [blame] | 33 | #include "state/StateManager.h" |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 34 | #include "stats_log_util.h" |
tsaichristine | d21aacf | 2019-10-07 14:47:38 -0700 | [diff] [blame] | 35 | #include "stats_util.h" |
| 36 | #include "statslog.h" |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 37 | |
| 38 | using android::util::FIELD_COUNT_REPEATED; |
David Chen | faa1af5 | 2018-03-30 15:14:04 -0700 | [diff] [blame] | 39 | using android::util::FIELD_TYPE_INT32; |
| 40 | using android::util::FIELD_TYPE_INT64; |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 41 | using android::util::FIELD_TYPE_MESSAGE; |
Yangster-mac | 9def8e3 | 2018-04-17 13:55:51 -0700 | [diff] [blame] | 42 | using android::util::FIELD_TYPE_STRING; |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 43 | using android::util::ProtoOutputStream; |
| 44 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 45 | using std::make_unique; |
| 46 | using std::set; |
| 47 | using std::string; |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 48 | using std::unordered_map; |
| 49 | using std::vector; |
| 50 | |
| 51 | namespace android { |
| 52 | namespace os { |
| 53 | namespace statsd { |
| 54 | |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 55 | const int FIELD_ID_METRICS = 1; |
David Chen | faa1af5 | 2018-03-30 15:14:04 -0700 | [diff] [blame] | 56 | const int FIELD_ID_ANNOTATIONS = 7; |
| 57 | const int FIELD_ID_ANNOTATIONS_INT64 = 1; |
| 58 | const int FIELD_ID_ANNOTATIONS_INT32 = 2; |
Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 59 | |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 60 | // for ActiveConfig |
| 61 | const int FIELD_ID_ACTIVE_CONFIG_ID = 1; |
| 62 | const int FIELD_ID_ACTIVE_CONFIG_UID = 2; |
| 63 | const int FIELD_ID_ACTIVE_CONFIG_METRIC = 3; |
| 64 | |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 65 | MetricsManager::MetricsManager(const ConfigKey& key, const StatsdConfig& config, |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 66 | const int64_t timeBaseNs, const int64_t currentTimeNs, |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 67 | const sp<UidMap>& uidMap, |
| 68 | const sp<StatsPullerManager>& pullerManager, |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 69 | const sp<AlarmMonitor>& anomalyAlarmMonitor, |
| 70 | const sp<AlarmMonitor>& periodicAlarmMonitor) |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 71 | : mConfigKey(key), |
| 72 | mUidMap(uidMap), |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 73 | mTtlNs(config.has_ttl_in_seconds() ? config.ttl_in_seconds() * NS_PER_SEC : -1), |
| 74 | mTtlEndNs(-1), |
David Chen | 4894490 | 2018-05-03 10:29:11 -0700 | [diff] [blame] | 75 | mLastReportTimeNs(currentTimeNs), |
Yao Chen | 9a43b4f | 2019-04-10 10:43:20 -0700 | [diff] [blame] | 76 | mLastReportWallClockNs(getWallClockNs()), |
| 77 | mShouldPersistHistory(config.persist_locally()) { |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 78 | // Init the ttl end timestamp. |
Yangster-mac | 15f6bbc | 2018-04-08 11:52:26 -0700 | [diff] [blame] | 79 | refreshTtl(timeBaseNs); |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 80 | |
Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 81 | mConfigValid = initStatsdConfig( |
| 82 | key, config, *uidMap, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor, |
| 83 | timeBaseNs, currentTimeNs, mTagIds, mAllAtomMatchers, mAllConditionTrackers, |
| 84 | mAllMetricProducers, mAllAnomalyTrackers, mAllPeriodicAlarmTrackers, |
Yangster-mac | 849dfdc2 | 2018-10-12 15:41:45 -0700 | [diff] [blame] | 85 | mConditionToMetricMap, mTrackerToMetricMap, mTrackerToConditionMap, |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 86 | mActivationAtomTrackerToMetricMap, mDeactivationAtomTrackerToMetricMap, |
| 87 | mMetricIndexesWithActivation, mNoReportMetricIds); |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 88 | |
Yangster-mac | 1c58f04 | 2018-05-17 15:52:51 -0700 | [diff] [blame] | 89 | mHashStringsInReport = config.hash_strings_in_metric_report(); |
dwchen | 730403e | 2018-10-29 11:41:56 -0700 | [diff] [blame] | 90 | mVersionStringsInReport = config.version_strings_in_metric_report(); |
| 91 | mInstallerInReport = config.installer_in_metric_report(); |
Yangster-mac | 1c58f04 | 2018-05-17 15:52:51 -0700 | [diff] [blame] | 92 | |
Yao Chen | 147ce60 | 2017-12-22 14:35:34 -0800 | [diff] [blame] | 93 | if (config.allowed_log_source_size() == 0) { |
David Chen | 8faaa01 | 2018-02-28 15:54:36 -0800 | [diff] [blame] | 94 | mConfigValid = false; |
| 95 | ALOGE("Log source whitelist is empty! This config won't get any data. Suggest adding at " |
| 96 | "least AID_SYSTEM and AID_STATSD to the allowed_log_source field."); |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 97 | } else { |
Yao Chen | 147ce60 | 2017-12-22 14:35:34 -0800 | [diff] [blame] | 98 | for (const auto& source : config.allowed_log_source()) { |
| 99 | auto it = UidMap::sAidToUidMapping.find(source); |
| 100 | if (it != UidMap::sAidToUidMapping.end()) { |
| 101 | mAllowedUid.push_back(it->second); |
| 102 | } else { |
| 103 | mAllowedPkg.push_back(source); |
| 104 | } |
| 105 | } |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 106 | |
| 107 | if (mAllowedUid.size() + mAllowedPkg.size() > StatsdStats::kMaxLogSourceCount) { |
| 108 | ALOGE("Too many log sources. This is likely to be an error in the config."); |
| 109 | mConfigValid = false; |
| 110 | } else { |
| 111 | initLogSourceWhiteList(); |
| 112 | } |
| 113 | } |
| 114 | |
David Chen | faa1af5 | 2018-03-30 15:14:04 -0700 | [diff] [blame] | 115 | // Store the sub-configs used. |
| 116 | for (const auto& annotation : config.annotation()) { |
| 117 | mAnnotations.emplace_back(annotation.field_int64(), annotation.field_int32()); |
| 118 | } |
| 119 | |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 120 | // Guardrail. Reject the config if it's too big. |
| 121 | if (mAllMetricProducers.size() > StatsdStats::kMaxMetricCountPerConfig || |
| 122 | mAllConditionTrackers.size() > StatsdStats::kMaxConditionCountPerConfig || |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 123 | mAllAtomMatchers.size() > StatsdStats::kMaxMatcherCountPerConfig) { |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 124 | ALOGE("This config is too big! Reject!"); |
| 125 | mConfigValid = false; |
| 126 | } |
Bookatz | 1476ef2 | 2018-02-13 12:26:01 -0800 | [diff] [blame] | 127 | if (mAllAnomalyTrackers.size() > StatsdStats::kMaxAlertCountPerConfig) { |
| 128 | ALOGE("This config has too many alerts! Reject!"); |
| 129 | mConfigValid = false; |
| 130 | } |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 131 | |
| 132 | mIsAlwaysActive = (mMetricIndexesWithActivation.size() != mAllMetricProducers.size()) || |
| 133 | (mAllMetricProducers.size() == 0); |
| 134 | bool isActive = mIsAlwaysActive; |
| 135 | for (int metric : mMetricIndexesWithActivation) { |
| 136 | isActive |= mAllMetricProducers[metric]->isActive(); |
| 137 | } |
| 138 | mIsActive = isActive; |
| 139 | VLOG("mIsActive is initialized to %d", mIsActive) |
| 140 | |
Yao Chen | f09569f | 2017-12-13 17:00:51 -0800 | [diff] [blame] | 141 | // no matter whether this config is valid, log it in the stats. |
David Chen | faa1af5 | 2018-03-30 15:14:04 -0700 | [diff] [blame] | 142 | StatsdStats::getInstance().noteConfigReceived( |
| 143 | key, mAllMetricProducers.size(), mAllConditionTrackers.size(), mAllAtomMatchers.size(), |
| 144 | mAllAnomalyTrackers.size(), mAnnotations, mConfigValid); |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 145 | // Check active |
| 146 | for (const auto& metric : mAllMetricProducers) { |
| 147 | if (metric->isActive()) { |
| 148 | mIsActive = true; |
| 149 | break; |
| 150 | } |
| 151 | } |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 152 | } |
| 153 | |
| 154 | MetricsManager::~MetricsManager() { |
tsaichristine | d21aacf | 2019-10-07 14:47:38 -0700 | [diff] [blame] | 155 | for (auto it : mAllMetricProducers) { |
| 156 | for (int atomId : it->getSlicedStateAtoms()) { |
| 157 | StateManager::getInstance().unregisterListener(atomId, it); |
| 158 | } |
| 159 | } |
| 160 | |
Bookatz | d3606c7 | 2017-10-19 10:13:49 -0700 | [diff] [blame] | 161 | VLOG("~MetricsManager()"); |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 162 | } |
| 163 | |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 164 | void MetricsManager::initLogSourceWhiteList() { |
| 165 | std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex); |
| 166 | mAllowedLogSources.clear(); |
| 167 | mAllowedLogSources.insert(mAllowedUid.begin(), mAllowedUid.end()); |
| 168 | |
| 169 | for (const auto& pkg : mAllowedPkg) { |
| 170 | auto uids = mUidMap->getAppUid(pkg); |
| 171 | mAllowedLogSources.insert(uids.begin(), uids.end()); |
| 172 | } |
| 173 | if (DEBUG) { |
| 174 | for (const auto& uid : mAllowedLogSources) { |
| 175 | VLOG("Allowed uid %d", uid); |
| 176 | } |
| 177 | } |
| 178 | } |
| 179 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 180 | bool MetricsManager::isConfigValid() const { |
| 181 | return mConfigValid; |
| 182 | } |
| 183 | |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 184 | void MetricsManager::notifyAppUpgrade(const int64_t& eventTimeNs, const string& apk, const int uid, |
David Chen | 27785a8 | 2018-01-19 17:06:45 -0800 | [diff] [blame] | 185 | const int64_t version) { |
Tej Singh | 9ec159a | 2019-11-14 11:59:48 -0800 | [diff] [blame] | 186 | // Inform all metric producers. |
| 187 | for (auto it : mAllMetricProducers) { |
| 188 | it->notifyAppUpgrade(eventTimeNs, apk, uid, version); |
| 189 | } |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 190 | // check if we care this package |
| 191 | if (std::find(mAllowedPkg.begin(), mAllowedPkg.end(), apk) == mAllowedPkg.end()) { |
| 192 | return; |
| 193 | } |
| 194 | // We will re-initialize the whole list because we don't want to keep the multi mapping of |
| 195 | // UID<->pkg inside MetricsManager to reduce the memory usage. |
| 196 | initLogSourceWhiteList(); |
| 197 | } |
| 198 | |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 199 | void MetricsManager::notifyAppRemoved(const int64_t& eventTimeNs, const string& apk, |
David Chen | 27785a8 | 2018-01-19 17:06:45 -0800 | [diff] [blame] | 200 | const int uid) { |
Tej Singh | 9ec159a | 2019-11-14 11:59:48 -0800 | [diff] [blame] | 201 | // Inform all metric producers. |
| 202 | for (auto it : mAllMetricProducers) { |
| 203 | it->notifyAppRemoved(eventTimeNs, apk, uid); |
| 204 | } |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 205 | // check if we care this package |
| 206 | if (std::find(mAllowedPkg.begin(), mAllowedPkg.end(), apk) == mAllowedPkg.end()) { |
| 207 | return; |
| 208 | } |
| 209 | // We will re-initialize the whole list because we don't want to keep the multi mapping of |
| 210 | // UID<->pkg inside MetricsManager to reduce the memory usage. |
| 211 | initLogSourceWhiteList(); |
| 212 | } |
| 213 | |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 214 | void MetricsManager::onUidMapReceived(const int64_t& eventTimeNs) { |
Tej Singh | 9ec159a | 2019-11-14 11:59:48 -0800 | [diff] [blame] | 215 | // Purposefully don't inform metric producers on a new snapshot |
| 216 | // because we don't need to flush partial buckets. |
| 217 | // This occurs if a new user is added/removed or statsd crashes. |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 218 | if (mAllowedPkg.size() == 0) { |
| 219 | return; |
| 220 | } |
| 221 | initLogSourceWhiteList(); |
| 222 | } |
| 223 | |
Yao Chen | 884c8c1 | 2018-01-26 10:36:25 -0800 | [diff] [blame] | 224 | void MetricsManager::dumpStates(FILE* out, bool verbose) { |
| 225 | fprintf(out, "ConfigKey %s, allowed source:", mConfigKey.ToString().c_str()); |
| 226 | { |
| 227 | std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex); |
| 228 | for (const auto& source : mAllowedLogSources) { |
| 229 | fprintf(out, "%d ", source); |
| 230 | } |
| 231 | } |
| 232 | fprintf(out, "\n"); |
| 233 | for (const auto& producer : mAllMetricProducers) { |
| 234 | producer->dumpStates(out, verbose); |
| 235 | } |
| 236 | } |
| 237 | |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 238 | void MetricsManager::dropData(const int64_t dropTimeNs) { |
Yao Chen | 06dba5d | 2018-01-26 13:38:16 -0800 | [diff] [blame] | 239 | for (const auto& producer : mAllMetricProducers) { |
| 240 | producer->dropData(dropTimeNs); |
| 241 | } |
| 242 | } |
| 243 | |
Yangster-mac | e68f3a5 | 2018-04-04 00:01:43 -0700 | [diff] [blame] | 244 | void MetricsManager::onDumpReport(const int64_t dumpTimeStampNs, |
| 245 | const bool include_current_partial_bucket, |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 246 | const bool erase_data, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 247 | const DumpLatency dumpLatency, |
Yangster-mac | 9def8e3 | 2018-04-17 13:55:51 -0700 | [diff] [blame] | 248 | std::set<string> *str_set, |
Yangster-mac | e68f3a5 | 2018-04-04 00:01:43 -0700 | [diff] [blame] | 249 | ProtoOutputStream* protoOutput) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 250 | VLOG("=========================Metric Reports Start=========================="); |
| 251 | // one StatsLogReport per MetricProduer |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 252 | for (const auto& producer : mAllMetricProducers) { |
| 253 | if (mNoReportMetricIds.find(producer->getMetricId()) == mNoReportMetricIds.end()) { |
Yangster-mac | 9def8e3 | 2018-04-17 13:55:51 -0700 | [diff] [blame] | 254 | uint64_t token = protoOutput->start( |
| 255 | FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_METRICS); |
Yangster-mac | 1c58f04 | 2018-05-17 15:52:51 -0700 | [diff] [blame] | 256 | if (mHashStringsInReport) { |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 257 | producer->onDumpReport(dumpTimeStampNs, include_current_partial_bucket, erase_data, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 258 | dumpLatency, str_set, protoOutput); |
Yangster-mac | 1c58f04 | 2018-05-17 15:52:51 -0700 | [diff] [blame] | 259 | } else { |
Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 260 | producer->onDumpReport(dumpTimeStampNs, include_current_partial_bucket, erase_data, |
Olivier Gaillard | 6c75ecd | 2019-02-20 09:57:33 +0000 | [diff] [blame] | 261 | dumpLatency, nullptr, protoOutput); |
Yangster-mac | 1c58f04 | 2018-05-17 15:52:51 -0700 | [diff] [blame] | 262 | } |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 263 | protoOutput->end(token); |
Yangster-mac | a802d73 | 2018-04-24 07:50:38 -0700 | [diff] [blame] | 264 | } else { |
| 265 | producer->clearPastBuckets(dumpTimeStampNs); |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 266 | } |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 267 | } |
David Chen | faa1af5 | 2018-03-30 15:14:04 -0700 | [diff] [blame] | 268 | for (const auto& annotation : mAnnotations) { |
| 269 | uint64_t token = protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | |
| 270 | FIELD_ID_ANNOTATIONS); |
| 271 | protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_ANNOTATIONS_INT64, |
| 272 | (long long)annotation.first); |
| 273 | protoOutput->write(FIELD_TYPE_INT32 | FIELD_ID_ANNOTATIONS_INT32, annotation.second); |
| 274 | protoOutput->end(token); |
| 275 | } |
Yangster-mac | 9def8e3 | 2018-04-17 13:55:51 -0700 | [diff] [blame] | 276 | |
Yangster-mac | 330af58 | 2018-02-08 15:24:38 -0800 | [diff] [blame] | 277 | mLastReportTimeNs = dumpTimeStampNs; |
Yangster-mac | 3fa5d7f | 2018-03-10 21:50:27 -0800 | [diff] [blame] | 278 | mLastReportWallClockNs = getWallClockNs(); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 279 | VLOG("=========================Metric Reports End=========================="); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 282 | |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 283 | bool MetricsManager::checkLogCredentials(const LogEvent& event) { |
| 284 | if (android::util::AtomsInfo::kWhitelistedAtoms.find(event.GetTagId()) != |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 285 | android::util::AtomsInfo::kWhitelistedAtoms.end()) |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 286 | { |
| 287 | return true; |
| 288 | } |
| 289 | std::lock_guard<std::mutex> lock(mAllowedLogSourcesMutex); |
| 290 | if (mAllowedLogSources.find(event.GetUid()) == mAllowedLogSources.end()) { |
| 291 | VLOG("log source %d not on the whitelist", event.GetUid()); |
| 292 | return false; |
| 293 | } |
| 294 | return true; |
| 295 | } |
| 296 | |
| 297 | bool MetricsManager::eventSanityCheck(const LogEvent& event) { |
David Chen | b639d14 | 2018-02-14 17:29:54 -0800 | [diff] [blame] | 298 | if (event.GetTagId() == android::util::APP_BREADCRUMB_REPORTED) { |
| 299 | // Check that app breadcrumb reported fields are valid. |
David Chen | daa9f3a | 2017-12-28 16:52:22 -0800 | [diff] [blame] | 300 | status_t err = NO_ERROR; |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 301 | |
| 302 | // Uid is 3rd from last field and must match the caller's uid, |
| 303 | // unless that caller is statsd itself (statsd is allowed to spoof uids). |
| 304 | long appHookUid = event.GetLong(event.size()-2, &err); |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 305 | if (err != NO_ERROR ) { |
| 306 | VLOG("APP_BREADCRUMB_REPORTED had error when parsing the uid"); |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 307 | return false; |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 308 | } |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 309 | int32_t loggerUid = event.GetUid(); |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 310 | if (loggerUid != appHookUid && loggerUid != AID_STATSD) { |
| 311 | VLOG("APP_BREADCRUMB_REPORTED has invalid uid: claimed %ld but caller is %d", |
| 312 | appHookUid, loggerUid); |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 313 | return false; |
David Chen | daa9f3a | 2017-12-28 16:52:22 -0800 | [diff] [blame] | 314 | } |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 315 | |
David Chen | daa9f3a | 2017-12-28 16:52:22 -0800 | [diff] [blame] | 316 | // The state must be from 0,3. This part of code must be manually updated. |
Bookatz | b223c4e | 2018-02-01 15:35:04 -0800 | [diff] [blame] | 317 | long appHookState = event.GetLong(event.size(), &err); |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 318 | if (err != NO_ERROR ) { |
| 319 | VLOG("APP_BREADCRUMB_REPORTED had error when parsing the state field"); |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 320 | return false; |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 321 | } else if (appHookState < 0 || appHookState > 3) { |
| 322 | VLOG("APP_BREADCRUMB_REPORTED does not have valid state %ld", appHookState); |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 323 | return false; |
David Chen | daa9f3a | 2017-12-28 16:52:22 -0800 | [diff] [blame] | 324 | } |
Tej Singh | bb8554a | 2018-01-26 11:59:14 -0800 | [diff] [blame] | 325 | } else if (event.GetTagId() == android::util::DAVEY_OCCURRED) { |
| 326 | // Daveys can be logged from any app since they are logged in libs/hwui/JankTracker.cpp. |
| 327 | // Check that the davey duration is reasonable. Max length check is for privacy. |
| 328 | status_t err = NO_ERROR; |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 329 | |
| 330 | // Uid is the first field provided. |
| 331 | long jankUid = event.GetLong(1, &err); |
| 332 | if (err != NO_ERROR ) { |
| 333 | VLOG("Davey occurred had error when parsing the uid"); |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 334 | return false; |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 335 | } |
| 336 | int32_t loggerUid = event.GetUid(); |
| 337 | if (loggerUid != jankUid && loggerUid != AID_STATSD) { |
| 338 | VLOG("DAVEY_OCCURRED has invalid uid: claimed %ld but caller is %d", jankUid, |
| 339 | loggerUid); |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 340 | return false; |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 341 | } |
| 342 | |
Tej Singh | bb8554a | 2018-01-26 11:59:14 -0800 | [diff] [blame] | 343 | long duration = event.GetLong(event.size(), &err); |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 344 | if (err != NO_ERROR ) { |
| 345 | VLOG("Davey occurred had error when parsing the duration"); |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 346 | return false; |
David Chen | 77ef671 | 2018-02-23 18:23:42 -0800 | [diff] [blame] | 347 | } else if (duration > 100000) { |
Tej Singh | bb8554a | 2018-01-26 11:59:14 -0800 | [diff] [blame] | 348 | VLOG("Davey duration is unreasonably long: %ld", duration); |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 349 | return false; |
Tej Singh | bb8554a | 2018-01-26 11:59:14 -0800 | [diff] [blame] | 350 | } |
Andrei Onea | da01ea5 | 2019-01-30 15:28:36 +0000 | [diff] [blame] | 351 | } |
| 352 | |
| 353 | return true; |
| 354 | } |
| 355 | |
| 356 | // Consume the stats log if it's interesting to this metric. |
| 357 | void MetricsManager::onLogEvent(const LogEvent& event) { |
| 358 | if (!mConfigValid) { |
| 359 | return; |
| 360 | } |
| 361 | |
| 362 | if (!checkLogCredentials(event)) { |
| 363 | return; |
| 364 | } |
| 365 | |
| 366 | if (!eventSanityCheck(event)) { |
| 367 | return; |
Yao Chen | d10f7b1 | 2017-12-18 12:53:50 -0800 | [diff] [blame] | 368 | } |
| 369 | |
Joe Onorato | c4dfae5 | 2017-10-17 23:38:21 -0700 | [diff] [blame] | 370 | int tagId = event.GetTagId(); |
Yangster-mac | 849dfdc2 | 2018-10-12 15:41:45 -0700 | [diff] [blame] | 371 | int64_t eventTimeNs = event.GetElapsedTimestampNs(); |
| 372 | |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 373 | bool isActive = mIsAlwaysActive; |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 374 | |
| 375 | // Set of metrics that are still active after flushing. |
| 376 | unordered_set<int> activeMetricsIndices; |
| 377 | |
| 378 | // Update state of all metrics w/ activation conditions as of eventTimeNs. |
| 379 | for (int metricIndex : mMetricIndexesWithActivation) { |
| 380 | const sp<MetricProducer>& metric = mAllMetricProducers[metricIndex]; |
| 381 | metric->flushIfExpire(eventTimeNs); |
| 382 | if (metric->isActive()) { |
| 383 | // If this metric w/ activation condition is still active after |
| 384 | // flushing, remember it. |
| 385 | activeMetricsIndices.insert(metricIndex); |
| 386 | } |
Yangster-mac | 849dfdc2 | 2018-10-12 15:41:45 -0700 | [diff] [blame] | 387 | } |
| 388 | |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 389 | mIsActive = isActive || !activeMetricsIndices.empty(); |
Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame] | 390 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 391 | if (mTagIds.find(tagId) == mTagIds.end()) { |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 392 | // Not interesting... |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 393 | return; |
| 394 | } |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 395 | |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 396 | vector<MatchingState> matcherCache(mAllAtomMatchers.size(), MatchingState::kNotComputed); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 397 | |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 398 | // Evaluate all atom matchers. |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 399 | for (auto& matcher : mAllAtomMatchers) { |
| 400 | matcher->onLogEvent(event, mAllAtomMatchers, matcherCache); |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 403 | // Set of metrics that received an activation cancellation. |
| 404 | unordered_set<int> metricIndicesWithCanceledActivations; |
| 405 | |
| 406 | // Determine which metric activations received a cancellation and cancel them. |
| 407 | for (const auto& it : mDeactivationAtomTrackerToMetricMap) { |
| 408 | if (matcherCache[it.first] == MatchingState::kMatched) { |
| 409 | for (int metricIndex : it.second) { |
| 410 | mAllMetricProducers[metricIndex]->cancelEventActivation(it.first); |
| 411 | metricIndicesWithCanceledActivations.insert(metricIndex); |
| 412 | } |
| 413 | } |
| 414 | } |
| 415 | |
| 416 | // Determine whether any metrics are no longer active after cancelling metric activations. |
| 417 | for (const int metricIndex : metricIndicesWithCanceledActivations) { |
| 418 | const sp<MetricProducer>& metric = mAllMetricProducers[metricIndex]; |
| 419 | metric->flushIfExpire(eventTimeNs); |
| 420 | if (!metric->isActive()) { |
| 421 | activeMetricsIndices.erase(metricIndex); |
| 422 | } |
| 423 | } |
| 424 | |
| 425 | isActive |= !activeMetricsIndices.empty(); |
| 426 | |
| 427 | |
| 428 | // Determine which metric activations should be turned on and turn them on |
Yangster-mac | 849dfdc2 | 2018-10-12 15:41:45 -0700 | [diff] [blame] | 429 | for (const auto& it : mActivationAtomTrackerToMetricMap) { |
| 430 | if (matcherCache[it.first] == MatchingState::kMatched) { |
| 431 | for (int metricIndex : it.second) { |
| 432 | mAllMetricProducers[metricIndex]->activate(it.first, eventTimeNs); |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 433 | isActive |= mAllMetricProducers[metricIndex]->isActive(); |
Yangster-mac | 849dfdc2 | 2018-10-12 15:41:45 -0700 | [diff] [blame] | 434 | } |
| 435 | } |
| 436 | } |
| 437 | |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 438 | mIsActive = isActive; |
| 439 | |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 440 | // A bitmap to see which ConditionTracker needs to be re-evaluated. |
| 441 | vector<bool> conditionToBeEvaluated(mAllConditionTrackers.size(), false); |
| 442 | |
| 443 | for (const auto& pair : mTrackerToConditionMap) { |
| 444 | if (matcherCache[pair.first] == MatchingState::kMatched) { |
| 445 | const auto& conditionList = pair.second; |
| 446 | for (const int conditionIndex : conditionList) { |
| 447 | conditionToBeEvaluated[conditionIndex] = true; |
| 448 | } |
| 449 | } |
| 450 | } |
| 451 | |
| 452 | vector<ConditionState> conditionCache(mAllConditionTrackers.size(), |
| 453 | ConditionState::kNotEvaluated); |
| 454 | // A bitmap to track if a condition has changed value. |
| 455 | vector<bool> changedCache(mAllConditionTrackers.size(), false); |
| 456 | for (size_t i = 0; i < mAllConditionTrackers.size(); i++) { |
| 457 | if (conditionToBeEvaluated[i] == false) { |
| 458 | continue; |
| 459 | } |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 460 | sp<ConditionTracker>& condition = mAllConditionTrackers[i]; |
| 461 | condition->evaluateCondition(event, matcherCache, mAllConditionTrackers, conditionCache, |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 462 | changedCache); |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | for (size_t i = 0; i < mAllConditionTrackers.size(); i++) { |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 466 | if (changedCache[i] == false) { |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 467 | continue; |
| 468 | } |
| 469 | auto pair = mConditionToMetricMap.find(i); |
| 470 | if (pair != mConditionToMetricMap.end()) { |
| 471 | auto& metricList = pair->second; |
| 472 | for (auto metricIndex : metricList) { |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 473 | // Metric cares about non sliced condition, and it's changed. |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 474 | // Push the new condition to it directly. |
Yao Chen | 967b205 | 2017-11-07 16:36:43 -0800 | [diff] [blame] | 475 | if (!mAllMetricProducers[metricIndex]->isConditionSliced()) { |
Yao Chen | 5154a379 | 2017-10-30 22:57:06 -0700 | [diff] [blame] | 476 | mAllMetricProducers[metricIndex]->onConditionChanged(conditionCache[i], |
Yangster-mac | 849dfdc2 | 2018-10-12 15:41:45 -0700 | [diff] [blame] | 477 | eventTimeNs); |
Muhammad Qureshi | 3a5ebf5 | 2019-03-28 12:38:21 -0700 | [diff] [blame] | 478 | // Metric cares about sliced conditions, and it may have changed. Send |
Yao Chen | 729093d | 2017-10-16 10:33:26 -0700 | [diff] [blame] | 479 | // notification, and the metric can query the sliced conditions that are |
| 480 | // interesting to it. |
Yangster | f2bee6f | 2017-11-29 12:01:05 -0800 | [diff] [blame] | 481 | } else { |
Yao Chen | 427d372 | 2018-03-22 15:21:52 -0700 | [diff] [blame] | 482 | mAllMetricProducers[metricIndex]->onSlicedConditionMayChange(conditionCache[i], |
Yangster-mac | 849dfdc2 | 2018-10-12 15:41:45 -0700 | [diff] [blame] | 483 | eventTimeNs); |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 484 | } |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 485 | } |
| 486 | } |
| 487 | } |
| 488 | |
Stefan Lafon | b8c9aa8 | 2017-12-03 14:27:25 -0800 | [diff] [blame] | 489 | // For matched AtomMatchers, tell relevant metrics that a matched event has come. |
| 490 | for (size_t i = 0; i < mAllAtomMatchers.size(); i++) { |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 491 | if (matcherCache[i] == MatchingState::kMatched) { |
Yao Chen | b356151 | 2017-11-21 18:07:17 -0800 | [diff] [blame] | 492 | StatsdStats::getInstance().noteMatcherMatched(mConfigKey, |
Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 493 | mAllAtomMatchers[i]->getId()); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 494 | auto pair = mTrackerToMetricMap.find(i); |
| 495 | if (pair != mTrackerToMetricMap.end()) { |
| 496 | auto& metricList = pair->second; |
| 497 | for (const int metricIndex : metricList) { |
Chenjie Yu | b3dda41 | 2017-10-24 13:41:59 -0700 | [diff] [blame] | 498 | // pushed metrics are never scheduled pulls |
Chenjie Yu | a7259ab | 2017-12-10 08:31:05 -0800 | [diff] [blame] | 499 | mAllMetricProducers[metricIndex]->onMatchedLogEvent(i, event); |
Yao Chen | caf339d | 2017-10-06 16:01:10 -0700 | [diff] [blame] | 500 | } |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 501 | } |
| 502 | } |
| 503 | } |
| 504 | } |
| 505 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 506 | void MetricsManager::onAnomalyAlarmFired( |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 507 | const int64_t& timestampNs, |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 508 | unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet) { |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 509 | for (const auto& itr : mAllAnomalyTrackers) { |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 510 | itr->informAlarmsFired(timestampNs, alarmSet); |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 511 | } |
| 512 | } |
| 513 | |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 514 | void MetricsManager::onPeriodicAlarmFired( |
Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 515 | const int64_t& timestampNs, |
Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 516 | unordered_set<sp<const InternalAlarm>, SpHash<InternalAlarm>>& alarmSet) { |
| 517 | for (const auto& itr : mAllPeriodicAlarmTrackers) { |
| 518 | itr->informAlarmsFired(timestampNs, alarmSet); |
Yangster-mac | e2cd6d5 | 2017-11-09 20:38:30 -0800 | [diff] [blame] | 519 | } |
| 520 | } |
| 521 | |
yro | 69007c8 | 2017-10-26 20:42:57 -0700 | [diff] [blame] | 522 | // Returns the total byte size of all metrics managed by a single config source. |
| 523 | size_t MetricsManager::byteSize() { |
| 524 | size_t totalSize = 0; |
Chih-Hung Hsieh | a1b644e | 2018-12-11 11:09:20 -0800 | [diff] [blame] | 525 | for (const auto& metricProducer : mAllMetricProducers) { |
yro | 69007c8 | 2017-10-26 20:42:57 -0700 | [diff] [blame] | 526 | totalSize += metricProducer->byteSize(); |
| 527 | } |
| 528 | return totalSize; |
| 529 | } |
| 530 | |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 531 | void MetricsManager::loadActiveConfig(const ActiveConfig& config, int64_t currentTimeNs) { |
| 532 | if (config.metric_size() == 0) { |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 533 | ALOGW("No active metric for config %s", mConfigKey.ToString().c_str()); |
| 534 | return; |
| 535 | } |
| 536 | |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 537 | for (int i = 0; i < config.metric_size(); i++) { |
| 538 | const auto& activeMetric = config.metric(i); |
| 539 | for (int metricIndex : mMetricIndexesWithActivation) { |
| 540 | const auto& metric = mAllMetricProducers[metricIndex]; |
| 541 | if (metric->getMetricId() == activeMetric.id()) { |
| 542 | VLOG("Setting active metric: %lld", (long long)metric->getMetricId()); |
| 543 | metric->loadActiveMetric(activeMetric, currentTimeNs); |
Tej Singh | 16ca28f | 2019-06-24 11:58:23 -0700 | [diff] [blame] | 544 | if (!mIsActive && metric->isActive()) { |
| 545 | StatsdStats::getInstance().noteActiveStatusChanged(mConfigKey, |
| 546 | /*activate=*/ true); |
| 547 | } |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 548 | mIsActive |= metric->isActive(); |
Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 549 | } |
| 550 | } |
| 551 | } |
| 552 | } |
| 553 | |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 554 | void MetricsManager::writeActiveConfigToProtoOutputStream( |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame] | 555 | int64_t currentTimeNs, const DumpReportReason reason, ProtoOutputStream* proto) { |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 556 | proto->write(FIELD_TYPE_INT64 | FIELD_ID_ACTIVE_CONFIG_ID, (long long)mConfigKey.GetId()); |
| 557 | proto->write(FIELD_TYPE_INT32 | FIELD_ID_ACTIVE_CONFIG_UID, mConfigKey.GetUid()); |
| 558 | for (int metricIndex : mMetricIndexesWithActivation) { |
| 559 | const auto& metric = mAllMetricProducers[metricIndex]; |
| 560 | const uint64_t metricToken = proto->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | |
| 561 | FIELD_ID_ACTIVE_CONFIG_METRIC); |
Tej Singh | f53d445 | 2019-05-09 18:17:59 -0700 | [diff] [blame] | 562 | metric->writeActiveMetricToProtoOutputStream(currentTimeNs, reason, proto); |
Muhammad Qureshi | 844694b | 2019-04-05 10:10:40 -0700 | [diff] [blame] | 563 | proto->end(metricToken); |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | |
| 568 | |
| 569 | |
Yao Chen | 44cf27c | 2017-09-14 22:32:50 -0700 | [diff] [blame] | 570 | } // namespace statsd |
| 571 | } // namespace os |
| 572 | } // namespace android |