From 59cc0a2237fe0527c9871f0236e9bc76146990b7 Mon Sep 17 00:00:00 2001 From: Yao Chen Date: Wed, 21 Mar 2018 17:21:23 -0700 Subject: [PATCH] Fix UidMap proto output error. And fix a bug in MaxDurationTracker. Bug: 76118312 Bug: 76145379 Test: adb shell cmd stats dump-report statsd_test Change-Id: I9a987525df5b37fcefd5f28700bfa1c3952f6692 --- .../src/metrics/duration_helper/MaxDurationTracker.cpp | 5 +++-- cmds/statsd/src/packages/UidMap.cpp | 3 ++- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/cmds/statsd/src/metrics/duration_helper/MaxDurationTracker.cpp b/cmds/statsd/src/metrics/duration_helper/MaxDurationTracker.cpp index 335ec4c7cbd59..c9547cf4bf41c 100644 --- a/cmds/statsd/src/metrics/duration_helper/MaxDurationTracker.cpp +++ b/cmds/statsd/src/metrics/duration_helper/MaxDurationTracker.cpp @@ -205,11 +205,12 @@ bool MaxDurationTracker::flushCurrentBucket( bool hasPendingEvent = false; // has either a kStarted or kPaused event across bucket boundaries // meaning we need to carry them over to the new bucket. - for (auto it = mInfos.begin(); it != mInfos.end(); ++it) { + for (auto it = mInfos.begin(); it != mInfos.end();) { if (it->second.state == DurationState::kStopped) { // No need to keep buckets for events that were stopped before. - mInfos.erase(it); + it = mInfos.erase(it); } else { + ++it; hasPendingEvent = true; } } diff --git a/cmds/statsd/src/packages/UidMap.cpp b/cmds/statsd/src/packages/UidMap.cpp index 3ba4b7a20fbed..1cb20bc732d86 100644 --- a/cmds/statsd/src/packages/UidMap.cpp +++ b/cmds/statsd/src/packages/UidMap.cpp @@ -365,7 +365,8 @@ void UidMap::appendUidMap(const int64_t& timestamp, const ConfigKey& key, count++; proto->write(FIELD_TYPE_INT64 | FIELD_ID_SNAPSHOT_TIMESTAMP, (long long)record.timestampNs); - proto->write(FIELD_TYPE_MESSAGE | FIELD_ID_SNAPSHOT_PACKAGE_INFO, record.bytes.data()); + proto->write(FIELD_TYPE_MESSAGE | FIELD_ID_SNAPSHOT_PACKAGE_INFO, record.bytes.data(), + record.bytes.size()); proto->end(snapshotsToken); } }