blob: 721d02c7a84b8a77119935dd3a29b4474389b4f9 [file] [log] [blame]
Chenjie Yub3dda412017-10-24 13:41:59 -07001/*
2 * Copyright (C) 2017 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#define DEBUG true // STOPSHIP if true
18#include "Log.h"
19
20#include "ValueMetricProducer.h"
Yao Chenb3561512017-11-21 18:07:17 -080021#include "guardrail/StatsdStats.h"
Chenjie Yub3dda412017-10-24 13:41:59 -070022
23#include <cutils/log.h>
24#include <limits.h>
25#include <stdlib.h>
26
yrob0378b02017-11-09 20:36:25 -080027using android::util::FIELD_COUNT_REPEATED;
yro2b0f8862017-11-06 14:27:31 -080028using android::util::FIELD_TYPE_BOOL;
29using android::util::FIELD_TYPE_FLOAT;
30using android::util::FIELD_TYPE_INT32;
31using android::util::FIELD_TYPE_INT64;
32using android::util::FIELD_TYPE_MESSAGE;
Yangster-macd1815dc2017-11-13 21:43:15 -080033using android::util::FIELD_TYPE_STRING;
yro2b0f8862017-11-06 14:27:31 -080034using android::util::ProtoOutputStream;
Chenjie Yub3dda412017-10-24 13:41:59 -070035using std::list;
Chenjie Yu6736c892017-11-09 10:50:09 -080036using std::make_pair;
Chenjie Yub3dda412017-10-24 13:41:59 -070037using std::make_shared;
Yao Chen93fe3a32017-11-02 13:52:59 -070038using std::map;
Chenjie Yub3dda412017-10-24 13:41:59 -070039using std::shared_ptr;
40using std::unique_ptr;
Yao Chen93fe3a32017-11-02 13:52:59 -070041using std::unordered_map;
Chenjie Yub3dda412017-10-24 13:41:59 -070042
43namespace android {
44namespace os {
45namespace statsd {
46
yro2b0f8862017-11-06 14:27:31 -080047// for StatsLogReport
Yangster-macd1815dc2017-11-13 21:43:15 -080048const int FIELD_ID_NAME = 1;
yro2b0f8862017-11-06 14:27:31 -080049const int FIELD_ID_START_REPORT_NANOS = 2;
50const int FIELD_ID_END_REPORT_NANOS = 3;
51const int FIELD_ID_VALUE_METRICS = 7;
52// for ValueMetricDataWrapper
53const int FIELD_ID_DATA = 1;
54// for ValueMetricData
55const int FIELD_ID_DIMENSION = 1;
56const int FIELD_ID_BUCKET_INFO = 2;
57// for KeyValuePair
58const int FIELD_ID_KEY = 1;
59const int FIELD_ID_VALUE_STR = 2;
60const int FIELD_ID_VALUE_INT = 3;
61const int FIELD_ID_VALUE_BOOL = 4;
62const int FIELD_ID_VALUE_FLOAT = 5;
63// for ValueBucketInfo
64const int FIELD_ID_START_BUCKET_NANOS = 1;
65const int FIELD_ID_END_BUCKET_NANOS = 2;
66const int FIELD_ID_VALUE = 3;
67
Chenjie Yu6736c892017-11-09 10:50:09 -080068static const uint64_t kDefaultBucketSizeMillis = 60 * 60 * 1000L;
69
Chenjie Yub3dda412017-10-24 13:41:59 -070070// ValueMetric has a minimum bucket size of 10min so that we don't pull too frequently
Yao Chenb3561512017-11-21 18:07:17 -080071ValueMetricProducer::ValueMetricProducer(const ConfigKey& key, const ValueMetric& metric,
72 const int conditionIndex,
Yao Chen93fe3a32017-11-02 13:52:59 -070073 const sp<ConditionWizard>& wizard, const int pullTagId,
Chenjie Yu6736c892017-11-09 10:50:09 -080074 const uint64_t startTimeNs,
75 shared_ptr<StatsPullerManager> statsPullerManager)
Yao Chenb3561512017-11-21 18:07:17 -080076 : MetricProducer(key, startTimeNs, conditionIndex, wizard),
Chenjie Yu6736c892017-11-09 10:50:09 -080077 mMetric(metric),
78 mStatsPullerManager(statsPullerManager),
79 mPullTagId(pullTagId) {
Yao Chen93fe3a32017-11-02 13:52:59 -070080 // TODO: valuemetric for pushed events may need unlimited bucket length
Chenjie Yu6736c892017-11-09 10:50:09 -080081 if (metric.has_bucket() && metric.bucket().has_bucket_size_millis()) {
82 mBucketSizeNs = mMetric.bucket().bucket_size_millis() * 1000 * 1000;
83 } else {
84 mBucketSizeNs = kDefaultBucketSizeMillis * 1000 * 1000;
85 }
Chenjie Yub3dda412017-10-24 13:41:59 -070086
Yao Chen93fe3a32017-11-02 13:52:59 -070087 mDimension.insert(mDimension.begin(), metric.dimension().begin(), metric.dimension().end());
Chenjie Yub3dda412017-10-24 13:41:59 -070088
Yao Chen93fe3a32017-11-02 13:52:59 -070089 if (metric.links().size() > 0) {
90 mConditionLinks.insert(mConditionLinks.begin(), metric.links().begin(),
91 metric.links().end());
92 mConditionSliced = true;
93 }
Chenjie Yub3dda412017-10-24 13:41:59 -070094
Yao Chen93fe3a32017-11-02 13:52:59 -070095 if (!metric.has_condition() && mPullTagId != -1) {
Chenjie Yu6736c892017-11-09 10:50:09 -080096 VLOG("Setting up periodic pulling for %d", mPullTagId);
97 mStatsPullerManager->RegisterReceiver(mPullTagId, this,
98 metric.bucket().bucket_size_millis());
Yao Chen93fe3a32017-11-02 13:52:59 -070099 }
Yangster-macd1815dc2017-11-13 21:43:15 -0800100 VLOG("value metric %s created. bucket size %lld start_time: %lld", metric.name().c_str(),
Yao Chen93fe3a32017-11-02 13:52:59 -0700101 (long long)mBucketSizeNs, (long long)mStartTimeNs);
Chenjie Yub3dda412017-10-24 13:41:59 -0700102}
103
Chenjie Yu6736c892017-11-09 10:50:09 -0800104// for testing
Yao Chenb3561512017-11-21 18:07:17 -0800105ValueMetricProducer::ValueMetricProducer(const ConfigKey& key, const ValueMetric& metric,
106 const int conditionIndex,
Chenjie Yu6736c892017-11-09 10:50:09 -0800107 const sp<ConditionWizard>& wizard, const int pullTagId,
108 const uint64_t startTimeNs)
Yao Chenb3561512017-11-21 18:07:17 -0800109 : ValueMetricProducer(key, metric, conditionIndex, wizard, pullTagId, startTimeNs,
Chenjie Yu6736c892017-11-09 10:50:09 -0800110 make_shared<StatsPullerManager>()) {
111}
112
Chenjie Yub3dda412017-10-24 13:41:59 -0700113ValueMetricProducer::~ValueMetricProducer() {
Yao Chen93fe3a32017-11-02 13:52:59 -0700114 VLOG("~ValueMetricProducer() called");
Chenjie Yu6736c892017-11-09 10:50:09 -0800115 if (mPullTagId != -1) {
116 mStatsPullerManager->UnRegisterReceiver(mPullTagId, this);
117 }
Chenjie Yub3dda412017-10-24 13:41:59 -0700118}
119
Yangsterf2bee6f2017-11-29 12:01:05 -0800120void ValueMetricProducer::onSlicedConditionMayChangeLocked(const uint64_t eventTime) {
Yangster-macd1815dc2017-11-13 21:43:15 -0800121 VLOG("Metric %s onSlicedConditionMayChange", mMetric.name().c_str());
Chenjie Yub3dda412017-10-24 13:41:59 -0700122}
123
Yao Chen288c6002017-12-12 13:43:18 -0800124void ValueMetricProducer::onDumpReportLocked(const uint64_t dumpTimeNs,
125 ProtoOutputStream* protoOutput) {
Yao Chen6a8c7992017-11-29 20:02:07 +0000126 VLOG("metric %s dump report now...", mMetric.name().c_str());
Yao Chen288c6002017-12-12 13:43:18 -0800127 flushIfNeededLocked(dumpTimeNs);
128 protoOutput->write(FIELD_TYPE_STRING | FIELD_ID_NAME, mMetric.name());
129 protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_START_REPORT_NANOS, (long long)mStartTimeNs);
130 long long protoToken = protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_ID_VALUE_METRICS);
Yao Chen6a8c7992017-11-29 20:02:07 +0000131
Yao Chen93fe3a32017-11-02 13:52:59 -0700132 for (const auto& pair : mPastBuckets) {
133 const HashableDimensionKey& hashableKey = pair.first;
yro2b0f8862017-11-06 14:27:31 -0800134 VLOG(" dimension key %s", hashableKey.c_str());
Yao Chen93fe3a32017-11-02 13:52:59 -0700135 auto it = mDimensionKeyMap.find(hashableKey);
136 if (it == mDimensionKeyMap.end()) {
137 ALOGE("Dimension key %s not found?!?! skip...", hashableKey.c_str());
138 continue;
139 }
yrob0378b02017-11-09 20:36:25 -0800140 long long wrapperToken =
Yao Chen288c6002017-12-12 13:43:18 -0800141 protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DATA);
Chenjie Yub3dda412017-10-24 13:41:59 -0700142
yro2b0f8862017-11-06 14:27:31 -0800143 // First fill dimension (KeyValuePairs).
144 for (const auto& kv : it->second) {
Yao Chen288c6002017-12-12 13:43:18 -0800145 long long dimensionToken = protoOutput->start(
146 FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_DIMENSION);
147 protoOutput->write(FIELD_TYPE_INT32 | FIELD_ID_KEY, kv.key());
yro2b0f8862017-11-06 14:27:31 -0800148 if (kv.has_value_str()) {
Yao Chen288c6002017-12-12 13:43:18 -0800149 protoOutput->write(FIELD_TYPE_STRING | FIELD_ID_VALUE_STR, kv.value_str());
yro2b0f8862017-11-06 14:27:31 -0800150 } else if (kv.has_value_int()) {
Yao Chen288c6002017-12-12 13:43:18 -0800151 protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_VALUE_INT, kv.value_int());
yro2b0f8862017-11-06 14:27:31 -0800152 } else if (kv.has_value_bool()) {
Yao Chen288c6002017-12-12 13:43:18 -0800153 protoOutput->write(FIELD_TYPE_BOOL | FIELD_ID_VALUE_BOOL, kv.value_bool());
yro2b0f8862017-11-06 14:27:31 -0800154 } else if (kv.has_value_float()) {
Yao Chen288c6002017-12-12 13:43:18 -0800155 protoOutput->write(FIELD_TYPE_FLOAT | FIELD_ID_VALUE_FLOAT, kv.value_float());
yro2b0f8862017-11-06 14:27:31 -0800156 }
Yao Chen288c6002017-12-12 13:43:18 -0800157 protoOutput->end(dimensionToken);
yro2b0f8862017-11-06 14:27:31 -0800158 }
159
160 // Then fill bucket_info (ValueBucketInfo).
161 for (const auto& bucket : pair.second) {
Yao Chen288c6002017-12-12 13:43:18 -0800162 long long bucketInfoToken = protoOutput->start(
163 FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_BUCKET_INFO);
164 protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_START_BUCKET_NANOS,
165 (long long)bucket.mBucketStartNs);
166 protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_END_BUCKET_NANOS,
167 (long long)bucket.mBucketEndNs);
168 protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_VALUE, (long long)bucket.mValue);
169 protoOutput->end(bucketInfoToken);
yro2b0f8862017-11-06 14:27:31 -0800170 VLOG("\t bucket [%lld - %lld] count: %lld", (long long)bucket.mBucketStartNs,
171 (long long)bucket.mBucketEndNs, (long long)bucket.mValue);
172 }
Yao Chen288c6002017-12-12 13:43:18 -0800173 protoOutput->end(wrapperToken);
Chenjie Yub3dda412017-10-24 13:41:59 -0700174 }
Yao Chen288c6002017-12-12 13:43:18 -0800175 protoOutput->end(protoToken);
176 protoOutput->write(FIELD_TYPE_INT64 | FIELD_ID_END_REPORT_NANOS, (long long)dumpTimeNs);
yro2b0f8862017-11-06 14:27:31 -0800177
Yangster-macd1815dc2017-11-13 21:43:15 -0800178 VLOG("metric %s dump report now...", mMetric.name().c_str());
Yao Chen6a8c7992017-11-29 20:02:07 +0000179 mPastBuckets.clear();
Yao Chen288c6002017-12-12 13:43:18 -0800180 mStartTimeNs = mCurrentBucketStartTimeNs;
yro2b0f8862017-11-06 14:27:31 -0800181 // TODO: Clear mDimensionKeyMap once the report is dumped.
Chenjie Yub3dda412017-10-24 13:41:59 -0700182}
183
Yangsterf2bee6f2017-11-29 12:01:05 -0800184void ValueMetricProducer::onConditionChangedLocked(const bool condition, const uint64_t eventTime) {
Yao Chen6a8c7992017-11-29 20:02:07 +0000185 mCondition = condition;
Chenjie Yub3dda412017-10-24 13:41:59 -0700186
Yao Chen6a8c7992017-11-29 20:02:07 +0000187 if (mPullTagId != -1) {
Chenjie Yub3dda412017-10-24 13:41:59 -0700188 if (mCondition == true) {
Chenjie Yu6736c892017-11-09 10:50:09 -0800189 mStatsPullerManager->RegisterReceiver(mPullTagId, this,
190 mMetric.bucket().bucket_size_millis());
191 } else if (mCondition == false) {
192 mStatsPullerManager->UnRegisterReceiver(mPullTagId, this);
Chenjie Yub3dda412017-10-24 13:41:59 -0700193 }
Yangster8de69392017-11-27 13:48:29 -0800194
Yao Chen6a8c7992017-11-29 20:02:07 +0000195 vector<shared_ptr<LogEvent>> allData;
196 if (mStatsPullerManager->Pull(mPullTagId, &allData)) {
197 if (allData.size() == 0) {
198 return;
199 }
200 for (const auto& data : allData) {
Yangsterf2bee6f2017-11-29 12:01:05 -0800201 onMatchedLogEventLocked(0, *data, false);
Yao Chen6a8c7992017-11-29 20:02:07 +0000202 }
Yangsterf2bee6f2017-11-29 12:01:05 -0800203 flushIfNeededLocked(eventTime);
Yao Chen6a8c7992017-11-29 20:02:07 +0000204 }
Chenjie Yu5305e1d2017-10-31 13:49:36 -0700205 return;
Chenjie Yub3dda412017-10-24 13:41:59 -0700206 }
Chenjie Yub3dda412017-10-24 13:41:59 -0700207}
208
209void ValueMetricProducer::onDataPulled(const std::vector<std::shared_ptr<LogEvent>>& allData) {
Yangsterf2bee6f2017-11-29 12:01:05 -0800210 std::lock_guard<std::mutex> lock(mMutex);
211
Yao Chen6a8c7992017-11-29 20:02:07 +0000212 if (mCondition == true || !mMetric.has_condition()) {
Chenjie Yub3dda412017-10-24 13:41:59 -0700213 if (allData.size() == 0) {
214 return;
215 }
216 uint64_t eventTime = allData.at(0)->GetTimestampNs();
Chenjie Yu6736c892017-11-09 10:50:09 -0800217 // alarm is not accurate and might drift.
218 if (eventTime > mCurrentBucketStartTimeNs + mBucketSizeNs * 3 / 2) {
Yangsterf2bee6f2017-11-29 12:01:05 -0800219 flushIfNeededLocked(eventTime);
Chenjie Yu6736c892017-11-09 10:50:09 -0800220 }
Chenjie Yub3dda412017-10-24 13:41:59 -0700221 for (const auto& data : allData) {
Yangsterf2bee6f2017-11-29 12:01:05 -0800222 onMatchedLogEventLocked(0, *data, true);
Chenjie Yub3dda412017-10-24 13:41:59 -0700223 }
Yangsterf2bee6f2017-11-29 12:01:05 -0800224 flushIfNeededLocked(eventTime);
Chenjie Yub3dda412017-10-24 13:41:59 -0700225 }
226}
227
Yangsterf2bee6f2017-11-29 12:01:05 -0800228bool ValueMetricProducer::hitGuardRailLocked(const HashableDimensionKey& newKey) {
Yao Chenb3561512017-11-21 18:07:17 -0800229 // ===========GuardRail==============
230 // 1. Report the tuple count if the tuple count > soft limit
231 if (mCurrentSlicedBucket.find(newKey) != mCurrentSlicedBucket.end()) {
232 return false;
233 }
234 if (mCurrentSlicedBucket.size() > StatsdStats::kDimensionKeySizeSoftLimit - 1) {
235 size_t newTupleCount = mCurrentSlicedBucket.size() + 1;
236 StatsdStats::getInstance().noteMetricDimensionSize(mConfigKey, mMetric.name(),
237 newTupleCount);
238 // 2. Don't add more tuples, we are above the allowed threshold. Drop the data.
239 if (newTupleCount > StatsdStats::kDimensionKeySizeHardLimit) {
240 ALOGE("ValueMetric %s dropping data for dimension key %s", mMetric.name().c_str(),
241 newKey.c_str());
242 return true;
243 }
244 }
245
246 return false;
247}
248
Yangsterf2bee6f2017-11-29 12:01:05 -0800249void ValueMetricProducer::onMatchedLogEventInternalLocked(
Yangster8de69392017-11-27 13:48:29 -0800250 const size_t matcherIndex, const HashableDimensionKey& eventKey,
251 const map<string, HashableDimensionKey>& conditionKey, bool condition,
252 const LogEvent& event, bool scheduledPull) {
253 uint64_t eventTimeNs = event.GetTimestampNs();
Yao Chen6a8c7992017-11-29 20:02:07 +0000254 if (eventTimeNs < mCurrentBucketStartTimeNs) {
255 VLOG("Skip event due to late arrival: %lld vs %lld", (long long)eventTimeNs,
256 (long long)mCurrentBucketStartTimeNs);
257 return;
258 }
259
Yangsterf2bee6f2017-11-29 12:01:05 -0800260 if (hitGuardRailLocked(eventKey)) {
Yangster8de69392017-11-27 13:48:29 -0800261 return;
262 }
Yao Chen6a8c7992017-11-29 20:02:07 +0000263 Interval& interval = mCurrentSlicedBucket[eventKey];
264
265 long value = get_value(event);
266
Yangster8de69392017-11-27 13:48:29 -0800267 if (mPullTagId != -1) {
Yao Chen6a8c7992017-11-29 20:02:07 +0000268 if (scheduledPull) {
269 // scheduled pull always sets beginning of current bucket and end
270 // of next bucket
271 if (interval.raw.size() > 0) {
272 interval.raw.back().second = value;
273 } else {
274 interval.raw.push_back(make_pair(value, value));
275 }
276 Interval& nextInterval = mNextSlicedBucket[eventKey];
277 if (nextInterval.raw.size() == 0) {
278 nextInterval.raw.push_back(make_pair(value, 0));
279 } else {
280 nextInterval.raw.front().first = value;
281 }
282 } else {
283 if (mCondition == true) {
284 interval.raw.push_back(make_pair(value, 0));
285 } else {
286 if (interval.raw.size() != 0) {
287 interval.raw.back().second = value;
288 } else {
289 interval.tainted = true;
290 VLOG("Data on condition true missing!");
291 }
292 }
293 }
Yangster8de69392017-11-27 13:48:29 -0800294 } else {
Yangsterf2bee6f2017-11-29 12:01:05 -0800295 flushIfNeededLocked(eventTimeNs);
Yao Chen6a8c7992017-11-29 20:02:07 +0000296 interval.raw.push_back(make_pair(value, 0));
Yangster8de69392017-11-27 13:48:29 -0800297 }
298}
299
Yao Chen6a8c7992017-11-29 20:02:07 +0000300long ValueMetricProducer::get_value(const LogEvent& event) {
Yao Chen93fe3a32017-11-02 13:52:59 -0700301 status_t err = NO_ERROR;
302 long val = event.GetLong(mMetric.value_field(), &err);
303 if (err == NO_ERROR) {
304 return val;
305 } else {
Chenjie Yu6736c892017-11-09 10:50:09 -0800306 VLOG("Can't find value in message. %s", event.ToString().c_str());
Yao Chen93fe3a32017-11-02 13:52:59 -0700307 return 0;
308 }
Chenjie Yub3dda412017-10-24 13:41:59 -0700309}
310
Yangsterf2bee6f2017-11-29 12:01:05 -0800311void ValueMetricProducer::flushIfNeededLocked(const uint64_t& eventTimeNs) {
Chenjie Yub3dda412017-10-24 13:41:59 -0700312 if (mCurrentBucketStartTimeNs + mBucketSizeNs > eventTimeNs) {
313 VLOG("eventTime is %lld, less than next bucket start time %lld", (long long)eventTimeNs,
314 (long long)(mCurrentBucketStartTimeNs + mBucketSizeNs));
315 return;
316 }
Chenjie Yub3dda412017-10-24 13:41:59 -0700317 VLOG("finalizing bucket for %ld, dumping %d slices", (long)mCurrentBucketStartTimeNs,
318 (int)mCurrentSlicedBucket.size());
yro2b0f8862017-11-06 14:27:31 -0800319 ValueBucket info;
320 info.mBucketStartNs = mCurrentBucketStartTimeNs;
321 info.mBucketEndNs = mCurrentBucketStartTimeNs + mBucketSizeNs;
Yangster-mace2cd6d52017-11-09 20:38:30 -0800322 info.mBucketNum = mCurrentBucketNum;
Chenjie Yub3dda412017-10-24 13:41:59 -0700323
Chenjie Yu6736c892017-11-09 10:50:09 -0800324 int tainted = 0;
Chenjie Yub3dda412017-10-24 13:41:59 -0700325 for (const auto& slice : mCurrentSlicedBucket) {
Yao Chen93fe3a32017-11-02 13:52:59 -0700326 long value = 0;
Chenjie Yu6736c892017-11-09 10:50:09 -0800327 if (mPullTagId != -1) {
328 for (const auto& pair : slice.second.raw) {
329 value += (pair.second - pair.first);
330 }
331 } else {
332 for (const auto& pair : slice.second.raw) {
333 value += pair.first;
334 }
Yao Chen93fe3a32017-11-02 13:52:59 -0700335 }
Chenjie Yu6736c892017-11-09 10:50:09 -0800336 tainted += slice.second.tainted;
yro2b0f8862017-11-06 14:27:31 -0800337 info.mValue = value;
Chenjie Yu6736c892017-11-09 10:50:09 -0800338 VLOG(" %s, %ld, %d", slice.first.c_str(), value, tainted);
Yao Chen93fe3a32017-11-02 13:52:59 -0700339 // it will auto create new vector of ValuebucketInfo if the key is not found.
340 auto& bucketList = mPastBuckets[slice.first];
341 bucketList.push_back(info);
Chenjie Yub3dda412017-10-24 13:41:59 -0700342 }
343
344 // Reset counters
345 mCurrentSlicedBucket.swap(mNextSlicedBucket);
346 mNextSlicedBucket.clear();
Yangster-mace2cd6d52017-11-09 20:38:30 -0800347
Chenjie Yub3dda412017-10-24 13:41:59 -0700348 int64_t numBucketsForward = (eventTimeNs - mCurrentBucketStartTimeNs) / mBucketSizeNs;
Yangster-mace2cd6d52017-11-09 20:38:30 -0800349 mCurrentBucketStartTimeNs = mCurrentBucketStartTimeNs + numBucketsForward * mBucketSizeNs;
350 mCurrentBucketNum += numBucketsForward;
351
Yao Chen93fe3a32017-11-02 13:52:59 -0700352 if (numBucketsForward > 1) {
Chenjie Yub3dda412017-10-24 13:41:59 -0700353 VLOG("Skipping forward %lld buckets", (long long)numBucketsForward);
354 }
Yangster-macd1815dc2017-11-13 21:43:15 -0800355 VLOG("metric %s: new bucket start time: %lld", mMetric.name().c_str(),
Chenjie Yub3dda412017-10-24 13:41:59 -0700356 (long long)mCurrentBucketStartTimeNs);
357}
358
Yangsterf2bee6f2017-11-29 12:01:05 -0800359size_t ValueMetricProducer::byteSizeLocked() const {
Yangster-mace2cd6d52017-11-09 20:38:30 -0800360 size_t totalSize = 0;
361 for (const auto& pair : mPastBuckets) {
362 totalSize += pair.second.size() * kBucketSize;
363 }
364 return totalSize;
yro2b0f8862017-11-06 14:27:31 -0800365}
366
Chenjie Yub3dda412017-10-24 13:41:59 -0700367} // namespace statsd
368} // namespace os
Yao Chen93fe3a32017-11-02 13:52:59 -0700369} // namespace android