You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@kudu.apache.org by ad...@apache.org on 2019/04/05 16:06:44 UTC

[kudu] branch master updated: [metrics] Remove incorrect comments

This is an automated email from the ASF dual-hosted git repository.

adar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git


The following commit(s) were added to refs/heads/master by this push:
     new 7fa52e0  [metrics] Remove incorrect comments
7fa52e0 is described below

commit 7fa52e0412777d5b19786f4af58770dc1036a73d
Author: Yingchun Lai <40...@qq.com>
AuthorDate: Wed Apr 3 12:23:40 2019 -0400

    [metrics] Remove incorrect comments
    
    Data store in std::map with key type 'const char*' is not in
    alphabetical order, and it's not needed to sort metrics.
    
    Change-Id: Id8788c38b73c623616b3fb2b73fcb6973df4ec87
    Reviewed-on: http://gerrit.cloudera.org:8080/12921
    Tested-by: Kudu Jenkins
    Reviewed-by: Adar Dembo <ad...@cloudera.com>
---
 src/kudu/util/metrics.cc | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)

diff --git a/src/kudu/util/metrics.cc b/src/kudu/util/metrics.cc
index dc30360..a5d7584 100644
--- a/src/kudu/util/metrics.cc
+++ b/src/kudu/util/metrics.cc
@@ -17,7 +17,6 @@
 #include "kudu/util/metrics.h"
 
 #include <iostream>
-#include <map>
 #include <utility>
 
 #include <gflags/gflags.h>
@@ -211,20 +210,21 @@ Status MetricEntity::WriteAsJson(JsonWriter* writer,
                                  const MetricJsonOptions& opts) const {
   bool select_all = MatchMetricInList(id(), requested_metrics);
 
-  // We want the keys to be in alphabetical order when printing, so we use an ordered map here.
-  typedef std::map<const char*, scoped_refptr<Metric> > OrderedMetricMap;
-  OrderedMetricMap metrics;
+  MetricMap metrics;
   AttributeMap attrs;
   {
     // Snapshot the metrics in this registry (not guaranteed to be a consistent snapshot)
     std::lock_guard<simple_spinlock> l(lock_);
     attrs = attributes_;
-    for (const MetricMap::value_type& val : metric_map_) {
-      const MetricPrototype* prototype = val.first;
-      const scoped_refptr<Metric>& metric = val.second;
+    metrics = metric_map_;
+  }
 
-      if (select_all || MatchMetricInList(prototype->name(), requested_metrics)) {
-        InsertOrDie(&metrics, prototype->name(), metric);
+  if (!select_all) {
+    for (auto metric = metrics.begin(); metric != metrics.end();) {
+      if (!MatchMetricInList(metric->first->name(), requested_metrics)) {
+        metric = metrics.erase(metric);
+      } else {
+        ++metric;
       }
     }
   }
@@ -255,14 +255,14 @@ Status MetricEntity::WriteAsJson(JsonWriter* writer,
 
   writer->String("metrics");
   writer->StartArray();
-  for (OrderedMetricMap::value_type& val : metrics) {
+  for (MetricMap::value_type& val : metrics) {
     const auto& m = val.second;
     if (m->ModifiedInOrAfterEpoch(opts.only_modified_in_or_after_epoch)) {
       if (!opts.include_untouched_metrics && m->IsUntouched()) {
         continue;
       }
       WARN_NOT_OK(m->WriteAsJson(writer, opts),
-                  strings::Substitute("Failed to write $0 as JSON", val.first));
+                  strings::Substitute("Failed to write $0 as JSON", val.first->name()));
     }
   }
   writer->EndArray();