OSDN Git Service

Merge "Reduce statsd log data size." into pi-dev
authorandroid-build-team Robot <android-build-team-robot@google.com>
Wed, 2 May 2018 00:45:51 +0000 (00:45 +0000)
committerAndroid (Google) Code Review <android-gerrit@google.com>
Wed, 2 May 2018 00:45:51 +0000 (00:45 +0000)
12 files changed:
1  2 
cmds/statsd/src/metrics/CountMetricProducer.cpp
cmds/statsd/src/metrics/CountMetricProducer.h
cmds/statsd/src/metrics/DurationMetricProducer.cpp
cmds/statsd/src/metrics/DurationMetricProducer.h
cmds/statsd/src/metrics/EventMetricProducer.cpp
cmds/statsd/src/metrics/EventMetricProducer.h
cmds/statsd/src/metrics/GaugeMetricProducer.cpp
cmds/statsd/src/metrics/GaugeMetricProducer.h
cmds/statsd/src/metrics/MetricProducer.h
cmds/statsd/src/metrics/MetricsManager.cpp
cmds/statsd/src/metrics/ValueMetricProducer.cpp
cmds/statsd/src/metrics/ValueMetricProducer.h

@@@ -122,14 -132,9 +132,15 @@@ void CountMetricProducer::onSlicedCondi
      VLOG("Metric %lld onSlicedConditionMayChange", (long long)mMetricId);
  }
  
 +
 +void CountMetricProducer::clearPastBucketsLocked(const int64_t dumpTimeNs) {
 +    flushIfNeededLocked(dumpTimeNs);
 +    mPastBuckets.clear();
 +}
 +
  void CountMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
                                               const bool include_current_partial_bucket,
+                                              std::set<string> *str_set,
                                               ProtoOutputStream* protoOutput) {
      if (include_current_partial_bucket) {
          flushLocked(dumpTimeNs);
@@@ -57,10 -57,9 +57,11 @@@ private
  
      void onDumpReportLocked(const int64_t dumpTimeNs,
                              const bool include_current_partial_bucket,
+                             std::set<string> *str_set,
                              android::util::ProtoOutputStream* protoOutput) override;
  
 +    void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
 +
      // Internal interface to handle condition change.
      void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
  
@@@ -438,13 -448,9 +448,14 @@@ void DurationMetricProducer::dropDataLo
      mPastBuckets.clear();
  }
  
 +void DurationMetricProducer::clearPastBucketsLocked(const int64_t dumpTimeNs) {
 +    flushIfNeededLocked(dumpTimeNs);
 +    mPastBuckets.clear();
 +}
 +
  void DurationMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
                                                  const bool include_current_partial_bucket,
+                                                 std::set<string> *str_set,
                                                  ProtoOutputStream* protoOutput) {
      if (include_current_partial_bucket) {
          flushLocked(dumpTimeNs);
@@@ -63,10 -63,9 +63,11 @@@ private
  
      void onDumpReportLocked(const int64_t dumpTimeNs,
                              const bool include_current_partial_bucket,
+                             std::set<string> *str_set,
                              android::util::ProtoOutputStream* protoOutput) override;
  
 +    void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
 +
      // Internal interface to handle condition change.
      void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
  
@@@ -100,12 -100,9 +100,13 @@@ std::unique_ptr<std::vector<uint8_t>> s
      return buffer;
  }
  
 +void EventMetricProducer::clearPastBucketsLocked(const int64_t dumpTimeNs) {
 +    mProto->clear();
 +}
 +
  void EventMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
                                               const bool include_current_partial_bucket,
+                                              std::set<string> *str_set,
                                               ProtoOutputStream* protoOutput) {
      if (mProto->size() <= 0) {
          return;
@@@ -48,8 -48,8 +48,9 @@@ private
  
      void onDumpReportLocked(const int64_t dumpTimeNs,
                              const bool include_current_partial_bucket,
+                             std::set<string> *str_set,
                              android::util::ProtoOutputStream* protoOutput) override;
 +    void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
  
      // Internal interface to handle condition change.
      void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;
@@@ -160,14 -169,9 +169,15 @@@ void GaugeMetricProducer::dumpStatesLoc
      }
  }
  
 +void GaugeMetricProducer::clearPastBucketsLocked(const int64_t dumpTimeNs) {
 +    flushIfNeededLocked(dumpTimeNs);
 +    mPastBuckets.clear();
 +    mSkippedBuckets.clear();
 +}
 +
  void GaugeMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
                                               const bool include_current_partial_bucket,
+                                              std::set<string> *str_set,
                                               ProtoOutputStream* protoOutput) {
      VLOG("Gauge metric %lld report now...", (long long)mMetricId);
      if (include_current_partial_bucket) {
@@@ -90,8 -90,8 +90,9 @@@ protected
  private:
      void onDumpReportLocked(const int64_t dumpTimeNs,
                              const bool include_current_partial_bucket,
+                             std::set<string> *str_set,
                              android::util::ProtoOutputStream* protoOutput) override;
 +    void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
  
      // for testing
      GaugeMetricProducer(const ConfigKey& key, const GaugeMetric& gaugeMetric,
@@@ -114,16 -115,12 +115,17 @@@ public
      // This method clears all the past buckets.
      void onDumpReport(const int64_t dumpTimeNs,
                        const bool include_current_partial_bucket,
+                       std::set<string> *str_set,
                        android::util::ProtoOutputStream* protoOutput) {
          std::lock_guard<std::mutex> lock(mMutex);
-         return onDumpReportLocked(dumpTimeNs, include_current_partial_bucket, protoOutput);
+         return onDumpReportLocked(dumpTimeNs, include_current_partial_bucket, str_set, protoOutput);
      }
  
 +    void clearPastBuckets(const int64_t dumpTimeNs) {
 +        std::lock_guard<std::mutex> lock(mMutex);
 +        return clearPastBucketsLocked(dumpTimeNs);
 +    }
 +
      void dumpStates(FILE* out, bool verbose) const {
          std::lock_guard<std::mutex> lock(mMutex);
          dumpStatesLocked(out, verbose);
@@@ -181,8 -178,8 +183,9 @@@ protected
                                                    const int64_t eventTime) = 0;
      virtual void onDumpReportLocked(const int64_t dumpTimeNs,
                                      const bool include_current_partial_bucket,
+                                     std::set<string> *str_set,
                                      android::util::ProtoOutputStream* protoOutput) = 0;
 +    virtual void clearPastBucketsLocked(const int64_t dumpTimeNs) = 0;
      virtual size_t byteSizeLocked() const = 0;
      virtual void dumpStatesLocked(FILE* out, bool verbose) const = 0;
  
@@@ -197,12 -199,11 +199,13 @@@ void MetricsManager::onDumpReport(cons
      // one StatsLogReport per MetricProduer
      for (const auto& producer : mAllMetricProducers) {
          if (mNoReportMetricIds.find(producer->getMetricId()) == mNoReportMetricIds.end()) {
-             uint64_t token =
-                     protoOutput->start(FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_METRICS);
-             producer->onDumpReport(dumpTimeStampNs, include_current_partial_bucket, protoOutput);
+             uint64_t token = protoOutput->start(
+                     FIELD_TYPE_MESSAGE | FIELD_COUNT_REPEATED | FIELD_ID_METRICS);
+             producer->onDumpReport(dumpTimeStampNs, include_current_partial_bucket, str_set,
+                                    protoOutput);
              protoOutput->end(token);
 +        } else {
 +            producer->clearPastBuckets(dumpTimeStampNs);
          }
      }
      for (const auto& annotation : mAnnotations) {
@@@ -151,14 -160,9 +160,15 @@@ void ValueMetricProducer::dropDataLocke
      mPastBuckets.clear();
  }
  
 +void ValueMetricProducer::clearPastBucketsLocked(const int64_t dumpTimeNs) {
 +    flushIfNeededLocked(dumpTimeNs);
 +    mPastBuckets.clear();
 +    mSkippedBuckets.clear();
 +}
 +
  void ValueMetricProducer::onDumpReportLocked(const int64_t dumpTimeNs,
                                               const bool include_current_partial_bucket,
+                                              std::set<string> *str_set,
                                               ProtoOutputStream* protoOutput) {
      VLOG("metric %lld dump report now...", (long long)mMetricId);
      if (include_current_partial_bucket) {
@@@ -88,8 -88,8 +88,9 @@@ protected
  private:
      void onDumpReportLocked(const int64_t dumpTimeNs,
                              const bool include_current_partial_bucket,
+                             std::set<string> *str_set,
                              android::util::ProtoOutputStream* protoOutput) override;
 +    void clearPastBucketsLocked(const int64_t dumpTimeNs) override;
  
      // Internal interface to handle condition change.
      void onConditionChangedLocked(const bool conditionMet, const int64_t eventTime) override;