| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 1 | // Copyright (C) 2017 The Android Open Source Project |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | #include "StatsLogProcessor.h" |
| 16 | #include "config/ConfigKey.h" |
| David Chen | 35045cb | 2018-03-23 22:21:47 -0700 | [diff] [blame] | 17 | #include "frameworks/base/cmds/statsd/src/stats_log.pb.h" |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 18 | #include "frameworks/base/cmds/statsd/src/statsd_config.pb.h" |
| 19 | #include "guardrail/StatsdStats.h" |
| 20 | #include "logd/LogEvent.h" |
| 21 | #include "packages/UidMap.h" |
| 22 | #include "statslog.h" |
| 23 | |
| 24 | #include <gmock/gmock.h> |
| 25 | #include <gtest/gtest.h> |
| 26 | |
| David Chen | 9e6dbbd | 2018-05-07 17:52:29 -0700 | [diff] [blame] | 27 | #include "tests/statsd_test_util.h" |
| 28 | |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 29 | #include <stdio.h> |
| 30 | |
| 31 | using namespace android; |
| 32 | using namespace testing; |
| 33 | |
| 34 | namespace android { |
| 35 | namespace os { |
| 36 | namespace statsd { |
| 37 | |
| Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 38 | using android::util::ProtoOutputStream; |
| 39 | |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 40 | #ifdef __ANDROID__ |
| 41 | |
| 42 | /** |
| 43 | * Mock MetricsManager (ByteSize() is called). |
| 44 | */ |
| 45 | class MockMetricsManager : public MetricsManager { |
| 46 | public: |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 47 | MockMetricsManager() |
| 48 | : MetricsManager(ConfigKey(1, 12345), StatsdConfig(), 1000, 1000, new UidMap(), |
| 49 | new StatsPullerManager(), |
| 50 | new AlarmMonitor(10, [](const sp<IStatsCompanionService>&, int64_t) {}, |
| 51 | [](const sp<IStatsCompanionService>&) {}), |
| 52 | new AlarmMonitor(10, [](const sp<IStatsCompanionService>&, int64_t) {}, |
| 53 | [](const sp<IStatsCompanionService>&) {})) { |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | MOCK_METHOD0(byteSize, size_t()); |
| Yao Chen | 06dba5d | 2018-01-26 13:38:16 -0800 | [diff] [blame] | 57 | |
| Yangster-mac | b142cc8 | 2018-03-30 15:22:08 -0700 | [diff] [blame] | 58 | MOCK_METHOD1(dropData, void(const int64_t dropTimeNs)); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 59 | }; |
| 60 | |
| 61 | TEST(StatsLogProcessorTest, TestRateLimitByteSize) { |
| 62 | sp<UidMap> m = new UidMap(); |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 63 | sp<StatsPullerManager> pullerManager = new StatsPullerManager(); |
| Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 64 | sp<AlarmMonitor> anomalyAlarmMonitor; |
| 65 | sp<AlarmMonitor> periodicAlarmMonitor; |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 66 | // Construct the processor with a dummy sendBroadcast function that does nothing. |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 67 | StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, periodicAlarmMonitor, 0, |
| Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame^] | 68 | [](const ConfigKey& key) { return true; }, |
| 69 | [](const int&, const vector<int64_t>&) {return true;}); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 70 | |
| 71 | MockMetricsManager mockMetricsManager; |
| 72 | |
| Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 73 | ConfigKey key(100, 12345); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 74 | // Expect only the first flush to trigger a check for byte size since the last two are |
| 75 | // rate-limited. |
| 76 | EXPECT_CALL(mockMetricsManager, byteSize()).Times(1); |
| Yangster-mac | b0d0628 | 2018-01-05 15:44:07 -0800 | [diff] [blame] | 77 | p.flushIfNecessaryLocked(99, key, mockMetricsManager); |
| 78 | p.flushIfNecessaryLocked(100, key, mockMetricsManager); |
| 79 | p.flushIfNecessaryLocked(101, key, mockMetricsManager); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 80 | } |
| 81 | |
| 82 | TEST(StatsLogProcessorTest, TestRateLimitBroadcast) { |
| 83 | sp<UidMap> m = new UidMap(); |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 84 | sp<StatsPullerManager> pullerManager = new StatsPullerManager(); |
| Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 85 | sp<AlarmMonitor> anomalyAlarmMonitor; |
| 86 | sp<AlarmMonitor> subscriberAlarmMonitor; |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 87 | int broadcastCount = 0; |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 88 | StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0, |
| 89 | [&broadcastCount](const ConfigKey& key) { |
| 90 | broadcastCount++; |
| 91 | return true; |
| Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame^] | 92 | }, |
| 93 | [](const int&, const vector<int64_t>&) {return true;}); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 94 | |
| 95 | MockMetricsManager mockMetricsManager; |
| 96 | |
| Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 97 | ConfigKey key(100, 12345); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 98 | EXPECT_CALL(mockMetricsManager, byteSize()) |
| Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 99 | .Times(1) |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 100 | .WillRepeatedly(Return(int(StatsdStats::kMaxMetricsBytesPerConfig * .95))); |
| 101 | |
| 102 | // Expect only one broadcast despite always returning a size that should trigger broadcast. |
| Yangster-mac | b0d0628 | 2018-01-05 15:44:07 -0800 | [diff] [blame] | 103 | p.flushIfNecessaryLocked(1, key, mockMetricsManager); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 104 | EXPECT_EQ(1, broadcastCount); |
| 105 | |
| Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 106 | // b/73089712 |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 107 | // This next call to flush should not trigger a broadcast. |
| Yao Chen | 8a8d16c | 2018-02-08 14:50:40 -0800 | [diff] [blame] | 108 | // p.mLastByteSizeTimes.clear(); // Force another check for byte size. |
| 109 | // p.flushIfNecessaryLocked(2, key, mockMetricsManager); |
| 110 | // EXPECT_EQ(1, broadcastCount); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 111 | } |
| 112 | |
| 113 | TEST(StatsLogProcessorTest, TestDropWhenByteSizeTooLarge) { |
| 114 | sp<UidMap> m = new UidMap(); |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 115 | sp<StatsPullerManager> pullerManager = new StatsPullerManager(); |
| Yangster-mac | 932ecec | 2018-02-01 10:23:52 -0800 | [diff] [blame] | 116 | sp<AlarmMonitor> anomalyAlarmMonitor; |
| 117 | sp<AlarmMonitor> subscriberAlarmMonitor; |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 118 | int broadcastCount = 0; |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 119 | StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0, |
| 120 | [&broadcastCount](const ConfigKey& key) { |
| 121 | broadcastCount++; |
| 122 | return true; |
| Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame^] | 123 | }, |
| 124 | [](const int&, const vector<int64_t>&) {return true;}); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 125 | |
| 126 | MockMetricsManager mockMetricsManager; |
| 127 | |
| Yangster-mac | 94e197c | 2018-01-02 16:03:03 -0800 | [diff] [blame] | 128 | ConfigKey key(100, 12345); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 129 | EXPECT_CALL(mockMetricsManager, byteSize()) |
| 130 | .Times(1) |
| 131 | .WillRepeatedly(Return(int(StatsdStats::kMaxMetricsBytesPerConfig * 1.2))); |
| 132 | |
| Yao Chen | 06dba5d | 2018-01-26 13:38:16 -0800 | [diff] [blame] | 133 | EXPECT_CALL(mockMetricsManager, dropData(_)).Times(1); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 134 | |
| 135 | // Expect to call the onDumpReport and skip the broadcast. |
| Yangster-mac | b0d0628 | 2018-01-05 15:44:07 -0800 | [diff] [blame] | 136 | p.flushIfNecessaryLocked(1, key, mockMetricsManager); |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 137 | EXPECT_EQ(0, broadcastCount); |
| 138 | } |
| 139 | |
| David Chen | 9e6dbbd | 2018-05-07 17:52:29 -0700 | [diff] [blame] | 140 | StatsdConfig MakeConfig(bool includeMetric) { |
| 141 | StatsdConfig config; |
| 142 | config.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root. |
| 143 | |
| 144 | if (includeMetric) { |
| 145 | auto appCrashMatcher = CreateProcessCrashAtomMatcher(); |
| 146 | *config.add_atom_matcher() = appCrashMatcher; |
| 147 | auto countMetric = config.add_count_metric(); |
| 148 | countMetric->set_id(StringToId("AppCrashes")); |
| 149 | countMetric->set_what(appCrashMatcher.id()); |
| 150 | countMetric->set_bucket(FIVE_MINUTES); |
| 151 | } |
| 152 | return config; |
| 153 | } |
| 154 | |
| David Chen | 35045cb | 2018-03-23 22:21:47 -0700 | [diff] [blame] | 155 | TEST(StatsLogProcessorTest, TestUidMapHasSnapshot) { |
| 156 | // Setup simple config key corresponding to empty config. |
| 157 | sp<UidMap> m = new UidMap(); |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 158 | sp<StatsPullerManager> pullerManager = new StatsPullerManager(); |
| dwchen | 730403e | 2018-10-29 11:41:56 -0700 | [diff] [blame] | 159 | m->updateMap(1, {1, 2}, {1, 2}, {String16("v1"), String16("v2")}, |
| 160 | {String16("p1"), String16("p2")}, {String16(""), String16("")}); |
| David Chen | 35045cb | 2018-03-23 22:21:47 -0700 | [diff] [blame] | 161 | sp<AlarmMonitor> anomalyAlarmMonitor; |
| 162 | sp<AlarmMonitor> subscriberAlarmMonitor; |
| 163 | int broadcastCount = 0; |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 164 | StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0, |
| 165 | [&broadcastCount](const ConfigKey& key) { |
| 166 | broadcastCount++; |
| 167 | return true; |
| Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame^] | 168 | }, |
| 169 | [](const int&, const vector<int64_t>&) {return true;}); |
| David Chen | 35045cb | 2018-03-23 22:21:47 -0700 | [diff] [blame] | 170 | ConfigKey key(3, 4); |
| David Chen | 9e6dbbd | 2018-05-07 17:52:29 -0700 | [diff] [blame] | 171 | StatsdConfig config = MakeConfig(true); |
| Yangster-mac | c04feba | 2018-04-02 14:37:33 -0700 | [diff] [blame] | 172 | p.OnConfigUpdated(0, key, config); |
| David Chen | 35045cb | 2018-03-23 22:21:47 -0700 | [diff] [blame] | 173 | |
| 174 | // Expect to get no metrics, but snapshot specified above in uidmap. |
| 175 | vector<uint8_t> bytes; |
| Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 176 | p.onDumpReport(key, 1, false, true, ADB_DUMP, &bytes); |
| David Chen | 35045cb | 2018-03-23 22:21:47 -0700 | [diff] [blame] | 177 | |
| 178 | ConfigMetricsReportList output; |
| 179 | output.ParseFromArray(bytes.data(), bytes.size()); |
| 180 | EXPECT_TRUE(output.reports_size() > 0); |
| 181 | auto uidmap = output.reports(0).uid_map(); |
| 182 | EXPECT_TRUE(uidmap.snapshots_size() > 0); |
| 183 | EXPECT_EQ(2, uidmap.snapshots(0).package_info_size()); |
| 184 | } |
| 185 | |
| David Chen | 9e6dbbd | 2018-05-07 17:52:29 -0700 | [diff] [blame] | 186 | TEST(StatsLogProcessorTest, TestEmptyConfigHasNoUidMap) { |
| 187 | // Setup simple config key corresponding to empty config. |
| 188 | sp<UidMap> m = new UidMap(); |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 189 | sp<StatsPullerManager> pullerManager = new StatsPullerManager(); |
| dwchen | 730403e | 2018-10-29 11:41:56 -0700 | [diff] [blame] | 190 | m->updateMap(1, {1, 2}, {1, 2}, {String16("v1"), String16("v2")}, |
| 191 | {String16("p1"), String16("p2")}, {String16(""), String16("")}); |
| David Chen | 9e6dbbd | 2018-05-07 17:52:29 -0700 | [diff] [blame] | 192 | sp<AlarmMonitor> anomalyAlarmMonitor; |
| 193 | sp<AlarmMonitor> subscriberAlarmMonitor; |
| 194 | int broadcastCount = 0; |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 195 | StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0, |
| 196 | [&broadcastCount](const ConfigKey& key) { |
| 197 | broadcastCount++; |
| 198 | return true; |
| Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame^] | 199 | }, |
| 200 | [](const int&, const vector<int64_t>&) {return true;}); |
| David Chen | 9e6dbbd | 2018-05-07 17:52:29 -0700 | [diff] [blame] | 201 | ConfigKey key(3, 4); |
| 202 | StatsdConfig config = MakeConfig(false); |
| 203 | p.OnConfigUpdated(0, key, config); |
| 204 | |
| 205 | // Expect to get no metrics, but snapshot specified above in uidmap. |
| 206 | vector<uint8_t> bytes; |
| Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 207 | p.onDumpReport(key, 1, false, true, ADB_DUMP, &bytes); |
| David Chen | 9e6dbbd | 2018-05-07 17:52:29 -0700 | [diff] [blame] | 208 | |
| 209 | ConfigMetricsReportList output; |
| 210 | output.ParseFromArray(bytes.data(), bytes.size()); |
| 211 | EXPECT_TRUE(output.reports_size() > 0); |
| 212 | EXPECT_FALSE(output.reports(0).has_uid_map()); |
| 213 | } |
| 214 | |
| David Chen | faa1af5 | 2018-03-30 15:14:04 -0700 | [diff] [blame] | 215 | TEST(StatsLogProcessorTest, TestReportIncludesSubConfig) { |
| 216 | // Setup simple config key corresponding to empty config. |
| 217 | sp<UidMap> m = new UidMap(); |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 218 | sp<StatsPullerManager> pullerManager = new StatsPullerManager(); |
| David Chen | faa1af5 | 2018-03-30 15:14:04 -0700 | [diff] [blame] | 219 | sp<AlarmMonitor> anomalyAlarmMonitor; |
| 220 | sp<AlarmMonitor> subscriberAlarmMonitor; |
| 221 | int broadcastCount = 0; |
| Chenjie Yu | e221920 | 2018-06-08 10:07:51 -0700 | [diff] [blame] | 222 | StatsLogProcessor p(m, pullerManager, anomalyAlarmMonitor, subscriberAlarmMonitor, 0, |
| 223 | [&broadcastCount](const ConfigKey& key) { |
| 224 | broadcastCount++; |
| 225 | return true; |
| Tej Singh | 6ede28b | 2019-01-29 17:06:54 -0800 | [diff] [blame^] | 226 | }, |
| 227 | [](const int&, const vector<int64_t>&) {return true;}); |
| David Chen | faa1af5 | 2018-03-30 15:14:04 -0700 | [diff] [blame] | 228 | ConfigKey key(3, 4); |
| 229 | StatsdConfig config; |
| 230 | auto annotation = config.add_annotation(); |
| 231 | annotation->set_field_int64(1); |
| 232 | annotation->set_field_int32(2); |
| 233 | config.add_allowed_log_source("AID_ROOT"); |
| 234 | p.OnConfigUpdated(1, key, config); |
| 235 | |
| 236 | // Expect to get no metrics, but snapshot specified above in uidmap. |
| 237 | vector<uint8_t> bytes; |
| Bookatz | ff71cad | 2018-09-20 17:17:49 -0700 | [diff] [blame] | 238 | p.onDumpReport(key, 1, false, true, ADB_DUMP, &bytes); |
| David Chen | faa1af5 | 2018-03-30 15:14:04 -0700 | [diff] [blame] | 239 | |
| 240 | ConfigMetricsReportList output; |
| 241 | output.ParseFromArray(bytes.data(), bytes.size()); |
| 242 | EXPECT_TRUE(output.reports_size() > 0); |
| 243 | auto report = output.reports(0); |
| 244 | EXPECT_EQ(1, report.annotation_size()); |
| 245 | EXPECT_EQ(1, report.annotation(0).field_int64()); |
| 246 | EXPECT_EQ(2, report.annotation(0).field_int32()); |
| 247 | } |
| 248 | |
| Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 249 | TEST(StatsLogProcessorTest, TestOnDumpReportEraseData) { |
| 250 | // Setup a simple config. |
| 251 | StatsdConfig config; |
| 252 | config.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root. |
| 253 | auto wakelockAcquireMatcher = CreateAcquireWakelockAtomMatcher(); |
| 254 | *config.add_atom_matcher() = wakelockAcquireMatcher; |
| 255 | |
| 256 | auto countMetric = config.add_count_metric(); |
| 257 | countMetric->set_id(123456); |
| 258 | countMetric->set_what(wakelockAcquireMatcher.id()); |
| 259 | countMetric->set_bucket(FIVE_MINUTES); |
| 260 | |
| 261 | ConfigKey cfgKey; |
| 262 | sp<StatsLogProcessor> processor = CreateStatsLogProcessor(1, 1, config, cfgKey); |
| 263 | |
| 264 | std::vector<AttributionNodeInternal> attributions1 = {CreateAttribution(111, "App1")}; |
| 265 | auto event = CreateAcquireWakelockEvent(attributions1, "wl1", 2); |
| 266 | processor->OnLogEvent(event.get()); |
| 267 | |
| 268 | vector<uint8_t> bytes; |
| 269 | ConfigMetricsReportList output; |
| 270 | |
| 271 | // Dump report WITHOUT erasing data. |
| 272 | processor->onDumpReport(cfgKey, 3, true, false /* Do NOT erase data. */, ADB_DUMP, &bytes); |
| 273 | output.ParseFromArray(bytes.data(), bytes.size()); |
| 274 | EXPECT_EQ(output.reports_size(), 1); |
| 275 | EXPECT_EQ(output.reports(0).metrics_size(), 1); |
| 276 | EXPECT_EQ(output.reports(0).metrics(0).count_metrics().data_size(), 1); |
| 277 | |
| 278 | // Dump report WITH erasing data. There should be data since we didn't previously erase it. |
| 279 | processor->onDumpReport(cfgKey, 4, true, true /* DO erase data. */, ADB_DUMP, &bytes); |
| 280 | output.ParseFromArray(bytes.data(), bytes.size()); |
| 281 | EXPECT_EQ(output.reports_size(), 1); |
| 282 | EXPECT_EQ(output.reports(0).metrics_size(), 1); |
| 283 | EXPECT_EQ(output.reports(0).metrics(0).count_metrics().data_size(), 1); |
| 284 | |
| 285 | // Dump report again. There should be no data since we erased it. |
| 286 | processor->onDumpReport(cfgKey, 5, true, true /* DO erase data. */, ADB_DUMP, &bytes); |
| 287 | output.ParseFromArray(bytes.data(), bytes.size()); |
| Bookatz | ea20bff | 2018-12-18 10:07:56 -0800 | [diff] [blame] | 288 | // We don't care whether statsd has a report, as long as it has no count metrics in it. |
| 289 | bool noData = output.reports_size() == 0 |
| 290 | || output.reports(0).metrics_size() == 0 |
| 291 | || output.reports(0).metrics(0).count_metrics().data_size() == 0; |
| Bookatz | 3e90658 | 2018-12-10 17:26:58 -0800 | [diff] [blame] | 292 | EXPECT_TRUE(noData); |
| 293 | } |
| 294 | |
| Chenjie Yu | c7939cb | 2019-02-04 17:25:45 -0800 | [diff] [blame] | 295 | TEST(StatsLogProcessorTest, TestActiveConfigMetricDiskWriteRead) { |
| 296 | int uid = 1111; |
| 297 | |
| 298 | // Setup a simple config, no activation |
| 299 | StatsdConfig config1; |
| 300 | config1.set_id(12341); |
| 301 | config1.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root. |
| 302 | auto wakelockAcquireMatcher = CreateAcquireWakelockAtomMatcher(); |
| 303 | *config1.add_atom_matcher() = wakelockAcquireMatcher; |
| 304 | |
| 305 | long metricId1 = 1234561; |
| 306 | long metricId2 = 1234562; |
| 307 | auto countMetric1 = config1.add_count_metric(); |
| 308 | countMetric1->set_id(metricId1); |
| 309 | countMetric1->set_what(wakelockAcquireMatcher.id()); |
| 310 | countMetric1->set_bucket(FIVE_MINUTES); |
| 311 | |
| 312 | auto countMetric2 = config1.add_count_metric(); |
| 313 | countMetric2->set_id(metricId2); |
| 314 | countMetric2->set_what(wakelockAcquireMatcher.id()); |
| 315 | countMetric2->set_bucket(FIVE_MINUTES); |
| 316 | |
| 317 | ConfigKey cfgKey1(uid, 12341); |
| 318 | long timeBase1 = 1; |
| 319 | sp<StatsLogProcessor> processor = |
| 320 | CreateStatsLogProcessor(timeBase1, timeBase1, config1, cfgKey1); |
| 321 | |
| 322 | // Add another config, with two metrics, one with activation |
| 323 | StatsdConfig config2; |
| 324 | config2.set_id(12342); |
| 325 | config2.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root. |
| 326 | *config2.add_atom_matcher() = wakelockAcquireMatcher; |
| 327 | |
| 328 | long metricId3 = 1234561; |
| 329 | long metricId4 = 1234562; |
| 330 | |
| 331 | auto countMetric3 = config2.add_count_metric(); |
| 332 | countMetric3->set_id(metricId3); |
| 333 | countMetric3->set_what(wakelockAcquireMatcher.id()); |
| 334 | countMetric3->set_bucket(FIVE_MINUTES); |
| 335 | |
| 336 | auto countMetric4 = config2.add_count_metric(); |
| 337 | countMetric4->set_id(metricId4); |
| 338 | countMetric4->set_what(wakelockAcquireMatcher.id()); |
| 339 | countMetric4->set_bucket(FIVE_MINUTES); |
| 340 | |
| 341 | auto metric3Activation = config2.add_metric_activation(); |
| 342 | metric3Activation->set_metric_id(metricId3); |
| 343 | auto metric3ActivationTrigger = metric3Activation->add_event_activation(); |
| 344 | metric3ActivationTrigger->set_atom_matcher_id(wakelockAcquireMatcher.id()); |
| 345 | metric3ActivationTrigger->set_ttl_seconds(100); |
| 346 | |
| 347 | ConfigKey cfgKey2(uid, 12342); |
| 348 | |
| 349 | // Add another config, with two metrics, both with activations |
| 350 | StatsdConfig config3; |
| 351 | config3.set_id(12342); |
| 352 | config3.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root. |
| 353 | *config3.add_atom_matcher() = wakelockAcquireMatcher; |
| 354 | |
| 355 | long metricId5 = 1234565; |
| 356 | long metricId6 = 1234566; |
| 357 | auto countMetric5 = config3.add_count_metric(); |
| 358 | countMetric5->set_id(metricId5); |
| 359 | countMetric5->set_what(wakelockAcquireMatcher.id()); |
| 360 | countMetric5->set_bucket(FIVE_MINUTES); |
| 361 | |
| 362 | auto countMetric6 = config3.add_count_metric(); |
| 363 | countMetric6->set_id(metricId6); |
| 364 | countMetric6->set_what(wakelockAcquireMatcher.id()); |
| 365 | countMetric6->set_bucket(FIVE_MINUTES); |
| 366 | |
| 367 | auto metric5Activation = config3.add_metric_activation(); |
| 368 | metric5Activation->set_metric_id(metricId5); |
| 369 | auto metric5ActivationTrigger = metric5Activation->add_event_activation(); |
| 370 | metric5ActivationTrigger->set_atom_matcher_id(wakelockAcquireMatcher.id()); |
| 371 | metric5ActivationTrigger->set_ttl_seconds(100); |
| 372 | |
| 373 | auto metric6Activation = config3.add_metric_activation(); |
| 374 | metric6Activation->set_metric_id(metricId6); |
| 375 | auto metric6ActivationTrigger = metric6Activation->add_event_activation(); |
| 376 | metric6ActivationTrigger->set_atom_matcher_id(wakelockAcquireMatcher.id()); |
| 377 | metric6ActivationTrigger->set_ttl_seconds(200); |
| 378 | |
| 379 | ConfigKey cfgKey3(uid, 12343); |
| 380 | |
| 381 | processor->OnConfigUpdated(2, cfgKey2, config2); |
| 382 | processor->OnConfigUpdated(3, cfgKey3, config3); |
| 383 | |
| 384 | EXPECT_EQ(3, processor->mMetricsManagers.size()); |
| 385 | auto it = processor->mMetricsManagers.find(cfgKey1); |
| 386 | EXPECT_TRUE(it != processor->mMetricsManagers.end()); |
| 387 | auto& metricsManager1 = it->second; |
| 388 | EXPECT_TRUE(metricsManager1->isActive()); |
| 389 | |
| 390 | auto metricIt = metricsManager1->mAllMetricProducers.begin(); |
| 391 | for (; metricIt != metricsManager1->mAllMetricProducers.end(); metricIt++) { |
| 392 | if ((*metricIt)->getMetricId() == metricId1) { |
| 393 | break; |
| 394 | } |
| 395 | } |
| 396 | EXPECT_TRUE(metricIt != metricsManager1->mAllMetricProducers.end()); |
| 397 | auto& metricProducer1 = *metricIt; |
| 398 | EXPECT_TRUE(metricProducer1->isActive()); |
| 399 | |
| 400 | metricIt = metricsManager1->mAllMetricProducers.begin(); |
| 401 | for (; metricIt != metricsManager1->mAllMetricProducers.end(); metricIt++) { |
| 402 | if ((*metricIt)->getMetricId() == metricId2) { |
| 403 | break; |
| 404 | } |
| 405 | } |
| 406 | EXPECT_TRUE(metricIt != metricsManager1->mAllMetricProducers.end()); |
| 407 | auto& metricProducer2 = *metricIt; |
| 408 | EXPECT_TRUE(metricProducer2->isActive()); |
| 409 | |
| 410 | it = processor->mMetricsManagers.find(cfgKey2); |
| 411 | EXPECT_TRUE(it != processor->mMetricsManagers.end()); |
| 412 | auto& metricsManager2 = it->second; |
| 413 | EXPECT_TRUE(metricsManager2->isActive()); |
| 414 | |
| 415 | metricIt = metricsManager2->mAllMetricProducers.begin(); |
| 416 | for (; metricIt != metricsManager2->mAllMetricProducers.end(); metricIt++) { |
| 417 | if ((*metricIt)->getMetricId() == metricId3) { |
| 418 | break; |
| 419 | } |
| 420 | } |
| 421 | EXPECT_TRUE(metricIt != metricsManager2->mAllMetricProducers.end()); |
| 422 | auto& metricProducer3 = *metricIt; |
| 423 | EXPECT_FALSE(metricProducer3->isActive()); |
| 424 | |
| 425 | metricIt = metricsManager2->mAllMetricProducers.begin(); |
| 426 | for (; metricIt != metricsManager2->mAllMetricProducers.end(); metricIt++) { |
| 427 | if ((*metricIt)->getMetricId() == metricId4) { |
| 428 | break; |
| 429 | } |
| 430 | } |
| 431 | EXPECT_TRUE(metricIt != metricsManager2->mAllMetricProducers.end()); |
| 432 | auto& metricProducer4 = *metricIt; |
| 433 | EXPECT_TRUE(metricProducer4->isActive()); |
| 434 | |
| 435 | it = processor->mMetricsManagers.find(cfgKey3); |
| 436 | EXPECT_TRUE(it != processor->mMetricsManagers.end()); |
| 437 | auto& metricsManager3 = it->second; |
| 438 | EXPECT_FALSE(metricsManager3->isActive()); |
| 439 | |
| 440 | metricIt = metricsManager3->mAllMetricProducers.begin(); |
| 441 | for (; metricIt != metricsManager2->mAllMetricProducers.end(); metricIt++) { |
| 442 | if ((*metricIt)->getMetricId() == metricId5) { |
| 443 | break; |
| 444 | } |
| 445 | } |
| 446 | EXPECT_TRUE(metricIt != metricsManager3->mAllMetricProducers.end()); |
| 447 | auto& metricProducer5 = *metricIt; |
| 448 | EXPECT_FALSE(metricProducer5->isActive()); |
| 449 | |
| 450 | metricIt = metricsManager3->mAllMetricProducers.begin(); |
| 451 | for (; metricIt != metricsManager3->mAllMetricProducers.end(); metricIt++) { |
| 452 | if ((*metricIt)->getMetricId() == metricId6) { |
| 453 | break; |
| 454 | } |
| 455 | } |
| 456 | EXPECT_TRUE(metricIt != metricsManager3->mAllMetricProducers.end()); |
| 457 | auto& metricProducer6 = *metricIt; |
| 458 | EXPECT_FALSE(metricProducer6->isActive()); |
| 459 | |
| 460 | std::vector<AttributionNodeInternal> attributions1 = {CreateAttribution(111, "App1")}; |
| 461 | auto event = CreateAcquireWakelockEvent(attributions1, "wl1", 100 + timeBase1); |
| 462 | processor->OnLogEvent(event.get()); |
| 463 | |
| 464 | int64_t shutDownTime = timeBase1 + 100 * NS_PER_SEC; |
| 465 | EXPECT_TRUE(metricProducer3->isActive()); |
| 466 | int64_t ttl3 = metricProducer3->getRemainingTtlNs(shutDownTime); |
| 467 | EXPECT_EQ(100, ttl3); |
| 468 | EXPECT_TRUE(metricProducer5->isActive()); |
| 469 | int64_t ttl5 = metricProducer5->getRemainingTtlNs(shutDownTime); |
| 470 | EXPECT_EQ(100, ttl5); |
| 471 | EXPECT_TRUE(metricProducer6->isActive()); |
| 472 | int64_t ttl6 = metricProducer6->getRemainingTtlNs(shutDownTime); |
| 473 | EXPECT_EQ(100 + 100 * NS_PER_SEC, ttl6); |
| 474 | |
| 475 | processor->WriteMetricsActivationToDisk(timeBase1 + 100 * NS_PER_SEC); |
| 476 | |
| 477 | long timeBase2 = 1000; |
| 478 | sp<StatsLogProcessor> processor2 = |
| 479 | CreateStatsLogProcessor(timeBase2, timeBase2, config1, cfgKey1); |
| 480 | processor2->OnConfigUpdated(timeBase2, cfgKey2, config2); |
| 481 | processor2->OnConfigUpdated(timeBase2, cfgKey3, config3); |
| 482 | |
| 483 | EXPECT_EQ(3, processor2->mMetricsManagers.size()); |
| 484 | it = processor2->mMetricsManagers.find(cfgKey1); |
| 485 | EXPECT_TRUE(it != processor2->mMetricsManagers.end()); |
| 486 | auto& metricsManager1001 = it->second; |
| 487 | EXPECT_TRUE(metricsManager1001->isActive()); |
| 488 | |
| 489 | metricIt = metricsManager1001->mAllMetricProducers.begin(); |
| 490 | for (; metricIt != metricsManager1001->mAllMetricProducers.end(); metricIt++) { |
| 491 | if ((*metricIt)->getMetricId() == metricId1) { |
| 492 | break; |
| 493 | } |
| 494 | } |
| 495 | EXPECT_TRUE(metricIt != metricsManager1001->mAllMetricProducers.end()); |
| 496 | auto& metricProducer1001 = *metricIt; |
| 497 | EXPECT_TRUE(metricProducer1001->isActive()); |
| 498 | |
| 499 | metricIt = metricsManager1001->mAllMetricProducers.begin(); |
| 500 | for (; metricIt != metricsManager1001->mAllMetricProducers.end(); metricIt++) { |
| 501 | if ((*metricIt)->getMetricId() == metricId2) { |
| 502 | break; |
| 503 | } |
| 504 | } |
| 505 | EXPECT_TRUE(metricIt != metricsManager1001->mAllMetricProducers.end()); |
| 506 | auto& metricProducer1002 = *metricIt; |
| 507 | EXPECT_TRUE(metricProducer1002->isActive()); |
| 508 | |
| 509 | it = processor2->mMetricsManagers.find(cfgKey2); |
| 510 | EXPECT_TRUE(it != processor2->mMetricsManagers.end()); |
| 511 | auto& metricsManager1002 = it->second; |
| 512 | EXPECT_TRUE(metricsManager1002->isActive()); |
| 513 | |
| 514 | metricIt = metricsManager1002->mAllMetricProducers.begin(); |
| 515 | for (; metricIt != metricsManager1002->mAllMetricProducers.end(); metricIt++) { |
| 516 | if ((*metricIt)->getMetricId() == metricId3) { |
| 517 | break; |
| 518 | } |
| 519 | } |
| 520 | EXPECT_TRUE(metricIt != metricsManager1002->mAllMetricProducers.end()); |
| 521 | auto& metricProducer1003 = *metricIt; |
| 522 | EXPECT_FALSE(metricProducer1003->isActive()); |
| 523 | |
| 524 | metricIt = metricsManager1002->mAllMetricProducers.begin(); |
| 525 | for (; metricIt != metricsManager1002->mAllMetricProducers.end(); metricIt++) { |
| 526 | if ((*metricIt)->getMetricId() == metricId4) { |
| 527 | break; |
| 528 | } |
| 529 | } |
| 530 | EXPECT_TRUE(metricIt != metricsManager1002->mAllMetricProducers.end()); |
| 531 | auto& metricProducer1004 = *metricIt; |
| 532 | EXPECT_TRUE(metricProducer1004->isActive()); |
| 533 | |
| 534 | it = processor2->mMetricsManagers.find(cfgKey3); |
| 535 | EXPECT_TRUE(it != processor2->mMetricsManagers.end()); |
| 536 | auto& metricsManager1003 = it->second; |
| 537 | EXPECT_FALSE(metricsManager1003->isActive()); |
| 538 | EXPECT_EQ(2, metricsManager1003->mAllMetricProducers.size()); |
| 539 | |
| 540 | metricIt = metricsManager1003->mAllMetricProducers.begin(); |
| 541 | for (; metricIt != metricsManager1002->mAllMetricProducers.end(); metricIt++) { |
| 542 | if ((*metricIt)->getMetricId() == metricId5) { |
| 543 | break; |
| 544 | } |
| 545 | } |
| 546 | EXPECT_TRUE(metricIt != metricsManager1003->mAllMetricProducers.end()); |
| 547 | auto& metricProducer1005 = *metricIt; |
| 548 | EXPECT_FALSE(metricProducer1005->isActive()); |
| 549 | |
| 550 | metricIt = metricsManager1003->mAllMetricProducers.begin(); |
| 551 | for (; metricIt != metricsManager1003->mAllMetricProducers.end(); metricIt++) { |
| 552 | if ((*metricIt)->getMetricId() == metricId6) { |
| 553 | break; |
| 554 | } |
| 555 | } |
| 556 | EXPECT_TRUE(metricIt != metricsManager1003->mAllMetricProducers.end()); |
| 557 | auto& metricProducer1006 = *metricIt; |
| 558 | EXPECT_FALSE(metricProducer1006->isActive()); |
| 559 | |
| 560 | EXPECT_FALSE(metricProducer1003->isActive()); |
| 561 | const auto& activation1003 = metricProducer1003->mEventActivationMap.begin()->second; |
| 562 | EXPECT_EQ(100 * NS_PER_SEC, activation1003.ttl_ns); |
| 563 | EXPECT_EQ(0, activation1003.activation_ns); |
| 564 | EXPECT_FALSE(metricProducer1005->isActive()); |
| 565 | const auto& activation1005 = metricProducer1005->mEventActivationMap.begin()->second; |
| 566 | EXPECT_EQ(100 * NS_PER_SEC, activation1005.ttl_ns); |
| 567 | EXPECT_EQ(0, activation1005.activation_ns); |
| 568 | EXPECT_FALSE(metricProducer1006->isActive()); |
| 569 | const auto& activation1006 = metricProducer1006->mEventActivationMap.begin()->second; |
| 570 | EXPECT_EQ(200 * NS_PER_SEC, activation1006.ttl_ns); |
| 571 | EXPECT_EQ(0, activation1006.activation_ns); |
| 572 | |
| 573 | processor2->LoadMetricsActivationFromDisk(); |
| 574 | |
| 575 | EXPECT_TRUE(metricProducer1003->isActive()); |
| 576 | EXPECT_EQ(timeBase2 + ttl3 - activation1003.ttl_ns, activation1003.activation_ns); |
| 577 | EXPECT_TRUE(metricProducer1005->isActive()); |
| 578 | EXPECT_EQ(timeBase2 + ttl5 - activation1005.ttl_ns, activation1005.activation_ns); |
| 579 | EXPECT_TRUE(metricProducer1006->isActive()); |
| 580 | EXPECT_EQ(timeBase2 + ttl6 - activation1006.ttl_ns, activation1003.activation_ns); |
| 581 | } |
| 582 | |
| Chenjie Yu | a9a310e | 2019-02-06 13:40:10 -0800 | [diff] [blame] | 583 | TEST(StatsLogProcessorTest, TestActivationOnBoot) { |
| 584 | int uid = 1111; |
| 585 | |
| 586 | // Setup a simple config, no activation |
| 587 | StatsdConfig config1; |
| 588 | config1.set_id(12341); |
| 589 | config1.add_allowed_log_source("AID_ROOT"); // LogEvent defaults to UID of root. |
| 590 | auto wakelockAcquireMatcher = CreateAcquireWakelockAtomMatcher(); |
| 591 | *config1.add_atom_matcher() = wakelockAcquireMatcher; |
| 592 | |
| 593 | long metricId1 = 1234561; |
| 594 | long metricId2 = 1234562; |
| 595 | auto countMetric1 = config1.add_count_metric(); |
| 596 | countMetric1->set_id(metricId1); |
| 597 | countMetric1->set_what(wakelockAcquireMatcher.id()); |
| 598 | countMetric1->set_bucket(FIVE_MINUTES); |
| 599 | |
| 600 | auto countMetric2 = config1.add_count_metric(); |
| 601 | countMetric2->set_id(metricId2); |
| 602 | countMetric2->set_what(wakelockAcquireMatcher.id()); |
| 603 | countMetric2->set_bucket(FIVE_MINUTES); |
| 604 | |
| 605 | auto metric1Activation = config1.add_metric_activation(); |
| 606 | metric1Activation->set_metric_id(metricId1); |
| 607 | metric1Activation->set_activation_type(MetricActivation::ACTIVATE_ON_BOOT); |
| 608 | auto metric1ActivationTrigger = metric1Activation->add_event_activation(); |
| 609 | metric1ActivationTrigger->set_atom_matcher_id(wakelockAcquireMatcher.id()); |
| 610 | metric1ActivationTrigger->set_ttl_seconds(100); |
| 611 | |
| 612 | ConfigKey cfgKey1(uid, 12341); |
| 613 | long timeBase1 = 1; |
| 614 | sp<StatsLogProcessor> processor = |
| 615 | CreateStatsLogProcessor(timeBase1, timeBase1, config1, cfgKey1); |
| 616 | |
| 617 | EXPECT_EQ(1, processor->mMetricsManagers.size()); |
| 618 | auto it = processor->mMetricsManagers.find(cfgKey1); |
| 619 | EXPECT_TRUE(it != processor->mMetricsManagers.end()); |
| 620 | auto& metricsManager1 = it->second; |
| 621 | EXPECT_TRUE(metricsManager1->isActive()); |
| 622 | |
| 623 | auto metricIt = metricsManager1->mAllMetricProducers.begin(); |
| 624 | for (; metricIt != metricsManager1->mAllMetricProducers.end(); metricIt++) { |
| 625 | if ((*metricIt)->getMetricId() == metricId1) { |
| 626 | break; |
| 627 | } |
| 628 | } |
| 629 | EXPECT_TRUE(metricIt != metricsManager1->mAllMetricProducers.end()); |
| 630 | auto& metricProducer1 = *metricIt; |
| 631 | EXPECT_FALSE(metricProducer1->isActive()); |
| 632 | |
| 633 | metricIt = metricsManager1->mAllMetricProducers.begin(); |
| 634 | for (; metricIt != metricsManager1->mAllMetricProducers.end(); metricIt++) { |
| 635 | if ((*metricIt)->getMetricId() == metricId2) { |
| 636 | break; |
| 637 | } |
| 638 | } |
| 639 | EXPECT_TRUE(metricIt != metricsManager1->mAllMetricProducers.end()); |
| 640 | auto& metricProducer2 = *metricIt; |
| 641 | EXPECT_TRUE(metricProducer2->isActive()); |
| 642 | |
| 643 | const auto& activation1 = metricProducer1->mEventActivationMap.begin()->second; |
| 644 | EXPECT_EQ(100 * NS_PER_SEC, activation1.ttl_ns); |
| 645 | EXPECT_EQ(0, activation1.activation_ns); |
| 646 | EXPECT_EQ(kNotActive, activation1.state); |
| 647 | |
| 648 | std::vector<AttributionNodeInternal> attributions1 = {CreateAttribution(111, "App1")}; |
| 649 | auto event = CreateAcquireWakelockEvent(attributions1, "wl1", 100 + timeBase1); |
| 650 | processor->OnLogEvent(event.get()); |
| 651 | |
| 652 | EXPECT_FALSE(metricProducer1->isActive()); |
| 653 | EXPECT_EQ(0, activation1.activation_ns); |
| 654 | EXPECT_EQ(kActiveOnBoot, activation1.state); |
| 655 | |
| 656 | int64_t shutDownTime = timeBase1 + 100 * NS_PER_SEC; |
| 657 | |
| 658 | processor->WriteMetricsActivationToDisk(shutDownTime); |
| 659 | EXPECT_TRUE(metricProducer1->isActive()); |
| 660 | int64_t ttl1 = metricProducer1->getRemainingTtlNs(shutDownTime); |
| 661 | EXPECT_EQ(100 * NS_PER_SEC, ttl1); |
| 662 | |
| 663 | long timeBase2 = 1000; |
| 664 | sp<StatsLogProcessor> processor2 = |
| 665 | CreateStatsLogProcessor(timeBase2, timeBase2, config1, cfgKey1); |
| 666 | |
| 667 | EXPECT_EQ(1, processor2->mMetricsManagers.size()); |
| 668 | it = processor2->mMetricsManagers.find(cfgKey1); |
| 669 | EXPECT_TRUE(it != processor2->mMetricsManagers.end()); |
| 670 | auto& metricsManager1001 = it->second; |
| 671 | EXPECT_TRUE(metricsManager1001->isActive()); |
| 672 | |
| 673 | metricIt = metricsManager1001->mAllMetricProducers.begin(); |
| 674 | for (; metricIt != metricsManager1001->mAllMetricProducers.end(); metricIt++) { |
| 675 | if ((*metricIt)->getMetricId() == metricId1) { |
| 676 | break; |
| 677 | } |
| 678 | } |
| 679 | EXPECT_TRUE(metricIt != metricsManager1001->mAllMetricProducers.end()); |
| 680 | auto& metricProducer1001 = *metricIt; |
| 681 | EXPECT_FALSE(metricProducer1001->isActive()); |
| 682 | |
| 683 | metricIt = metricsManager1001->mAllMetricProducers.begin(); |
| 684 | for (; metricIt != metricsManager1001->mAllMetricProducers.end(); metricIt++) { |
| 685 | if ((*metricIt)->getMetricId() == metricId2) { |
| 686 | break; |
| 687 | } |
| 688 | } |
| 689 | EXPECT_TRUE(metricIt != metricsManager1001->mAllMetricProducers.end()); |
| 690 | auto& metricProducer1002 = *metricIt; |
| 691 | EXPECT_TRUE(metricProducer1002->isActive()); |
| 692 | |
| 693 | const auto& activation1001 = metricProducer1001->mEventActivationMap.begin()->second; |
| 694 | EXPECT_EQ(100 * NS_PER_SEC, activation1001.ttl_ns); |
| 695 | EXPECT_EQ(0, activation1001.activation_ns); |
| 696 | EXPECT_EQ(kNotActive, activation1001.state); |
| 697 | |
| 698 | processor2->LoadMetricsActivationFromDisk(); |
| 699 | |
| 700 | EXPECT_TRUE(metricProducer1001->isActive()); |
| 701 | EXPECT_EQ(timeBase2 + ttl1 - activation1001.ttl_ns, activation1001.activation_ns); |
| 702 | } |
| 703 | |
| David Chen | d9269e2 | 2017-12-05 13:43:51 -0800 | [diff] [blame] | 704 | #else |
| 705 | GTEST_LOG_(INFO) << "This test does nothing.\n"; |
| 706 | #endif |
| 707 | |
| 708 | } // namespace statsd |
| 709 | } // namespace os |
| Yao Chen | 288c600 | 2017-12-12 13:43:18 -0800 | [diff] [blame] | 710 | } // namespace android |