OSDN Git Service

Fix UidMap proto output error. And fix a bug in MaxDurationTracker.
authorYao Chen <yaochen@google.com>
Thu, 22 Mar 2018 00:21:23 +0000 (17:21 -0700)
committerYao Chen <yaochen@google.com>
Thu, 22 Mar 2018 16:07:03 +0000 (09:07 -0700)
Bug: 76118312
Bug: 76145379

Test: adb shell cmd stats dump-report
      statsd_test
Change-Id: I9a987525df5b37fcefd5f28700bfa1c3952f6692

cmds/statsd/src/metrics/duration_helper/MaxDurationTracker.cpp
cmds/statsd/src/packages/UidMap.cpp

index 335ec4c..c9547cf 100644 (file)
@@ -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;
         }
     }
index 3ba4b7a..1cb20bc 100644 (file)
@@ -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);
         }
     }