From 8dda354bde1e639d7f481b6895b38460fba3a018 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Thu, 4 Oct 2018 08:58:31 +0000 Subject: rename MetricIdentifier -> MetricPointId --- .../src/vespa/vespalib/metrics/CMakeLists.txt | 2 +- .../src/vespa/vespalib/metrics/bucket.cpp | 4 +-- .../src/vespa/vespalib/metrics/bucket.h | 2 +- .../src/vespa/vespalib/metrics/counter.cpp | 2 +- .../src/vespa/vespalib/metrics/counter.h | 6 ++-- .../vespa/vespalib/metrics/counter_aggregator.h | 4 +-- .../src/vespa/vespalib/metrics/gauge.cpp | 2 +- .../src/vespa/vespalib/metrics/gauge.h | 6 ++-- .../src/vespa/vespalib/metrics/gauge_aggregator.h | 4 +-- .../vespa/vespalib/metrics/metric_identifier.cpp | 2 -- .../src/vespa/vespalib/metrics/metric_identifier.h | 38 ---------------------- .../src/vespa/vespalib/metrics/metric_point_id.cpp | 2 ++ .../src/vespa/vespalib/metrics/metric_point_id.h | 38 ++++++++++++++++++++++ .../src/vespa/vespalib/metrics/simple_metrics.h | 2 +- 14 files changed, 57 insertions(+), 57 deletions(-) delete mode 100644 staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.cpp delete mode 100644 staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.h create mode 100644 staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.cpp create mode 100644 staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt index 4a28734b85d..6da005ffbb7 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt +++ b/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt @@ -13,7 +13,7 @@ vespa_add_library(staging_vespalib_vespalib_metrics OBJECT handle.cpp json_formatter.cpp label.cpp - metric_identifier.cpp + metric_point_id.cpp metric_name.cpp metrics_manager.cpp metric_types.cpp diff --git a/staging_vespalib/src/vespa/vespalib/metrics/bucket.cpp b/staging_vespalib/src/vespa/vespalib/metrics/bucket.cpp index 52e95e1ac3f..af942a48fb9 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/bucket.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/bucket.cpp @@ -14,12 +14,12 @@ mergeFromSamples(const StableStore &source) { using Aggregator = typename T::aggregator_type; using Sample = typename T::sample_type; - using Map = std::map; + using Map = std::map; using MapValue = typename Map::value_type; Map map; source.for_each([&map] (const Sample &sample) { - MetricIdentifier id = sample.idx; + MetricPointId id = sample.idx; auto iter_check = map.emplace(id, sample); if (!iter_check.second) { iter_check.first->second.merge(sample); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/bucket.h b/staging_vespalib/src/vespa/vespalib/metrics/bucket.h index 5a88e435502..e358080b73b 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/bucket.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/bucket.h @@ -3,7 +3,7 @@ #include #include "stable_store.h" -#include "metric_identifier.h" +#include "metric_point_id.h" #include "counter.h" #include "gauge.h" #include "clock.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/counter.cpp b/staging_vespalib/src/vespa/vespalib/metrics/counter.cpp index 08f72e6aa34..c04a21a0020 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/counter.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/counter.cpp @@ -10,7 +10,7 @@ void Counter::add(size_t count, Point point) const { if (_manager) { - MetricIdentifier fullId(_id, point); + MetricPointId fullId(_id, point); _manager->add(Increment(fullId, count)); } } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/counter.h b/staging_vespalib/src/vespa/vespalib/metrics/counter.h index 36a25adda2d..680f4a18fb0 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/counter.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/counter.h @@ -2,7 +2,7 @@ #pragma once #include -#include "metric_identifier.h" +#include "metric_point_id.h" #include "point.h" namespace vespalib { @@ -42,10 +42,10 @@ public: // internal struct Increment { - MetricIdentifier idx; + MetricPointId idx; size_t value; Increment() = delete; - Increment(MetricIdentifier id, size_t v) : idx(id), value(v) {} + Increment(MetricPointId id, size_t v) : idx(id), value(v) {} }; typedef CounterAggregator aggregator_type; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/counter_aggregator.h b/staging_vespalib/src/vespa/vespalib/metrics/counter_aggregator.h index 995ba07deb3..e7f9ab1c9ab 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/counter_aggregator.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/counter_aggregator.h @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include "metric_identifier.h" +#include "metric_point_id.h" #include "counter.h" namespace vespalib { @@ -9,7 +9,7 @@ namespace metrics { // internal struct CounterAggregator { - MetricIdentifier idx; + MetricPointId idx; size_t count; CounterAggregator(const Counter::Increment &other); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/gauge.cpp b/staging_vespalib/src/vespa/vespalib/metrics/gauge.cpp index af98ba2de18..f2afc87f16f 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/gauge.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/gauge.cpp @@ -9,7 +9,7 @@ void Gauge::sample(double value, Point point) const { if (_manager) { - MetricIdentifier fullId(_id, point); + MetricPointId fullId(_id, point); _manager->sample(Measurement(fullId, value)); } } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/gauge.h b/staging_vespalib/src/vespa/vespalib/metrics/gauge.h index fa3f826f2b8..b9702b93089 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/gauge.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/gauge.h @@ -2,7 +2,7 @@ #pragma once #include -#include "metric_identifier.h" +#include "metric_point_id.h" #include "point.h" namespace vespalib { @@ -32,10 +32,10 @@ public: // internal struct Measurement { - MetricIdentifier idx; + MetricPointId idx; double value; Measurement() = delete; - Measurement(MetricIdentifier id, double v) : idx(id), value(v) {} + Measurement(MetricPointId id, double v) : idx(id), value(v) {} }; typedef GaugeAggregator aggregator_type; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/gauge_aggregator.h b/staging_vespalib/src/vespa/vespalib/metrics/gauge_aggregator.h index 84772d7fff4..ae3365bc7f0 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/gauge_aggregator.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/gauge_aggregator.h @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include "metric_identifier.h" +#include "metric_point_id.h" #include "gauge.h" namespace vespalib { @@ -9,7 +9,7 @@ namespace metrics { // internal struct GaugeAggregator { - MetricIdentifier idx; + MetricPointId idx; size_t observedCount; double sumValue; double minValue; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.cpp b/staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.cpp deleted file mode 100644 index 950adc3462d..00000000000 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.cpp +++ /dev/null @@ -1,2 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "metric_identifier.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.h b/staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.h deleted file mode 100644 index 0fc5af41a81..00000000000 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include "metric_name.h" -#include "point.h" -#include - -namespace vespalib { -namespace metrics { - -// internal -struct MetricIdentifier { - const MetricName _name; - const Point _point; - - MetricIdentifier() = delete; - - MetricIdentifier(MetricName name, Point point) - : _name(name), _point(point) {} - - bool operator< (const MetricIdentifier &other) const { - if (_name != other._name) { - return _name < other._name; - } - return _point < other._point; - } - bool operator== (const MetricIdentifier &other) const { - return (_name == other._name && - _point == other._point); - } - - MetricName name() const { return _name; } - Point point() const { return _point; } - -}; - -} // namespace vespalib::metrics -} // namespace vespalib diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.cpp b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.cpp new file mode 100644 index 00000000000..90ecabdb75f --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.cpp @@ -0,0 +1,2 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "metric_point_id.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h new file mode 100644 index 00000000000..9a709bfb9a6 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h @@ -0,0 +1,38 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include "metric_name.h" +#include "point.h" +#include + +namespace vespalib { +namespace metrics { + +/** class to use as a map key, identifying a metric and a point */ +struct MetricPointId { + const MetricName _name; + const Point _point; + + MetricPointId() = delete; + + MetricPointId(MetricName name, Point point) + : _name(name), _point(point) {} + + bool operator< (const MetricPointId &other) const { + if (_name != other._name) { + return _name < other._name; + } + return _point < other._point; + } + bool operator== (const MetricPointId &other) const { + return (_name == other._name && + _point == other._point); + } + + MetricName name() const { return _name; } + Point point() const { return _point; } + +}; + +} // namespace vespalib::metrics +} // namespace vespalib diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h index 6e6cff55b1f..4f9f47f2347 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h @@ -13,7 +13,7 @@ #include "gauge.h" #include "json_formatter.h" #include "label.h" -#include "metric_identifier.h" +#include "metric_point_id.h" #include "metric_name.h" #include "metrics_manager.h" #include "point_builder.h" -- cgit v1.2.3 From 6c2a5af5bf087efb126692e69ed973739e0fbafb Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Thu, 4 Oct 2018 09:00:15 +0000 Subject: rename MetricName -> MetricId --- .../src/tests/metrics/simple_metrics_test.cpp | 2 +- .../src/vespa/vespalib/metrics/CMakeLists.txt | 2 +- staging_vespalib/src/vespa/vespalib/metrics/counter.h | 4 ++-- .../src/vespa/vespalib/metrics/dummy_metrics_manager.h | 4 ++-- staging_vespalib/src/vespa/vespalib/metrics/gauge.h | 4 ++-- staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp | 2 ++ staging_vespalib/src/vespa/vespalib/metrics/metric_id.h | 15 +++++++++++++++ .../src/vespa/vespalib/metrics/metric_name.cpp | 2 -- staging_vespalib/src/vespa/vespalib/metrics/metric_name.h | 15 --------------- .../src/vespa/vespalib/metrics/metric_point_id.h | 8 ++++---- staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp | 6 +++--- staging_vespalib/src/vespa/vespalib/metrics/name_repo.h | 6 +++--- .../src/vespa/vespalib/metrics/simple_metrics.h | 2 +- .../src/vespa/vespalib/metrics/simple_metrics_manager.cpp | 8 ++++---- 14 files changed, 40 insertions(+), 40 deletions(-) create mode 100644 staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp create mode 100644 staging_vespalib/src/vespa/vespalib/metrics/metric_id.h delete mode 100644 staging_vespalib/src/vespa/vespalib/metrics/metric_name.cpp delete mode 100644 staging_vespalib/src/vespa/vespalib/metrics/metric_name.h (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp b/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp index d0163f922b3..7ef57415416 100644 --- a/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp +++ b/staging_vespalib/src/tests/metrics/simple_metrics_test.cpp @@ -15,7 +15,7 @@ using namespace vespalib::metrics; TEST("require that simple metrics gauge merge works") { - MetricIdentifier id(MetricName(42), Point(17)); + MetricPointId id(MetricId(42), Point(17)); Gauge::Measurement a1(id, 0.0); Gauge::Measurement b1(id, 7.0); Gauge::Measurement b2(id, 9.0); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt index 6da005ffbb7..5112286b359 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt +++ b/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt @@ -14,7 +14,7 @@ vespa_add_library(staging_vespalib_vespalib_metrics OBJECT json_formatter.cpp label.cpp metric_point_id.cpp - metric_name.cpp + metric_id.cpp metrics_manager.cpp metric_types.cpp name_collection.cpp diff --git a/staging_vespalib/src/vespa/vespalib/metrics/counter.h b/staging_vespalib/src/vespa/vespalib/metrics/counter.h index 680f4a18fb0..192a08aba66 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/counter.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/counter.h @@ -17,14 +17,14 @@ class CounterAggregator; **/ class Counter { std::shared_ptr _manager; - MetricName _id; + MetricId _id; public: Counter() : _manager(), _id(0) {} Counter(const Counter&) = delete; Counter(Counter &&other) = default; Counter& operator= (const Counter &) = delete; Counter& operator= (Counter &&other) = default; - Counter(std::shared_ptr m, MetricName id) + Counter(std::shared_ptr m, MetricId id) : _manager(std::move(m)), _id(id) {} diff --git a/staging_vespalib/src/vespa/vespalib/metrics/dummy_metrics_manager.h b/staging_vespalib/src/vespa/vespalib/metrics/dummy_metrics_manager.h index 52e9c6a608c..588bc43d83c 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/dummy_metrics_manager.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/dummy_metrics_manager.h @@ -30,10 +30,10 @@ public: } Counter counter(const vespalib::string &, const vespalib::string &) override { - return Counter(shared_from_this(), MetricName(0)); + return Counter(shared_from_this(), MetricId(0)); } Gauge gauge(const vespalib::string &, const vespalib::string &) override { - return Gauge(shared_from_this(), MetricName(0)); + return Gauge(shared_from_this(), MetricId(0)); } Dimension dimension(const vespalib::string &) override { diff --git a/staging_vespalib/src/vespa/vespalib/metrics/gauge.h b/staging_vespalib/src/vespa/vespalib/metrics/gauge.h index b9702b93089..c4542ac87e4 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/gauge.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/gauge.h @@ -17,9 +17,9 @@ class GaugeAggregator; class Gauge { private: std::shared_ptr _manager; - MetricName _id; + MetricId _id; public: - Gauge(std::shared_ptr m, MetricName id) + Gauge(std::shared_ptr m, MetricId id) : _manager(std::move(m)), _id(id) {} diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp new file mode 100644 index 00000000000..df985db9938 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp @@ -0,0 +1,2 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "metric_id.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_id.h b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.h new file mode 100644 index 00000000000..58b401cd552 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.h @@ -0,0 +1,15 @@ +// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include "handle.h" + +namespace vespalib::metrics { + +struct MetricIdTag {}; + +/** + * Opaque handle representing an uniquely named metric. + **/ +using MetricId = Handle; + +} // namespace vespalib::metrics diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_name.cpp b/staging_vespalib/src/vespa/vespalib/metrics/metric_name.cpp deleted file mode 100644 index 2a58d55e945..00000000000 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_name.cpp +++ /dev/null @@ -1,2 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "metric_name.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_name.h b/staging_vespalib/src/vespa/vespalib/metrics/metric_name.h deleted file mode 100644 index 60dfa0aa00f..00000000000 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_name.h +++ /dev/null @@ -1,15 +0,0 @@ -// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#pragma once - -#include "handle.h" - -namespace vespalib::metrics { - -struct MetricNameTag {}; - -/** - * Opaque handle representing an uniquely named metric. - **/ -using MetricName = Handle; - -} // namespace vespalib::metrics diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h index 9a709bfb9a6..f9d788a0f92 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h @@ -1,7 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once -#include "metric_name.h" +#include "metric_id.h" #include "point.h" #include @@ -10,12 +10,12 @@ namespace metrics { /** class to use as a map key, identifying a metric and a point */ struct MetricPointId { - const MetricName _name; + const MetricId _name; const Point _point; MetricPointId() = delete; - MetricPointId(MetricName name, Point point) + MetricPointId(MetricId name, Point point) : _name(name), _point(point) {} bool operator< (const MetricPointId &other) const { @@ -29,7 +29,7 @@ struct MetricPointId { _point == other._point); } - MetricName name() const { return _name; } + MetricId name() const { return _name; } Point point() const { return _point; } }; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp index f8294661c77..a47be2f128c 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp @@ -7,12 +7,12 @@ LOG_SETUP(".vespalib.metrics.name_repo"); namespace vespalib { namespace metrics { -MetricName +MetricId NameRepo::metric(const vespalib::string &name) { size_t id = _metricNames.resolve(name); LOG(debug, "metric name %s -> %zu", name.c_str(), id); - return MetricName(id); + return MetricId(id); } Dimension @@ -32,7 +32,7 @@ NameRepo::label(const vespalib::string &value) } const vespalib::string& -NameRepo::metricName(MetricName metric) +NameRepo::metricName(MetricId metric) { return _metricNames.lookup(metric.id()); } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h index f6972091ff1..b6e643c489e 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h @@ -4,7 +4,7 @@ #include #include "dimension.h" #include "label.h" -#include "metric_name.h" +#include "metric_id.h" #include "point.h" #include "name_collection.h" @@ -28,11 +28,11 @@ private: ~NameRepo() = default; public: - MetricName metric(const vespalib::string &name); + MetricId metric(const vespalib::string &name); Dimension dimension(const vespalib::string &name); Label label(const vespalib::string &value); - const vespalib::string& metricName(MetricName metric); + const vespalib::string& metricName(MetricId metric); const vespalib::string& dimensionName(Dimension dim); const vespalib::string& labelValue(Label l); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h index 4f9f47f2347..34959146928 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h @@ -14,7 +14,7 @@ #include "json_formatter.h" #include "label.h" #include "metric_point_id.h" -#include "metric_name.h" +#include "metric_id.h" #include "metrics_manager.h" #include "point_builder.h" #include "point.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp index 4df44755c0b..46c3f30ea27 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp @@ -51,7 +51,7 @@ SimpleMetricsManager::createForTest(const SimpleManagerConfig &config, Counter SimpleMetricsManager::counter(const vespalib::string &name, const vespalib::string &) { - MetricName mn = NameRepo::instance.metric(name); + MetricId mn = NameRepo::instance.metric(name); _metricTypes.check(mn.id(), name, MetricTypes::MetricType::COUNTER); LOG(debug, "counter with metric name %s -> %zu", name.c_str(), mn.id()); return Counter(shared_from_this(), mn); @@ -60,7 +60,7 @@ SimpleMetricsManager::counter(const vespalib::string &name, const vespalib::stri Gauge SimpleMetricsManager::gauge(const vespalib::string &name, const vespalib::string &) { - MetricName mn = NameRepo::instance.metric(name); + MetricId mn = NameRepo::instance.metric(name); _metricTypes.check(mn.id(), name, MetricTypes::MetricType::GAUGE); LOG(debug, "gauge with metric name %s -> %zu", name.c_str(), mn.id()); return Gauge(shared_from_this(), mn); @@ -118,14 +118,14 @@ SimpleMetricsManager::snapshotFrom(const Bucket &bucket) } } for (const CounterAggregator& entry : bucket.counters) { - MetricName mn = entry.idx.name(); + MetricId mn = entry.idx.name(); size_t pi = entry.idx.point().id(); const vespalib::string &name = NameRepo::instance.metricName(mn); CounterSnapshot val(name, snap.points()[pi], entry); snap.add(val); } for (const GaugeAggregator& entry : bucket.gauges) { - MetricName mn = entry.idx.name(); + MetricId mn = entry.idx.name(); size_t pi = entry.idx.point().id(); const vespalib::string &name = NameRepo::instance.metricName(mn); GaugeSnapshot val(name, snap.points()[pi], entry); -- cgit v1.2.3 From 8a941d0fb215cb1a698959bafa5b789a376eef93 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Fri, 5 Oct 2018 19:36:04 +0000 Subject: constify --- staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp | 8 ++++---- staging_vespalib/src/vespa/vespalib/metrics/name_repo.h | 8 ++++---- .../src/vespa/vespalib/metrics/point_map_collection.cpp | 2 +- .../src/vespa/vespalib/metrics/point_map_collection.h | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp index a47be2f128c..bb4fb6deb7c 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp @@ -32,26 +32,26 @@ NameRepo::label(const vespalib::string &value) } const vespalib::string& -NameRepo::metricName(MetricId metric) +NameRepo::metricName(MetricId metric) const { return _metricNames.lookup(metric.id()); } const vespalib::string& -NameRepo::dimensionName(Dimension dim) +NameRepo::dimensionName(Dimension dim) const { return _dimensionNames.lookup(dim.id()); } const vespalib::string& -NameRepo::labelValue(Label l) +NameRepo::labelValue(Label l) const { return _labelValues.lookup(l.id()); } const PointMap::BackingMap& -NameRepo::pointMap(Point from) +NameRepo::pointMap(Point from) const { const PointMap &map = _pointMaps.lookup(from.id()); return map.backingMap(); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h index b6e643c489e..ce2884cefbc 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h @@ -32,11 +32,11 @@ public: Dimension dimension(const vespalib::string &name); Label label(const vespalib::string &value); - const vespalib::string& metricName(MetricId metric); - const vespalib::string& dimensionName(Dimension dim); - const vespalib::string& labelValue(Label l); + const vespalib::string& metricName(MetricId metric) const; + const vespalib::string& dimensionName(Dimension dim) const; + const vespalib::string& labelValue(Label l) const; - const PointMap::BackingMap& pointMap(Point from); + const PointMap::BackingMap& pointMap(Point from) const; Point pointFrom(PointMap::BackingMap map); static NameRepo instance; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp index 7b09fbf7746..3769d141516 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp @@ -8,7 +8,7 @@ namespace metrics { using Guard = std::lock_guard; const PointMap & -PointMapCollection::lookup(size_t id) +PointMapCollection::lookup(size_t id) const { Guard guard(_lock); assert(id < _vec.size()); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h index ba301ff3f06..ce501c9229a 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h @@ -18,7 +18,7 @@ private: PointMapMap _map; std::vector _vec; public: - const PointMap &lookup(size_t id); + const PointMap &lookup(size_t id) const; size_t resolve(PointMap map); size_t size() const; -- cgit v1.2.3 From ca101d103d57ea6adebf3fcd5cb24a9ba0411f27 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Fri, 5 Oct 2018 20:00:28 +0000 Subject: add APIs using NameRepo instance --- .../src/vespa/vespalib/metrics/dimension.cpp | 17 +++++++++++++++++ staging_vespalib/src/vespa/vespalib/metrics/dimension.h | 7 ++++++- staging_vespalib/src/vespa/vespalib/metrics/label.cpp | 17 +++++++++++++++++ staging_vespalib/src/vespa/vespalib/metrics/label.h | 9 +++++++-- .../src/vespa/vespalib/metrics/metric_id.cpp | 17 +++++++++++++++++ staging_vespalib/src/vespa/vespalib/metrics/metric_id.h | 8 +++++++- 6 files changed, 71 insertions(+), 4 deletions(-) (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/vespa/vespalib/metrics/dimension.cpp b/staging_vespalib/src/vespa/vespalib/metrics/dimension.cpp index 05bdd42f34a..1877a986c3e 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/dimension.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/dimension.cpp @@ -1,2 +1,19 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "dimension.h" +#include "name_repo.h" + +namespace vespalib::metrics { + +Dimension +Dimension::from_name(const vespalib::string& name) +{ + return NameRepo::instance.dimension(name); +} + +const vespalib::string& +Dimension::as_name() const +{ + return NameRepo::instance.dimensionName(*this); +} + +} // namespace vespalib::metrics diff --git a/staging_vespalib/src/vespa/vespalib/metrics/dimension.h b/staging_vespalib/src/vespa/vespalib/metrics/dimension.h index ee16bc6f98a..e367e50d8f5 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/dimension.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/dimension.h @@ -13,6 +13,11 @@ struct DimensionTag {}; /** * Opaque handle representing an uniquely named dimension. **/ -using Dimension = Handle; +struct Dimension : Handle +{ + explicit Dimension(size_t id) : Handle(id) {} + static Dimension from_name(const vespalib::string& name); + const vespalib::string& as_name() const; +}; } // namespace vespalib::metrics diff --git a/staging_vespalib/src/vespa/vespalib/metrics/label.cpp b/staging_vespalib/src/vespa/vespalib/metrics/label.cpp index 218db1ca2ce..3de952b252d 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/label.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/label.cpp @@ -1,2 +1,19 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "label.h" +#include "name_repo.h" + +namespace vespalib::metrics { + +Label +Label::from_value(const vespalib::string& value) +{ + return NameRepo::instance.label(value); +} + +const vespalib::string& +Label::as_value() const +{ + return NameRepo::instance.labelValue(*this); +} + +} // namespace vespalib::metrics diff --git a/staging_vespalib/src/vespa/vespalib/metrics/label.h b/staging_vespalib/src/vespa/vespalib/metrics/label.h index e2356415fd6..561c8061991 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/label.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/label.h @@ -11,8 +11,13 @@ using LabelValue = vespalib::string; struct LabelTag {}; /** - * Opaque handle representing an uniquely named label. + * Opaque handle representing an unique label value. **/ -using Label = Handle; +struct Label : Handle +{ + explicit Label(size_t id) : Handle(id) {} + static Label from_value(const vespalib::string& value); + const vespalib::string& as_value() const; +}; } // namespace vespalib::metrics diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp index df985db9938..2b8c0705a9f 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp @@ -1,2 +1,19 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "metric_id.h" +#include "name_repo.h" + +namespace vespalib::metrics { + +MetricId +MetricId::from_name(const vespalib::string& name) +{ + return NameRepo::instance.metric(name); +} + +const vespalib::string& +MetricId::as_name() const +{ + return NameRepo::instance.metricName(*this); +} + +} // namespace vespalib::metrics diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_id.h b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.h index 58b401cd552..5f337e6decd 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_id.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.h @@ -2,6 +2,7 @@ #pragma once #include "handle.h" +#include namespace vespalib::metrics { @@ -10,6 +11,11 @@ struct MetricIdTag {}; /** * Opaque handle representing an uniquely named metric. **/ -using MetricId = Handle; +struct MetricId : Handle +{ + explicit MetricId(size_t id) : Handle(id) {} + static MetricId from_name(const vespalib::string& name); + const vespalib::string& as_name() const; +}; } // namespace vespalib::metrics -- cgit v1.2.3 From 352591dc2b5fe81fa4222406d6f94f41c35a5177 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Fri, 5 Oct 2018 20:04:05 +0000 Subject: use new APIs --- .../src/vespa/vespalib/metrics/simple_metrics_manager.cpp | 15 ++++++++------- .../src/vespa/vespalib/metrics/simple_metrics_manager.h | 8 -------- 2 files changed, 8 insertions(+), 15 deletions(-) (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp index 46c3f30ea27..5f1525782de 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp @@ -1,6 +1,7 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "simple_metrics_manager.h" #include "simple_tick.h" +#include "name_repo.h" #include LOG_SETUP(".vespalib.metrics.simple_metrics_manager"); @@ -51,7 +52,7 @@ SimpleMetricsManager::createForTest(const SimpleManagerConfig &config, Counter SimpleMetricsManager::counter(const vespalib::string &name, const vespalib::string &) { - MetricId mn = NameRepo::instance.metric(name); + MetricId mn = MetricId::from_name(name); _metricTypes.check(mn.id(), name, MetricTypes::MetricType::COUNTER); LOG(debug, "counter with metric name %s -> %zu", name.c_str(), mn.id()); return Counter(shared_from_this(), mn); @@ -60,7 +61,7 @@ SimpleMetricsManager::counter(const vespalib::string &name, const vespalib::stri Gauge SimpleMetricsManager::gauge(const vespalib::string &name, const vespalib::string &) { - MetricId mn = NameRepo::instance.metric(name); + MetricId mn = MetricId::from_name(name); _metricTypes.check(mn.id(), name, MetricTypes::MetricType::GAUGE); LOG(debug, "gauge with metric name %s -> %zu", name.c_str(), mn.id()); return Gauge(shared_from_this(), mn); @@ -112,7 +113,7 @@ SimpleMetricsManager::snapshotFrom(const Bucket &bucket) const PointMap::BackingMap &map = NameRepo::instance.pointMap(Point(point_id)); PointSnapshot point; for (const PointMap::BackingMap::value_type &kv : map) { - point.dimensions.emplace_back(nameFor(kv.first), valueFor(kv.second)); + point.dimensions.emplace_back(kv.first.as_name(), kv.second.as_value()); } snap.add(point); } @@ -120,14 +121,14 @@ SimpleMetricsManager::snapshotFrom(const Bucket &bucket) for (const CounterAggregator& entry : bucket.counters) { MetricId mn = entry.idx.name(); size_t pi = entry.idx.point().id(); - const vespalib::string &name = NameRepo::instance.metricName(mn); + const vespalib::string &name = mn.as_name(); CounterSnapshot val(name, snap.points()[pi], entry); snap.add(val); } for (const GaugeAggregator& entry : bucket.gauges) { MetricId mn = entry.idx.name(); size_t pi = entry.idx.point().id(); - const vespalib::string &name = NameRepo::instance.metricName(mn); + const vespalib::string &name = mn.as_name(); GaugeSnapshot val(name, snap.points()[pi], entry); snap.add(val); } @@ -170,7 +171,7 @@ SimpleMetricsManager::collectCurrentSamples(TimeStamp prev, Dimension SimpleMetricsManager::dimension(const vespalib::string &name) { - Dimension dim = NameRepo::instance.dimension(name); + Dimension dim = Dimension::from_name(name); LOG(debug, "dimension name %s -> %zu", name.c_str(), dim.id()); return dim; } @@ -178,7 +179,7 @@ SimpleMetricsManager::dimension(const vespalib::string &name) Label SimpleMetricsManager::label(const vespalib::string &value) { - Label l = NameRepo::instance.label(value); + Label l = Label::from_value(value); LOG(debug, "label value %s -> %zu", value.c_str(), l.id()); return l; } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.h b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.h index 4d4b6eb87db..5651a02979a 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.h @@ -6,7 +6,6 @@ #include #include #include -#include "name_repo.h" #include "current_samples.h" #include "snapshots.h" #include "metrics_manager.h" @@ -36,13 +35,6 @@ class SimpleMetricsManager : public MetricsManager private: MetricTypes _metricTypes; - const vespalib::string& nameFor(Dimension dimension) { - return NameRepo::instance.dimensionName(dimension); - } - const vespalib::string& valueFor(Label label) { - return NameRepo::instance.labelValue(label); - } - CurrentSamples _currentSamples; Tick::UP _tickSupplier; -- cgit v1.2.3 From 90a024290d5db17d4484a04530f1bffe2532cf4d Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Fri, 5 Oct 2018 20:12:02 +0000 Subject: rename PointMap * PointMap -> HashedPointMap * PointMap::BackingMap -> PointMap --- .../src/vespa/vespalib/metrics/dummy_metrics_manager.h | 2 +- .../src/vespa/vespalib/metrics/metrics_manager.h | 2 +- .../src/vespa/vespalib/metrics/name_repo.cpp | 8 ++++---- staging_vespalib/src/vespa/vespalib/metrics/name_repo.h | 4 ++-- .../src/vespa/vespalib/metrics/point_builder.cpp | 4 ++-- .../src/vespa/vespalib/metrics/point_builder.h | 4 ++-- .../src/vespa/vespalib/metrics/point_map.cpp | 6 +++--- staging_vespalib/src/vespa/vespalib/metrics/point_map.h | 16 ++++++++-------- .../src/vespa/vespalib/metrics/point_map_collection.cpp | 4 ++-- .../src/vespa/vespalib/metrics/point_map_collection.h | 6 +++--- .../vespa/vespalib/metrics/simple_metrics_manager.cpp | 10 +++++----- .../src/vespa/vespalib/metrics/simple_metrics_manager.h | 2 +- 12 files changed, 34 insertions(+), 34 deletions(-) (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/vespa/vespalib/metrics/dummy_metrics_manager.h b/staging_vespalib/src/vespa/vespalib/metrics/dummy_metrics_manager.h index 588bc43d83c..e4ca1e0ec49 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/dummy_metrics_manager.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/dummy_metrics_manager.h @@ -45,7 +45,7 @@ public: PointBuilder pointBuilder(Point) override { return PointBuilder(shared_from_this()); } - Point pointFrom(PointMap::BackingMap) override { + Point pointFrom(PointMap) override { return Point(0); } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metrics_manager.h b/staging_vespalib/src/vespa/vespalib/metrics/metrics_manager.h index 14f11fa4ab2..4bd919cd1bf 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/metrics_manager.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/metrics_manager.h @@ -78,7 +78,7 @@ public: virtual Snapshot totalSnapshot() = 0; // for use from PointBuilder only - virtual Point pointFrom(PointMap::BackingMap map) = 0; + virtual Point pointFrom(PointMap map) = 0; // for use from Counter only virtual void add(Counter::Increment inc) = 0; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp index bb4fb6deb7c..7db14f3af52 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp @@ -50,17 +50,17 @@ NameRepo::labelValue(Label l) const } -const PointMap::BackingMap& +const PointMap& NameRepo::pointMap(Point from) const { - const PointMap &map = _pointMaps.lookup(from.id()); + const HashedPointMap &map = _pointMaps.lookup(from.id()); return map.backingMap(); } Point -NameRepo::pointFrom(PointMap::BackingMap map) +NameRepo::pointFrom(PointMap map) { - size_t id = _pointMaps.resolve(PointMap(std::move(map))); + size_t id = _pointMaps.resolve(HashedPointMap(std::move(map))); return Point(id); } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h index ce2884cefbc..217fc2e3219 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h @@ -36,8 +36,8 @@ public: const vespalib::string& dimensionName(Dimension dim) const; const vespalib::string& labelValue(Label l) const; - const PointMap::BackingMap& pointMap(Point from) const; - Point pointFrom(PointMap::BackingMap map); + const PointMap& pointMap(Point from) const; + Point pointFrom(PointMap map); static NameRepo instance; }; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp index a89336b4399..76c172c9c44 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp @@ -10,7 +10,7 @@ PointBuilder::PointBuilder(std::shared_ptr m) {} PointBuilder::PointBuilder(std::shared_ptr m, - const PointMap::BackingMap ©From) + const PointMap ©From) : _owner(std::move(m)), _map(copyFrom) {} @@ -60,7 +60,7 @@ PointBuilder::bind(DimensionName dimension, LabelValue label) && Point PointBuilder::build() { - return _owner->pointFrom(PointMap::BackingMap(_map)); + return _owner->pointFrom(PointMap(_map)); } PointBuilder::operator Point() && diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_builder.h b/staging_vespalib/src/vespa/vespalib/metrics/point_builder.h index 923238ec385..ece05089acd 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_builder.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_builder.h @@ -18,12 +18,12 @@ class MetricsManager; class PointBuilder { private: std::shared_ptr _owner; - PointMap::BackingMap _map; + PointMap _map; public: // for use from MetricsManager PointBuilder(std::shared_ptr m); - PointBuilder(std::shared_ptr m, const PointMap::BackingMap &from); + PointBuilder(std::shared_ptr m, const PointMap &from); ~PointBuilder() {} /** diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp index 51908ae235e..134123b2685 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp @@ -5,18 +5,18 @@ namespace vespalib { namespace metrics { -PointMap::PointMap(BackingMap &&from) +HashedPointMap::HashedPointMap(PointMap &&from) : _map(std::move(from)), _hash(0) { - for (const BackingMap::value_type &entry : _map) { + for (const PointMap::value_type &entry : _map) { _hash = (_hash << 7) + (_hash >> 31) + entry.first.id(); _hash = (_hash << 7) + (_hash >> 31) + entry.second.id(); } } bool -PointMap::operator< (const PointMap &other) const +HashedPointMap::operator< (const HashedPointMap &other) const { // cheap comparison first if (_hash != other._hash) { diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map.h b/staging_vespalib/src/vespa/vespalib/metrics/point_map.h index 2ed50a85842..91c28b292c8 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map.h @@ -8,19 +8,19 @@ namespace vespalib { namespace metrics { +using PointMap = std::map; + // internal -class PointMap { -public: - using BackingMap = std::map; +class HashedPointMap { private: - const PointMap::BackingMap _map; + const PointMap _map; size_t _hash; public: - PointMap() : _map(), _hash(0) {} - PointMap(BackingMap &&from); - bool operator< (const PointMap &other) const; + HashedPointMap() : _map(), _hash(0) {} + HashedPointMap(PointMap &&from); + bool operator< (const HashedPointMap &other) const; - const BackingMap &backingMap() const { return _map; } + const PointMap &backingMap() const { return _map; } }; } // namespace vespalib::metrics diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp index 3769d141516..36cb884290e 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp @@ -7,7 +7,7 @@ namespace metrics { using Guard = std::lock_guard; -const PointMap & +const HashedPointMap & PointMapCollection::lookup(size_t id) const { Guard guard(_lock); @@ -17,7 +17,7 @@ PointMapCollection::lookup(size_t id) const } size_t -PointMapCollection::resolve(PointMap map) +PointMapCollection::resolve(HashedPointMap map) { Guard guard(_lock); size_t nextId = _vec.size(); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h index ce501c9229a..91eb907ee74 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h @@ -12,14 +12,14 @@ namespace metrics { // internal class PointMapCollection { private: - using PointMapMap = std::map; + using PointMapMap = std::map; mutable std::mutex _lock; PointMapMap _map; std::vector _vec; public: - const PointMap &lookup(size_t id) const; - size_t resolve(PointMap map); + const HashedPointMap &lookup(size_t id) const; + size_t resolve(HashedPointMap map); size_t size() const; PointMapCollection() = default; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp index 5f1525782de..8f81dae4eb4 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp @@ -25,7 +25,7 @@ SimpleMetricsManager::SimpleMetricsManager(const SimpleManagerConfig &config, _thread(&SimpleMetricsManager::tickerLoop, this) { if (_maxBuckets < 1) _maxBuckets = 1; - Point empty = pointFrom(PointMap::BackingMap()); + Point empty = pointFrom(PointMap()); assert(empty.id() == 0); } @@ -110,9 +110,9 @@ SimpleMetricsManager::snapshotFrom(const Bucket &bucket) Snapshot snap(s, e); { for (size_t point_id = 0; point_id <= max_point_id; ++point_id) { - const PointMap::BackingMap &map = NameRepo::instance.pointMap(Point(point_id)); + const PointMap &map = NameRepo::instance.pointMap(Point(point_id)); PointSnapshot point; - for (const PointMap::BackingMap::value_type &kv : map) { + for (const PointMap::value_type &kv : map) { point.dimensions.emplace_back(kv.first.as_name(), kv.second.as_value()); } snap.add(point); @@ -187,12 +187,12 @@ SimpleMetricsManager::label(const vespalib::string &value) PointBuilder SimpleMetricsManager::pointBuilder(Point from) { - const PointMap::BackingMap &map = NameRepo::instance.pointMap(from); + const PointMap &map = NameRepo::instance.pointMap(from); return PointBuilder(shared_from_this(), map); } Point -SimpleMetricsManager::pointFrom(PointMap::BackingMap map) +SimpleMetricsManager::pointFrom(PointMap map) { return NameRepo::instance.pointFrom(std::move(map)); } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.h b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.h index 5651a02979a..f41f3355bfa 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.h @@ -70,7 +70,7 @@ public: Dimension dimension(const vespalib::string &name) override; Label label(const vespalib::string &value) override; PointBuilder pointBuilder(Point from) override; - Point pointFrom(PointMap::BackingMap map) override; + Point pointFrom(PointMap map) override; Snapshot snapshot() override; Snapshot totalSnapshot() override; -- cgit v1.2.3 From c22ca093e702812e992c148e0a5016813e5cd3e8 Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Fri, 5 Oct 2018 20:20:44 +0000 Subject: HashedPointMap is only needed PointMapCollection --- .../src/vespa/vespalib/metrics/name_repo.cpp | 5 +-- .../src/vespa/vespalib/metrics/point_map.cpp | 49 +--------------------- .../src/vespa/vespalib/metrics/point_map.h | 13 ------ .../vespalib/metrics/point_map_collection.cpp | 46 ++++++++++++++++++-- .../vespa/vespalib/metrics/point_map_collection.h | 17 +++++++- 5 files changed, 61 insertions(+), 69 deletions(-) (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp index 7db14f3af52..9e3683d465f 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp @@ -53,14 +53,13 @@ NameRepo::labelValue(Label l) const const PointMap& NameRepo::pointMap(Point from) const { - const HashedPointMap &map = _pointMaps.lookup(from.id()); - return map.backingMap(); + return _pointMaps.lookup(from.id()); } Point NameRepo::pointFrom(PointMap map) { - size_t id = _pointMaps.resolve(HashedPointMap(std::move(map))); + size_t id = _pointMaps.resolve(std::move(map)); return Point(id); } diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp index 134123b2685..6e9ab4d1801 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map.cpp @@ -1,49 +1,2 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "point.h" -#include "metrics_manager.h" - -namespace vespalib { -namespace metrics { - -HashedPointMap::HashedPointMap(PointMap &&from) - : _map(std::move(from)), - _hash(0) -{ - for (const PointMap::value_type &entry : _map) { - _hash = (_hash << 7) + (_hash >> 31) + entry.first.id(); - _hash = (_hash << 7) + (_hash >> 31) + entry.second.id(); - } -} - -bool -HashedPointMap::operator< (const HashedPointMap &other) const -{ - // cheap comparison first - if (_hash != other._hash) { - return _hash < other._hash; - } - if (_map.size() != other._map.size()) { - return _map.size() < other._map.size(); - } - // sizes equal, iterate in parallel - for (auto m = _map.begin(), o = other._map.begin(); - m != _map.end(); - ++m, ++o) - { - const Dimension& d1 = m->first; - const Dimension& d2 = o->first; - if (d1 != d2) { - return d1 < d2; - } - const Label &l1 = m->second; - const Label &l2 = o->second; - if (l1 != l2) { - return l1 < l2; - } - } - // equal - return false; -} - -} // namespace vespalib::metrics -} // namespace vespalib +#include "point_map.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map.h b/staging_vespalib/src/vespa/vespalib/metrics/point_map.h index 91c28b292c8..a1063ce944a 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map.h @@ -10,18 +10,5 @@ namespace metrics { using PointMap = std::map; -// internal -class HashedPointMap { -private: - const PointMap _map; - size_t _hash; -public: - HashedPointMap() : _map(), _hash(0) {} - HashedPointMap(PointMap &&from); - bool operator< (const HashedPointMap &other) const; - - const PointMap &backingMap() const { return _map; } -}; - } // namespace vespalib::metrics } // namespace vespalib diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp index 36cb884290e..9909eb04cdc 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp @@ -5,19 +5,59 @@ namespace vespalib { namespace metrics { +HashedPointMap::HashedPointMap(PointMap &&from) + : _map(std::move(from)), + _hash(0) +{ + for (const PointMap::value_type &entry : _map) { + _hash = (_hash << 7) + (_hash >> 31) + entry.first.id(); + _hash = (_hash << 7) + (_hash >> 31) + entry.second.id(); + } +} + +bool +HashedPointMap::operator< (const HashedPointMap &other) const +{ + // cheap comparison first + if (_hash != other._hash) { + return _hash < other._hash; + } + if (_map.size() != other._map.size()) { + return _map.size() < other._map.size(); + } + // sizes equal, iterate in parallel + for (auto m = _map.begin(), o = other._map.begin(); + m != _map.end(); + ++m, ++o) + { + const Dimension& d1 = m->first; + const Dimension& d2 = o->first; + if (d1 != d2) { + return d1 < d2; + } + const Label &l1 = m->second; + const Label &l2 = o->second; + if (l1 != l2) { + return l1 < l2; + } + } + // equal + return false; +} + using Guard = std::lock_guard; -const HashedPointMap & +const PointMap & PointMapCollection::lookup(size_t id) const { Guard guard(_lock); assert(id < _vec.size()); PointMapMap::const_iterator iter = _vec[id]; - return iter->first; + return iter->first.backingMap(); } size_t -PointMapCollection::resolve(HashedPointMap map) +PointMapCollection::resolve(PointMap map) { Guard guard(_lock); size_t nextId = _vec.size(); diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h index 91eb907ee74..3474bff6188 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h @@ -9,6 +9,19 @@ namespace vespalib { namespace metrics { +// internal +class HashedPointMap { +private: + const PointMap _map; + size_t _hash; +public: + HashedPointMap() : _map(), _hash(0) {} + HashedPointMap(PointMap &&from); + bool operator< (const HashedPointMap &other) const; + + const PointMap &backingMap() const { return _map; } +}; + // internal class PointMapCollection { private: @@ -18,8 +31,8 @@ private: PointMapMap _map; std::vector _vec; public: - const HashedPointMap &lookup(size_t id) const; - size_t resolve(HashedPointMap map); + const PointMap &lookup(size_t id) const; + size_t resolve(PointMap map); size_t size() const; PointMapCollection() = default; -- cgit v1.2.3 From 96a953de4aa6c94166c34757b2c727b44375848a Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Fri, 5 Oct 2018 20:29:18 +0000 Subject: add API in Point class also --- staging_vespalib/src/vespa/vespalib/metrics/point.cpp | 19 +++++++++++++++++++ staging_vespalib/src/vespa/vespalib/metrics/point.h | 5 +++++ 2 files changed, 24 insertions(+) (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point.cpp index a5f99a4ba6d..6ad402a1233 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point.cpp @@ -1,10 +1,29 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "point.h" +#include "name_repo.h" namespace vespalib { namespace metrics { Point Point::empty(0); +Point +Point::from_map(const PointMap& map) +{ + return NameRepo::instance.pointFrom(map); +} + +Point +Point::from_map(PointMap&& map) +{ + return NameRepo::instance.pointFrom(std::move(map)); +} + +const PointMap& +Point::as_map() const +{ + return NameRepo::instance.pointMap(*this); +} + } // namespace vespalib::metrics } // namespace vespalib diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point.h b/staging_vespalib/src/vespa/vespalib/metrics/point.h index e50283bd94c..d152d91978e 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point.h @@ -2,6 +2,7 @@ #pragma once #include "handle.h" +#include "point_map.h" namespace vespalib::metrics { @@ -12,6 +13,10 @@ class Point : public Handle { public: static Point empty; explicit Point(size_t id) : Handle(id) {} + + static Point from_map(const PointMap& map); + static Point from_map(PointMap&& map); + const PointMap& as_map() const; }; } // namespace vespalib::metrics -- cgit v1.2.3 From a06fc46c5e71315ab460fb11ef1a6e05816e396a Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Fri, 5 Oct 2018 20:32:06 +0000 Subject: use new API, avoid using NameRepo directly --- staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp | 2 +- .../src/vespa/vespalib/metrics/simple_metrics_manager.cpp | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp index 76c172c9c44..7d99ce8a0a2 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp @@ -60,7 +60,7 @@ PointBuilder::bind(DimensionName dimension, LabelValue label) && Point PointBuilder::build() { - return _owner->pointFrom(PointMap(_map)); + return _owner->pointFrom(_map); } PointBuilder::operator Point() && diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp index 8f81dae4eb4..50dd30efc5a 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp @@ -1,7 +1,6 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #include "simple_metrics_manager.h" #include "simple_tick.h" -#include "name_repo.h" #include LOG_SETUP(".vespalib.metrics.simple_metrics_manager"); @@ -110,7 +109,7 @@ SimpleMetricsManager::snapshotFrom(const Bucket &bucket) Snapshot snap(s, e); { for (size_t point_id = 0; point_id <= max_point_id; ++point_id) { - const PointMap &map = NameRepo::instance.pointMap(Point(point_id)); + const PointMap &map = Point(point_id).as_map(); PointSnapshot point; for (const PointMap::value_type &kv : map) { point.dimensions.emplace_back(kv.first.as_name(), kv.second.as_value()); @@ -187,17 +186,16 @@ SimpleMetricsManager::label(const vespalib::string &value) PointBuilder SimpleMetricsManager::pointBuilder(Point from) { - const PointMap &map = NameRepo::instance.pointMap(from); + const PointMap &map = from.as_map(); return PointBuilder(shared_from_this(), map); } Point SimpleMetricsManager::pointFrom(PointMap map) { - return NameRepo::instance.pointFrom(std::move(map)); + return Point::from_map(std::move(map)); } - void SimpleMetricsManager::tickerLoop() { -- cgit v1.2.3 From b391bbe70f32c125645f39f299a906ff2aaaed9a Mon Sep 17 00:00:00 2001 From: Arne Juul Date: Fri, 5 Oct 2018 20:44:09 +0000 Subject: simplify slightly --- .../vespa/vespalib/metrics/point_map_collection.cpp | 20 ++------------------ .../vespa/vespalib/metrics/point_map_collection.h | 1 - 2 files changed, 2 insertions(+), 19 deletions(-) (limited to 'staging_vespalib/src') diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp index 9909eb04cdc..892a1abcb36 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp @@ -25,24 +25,8 @@ HashedPointMap::operator< (const HashedPointMap &other) const if (_map.size() != other._map.size()) { return _map.size() < other._map.size(); } - // sizes equal, iterate in parallel - for (auto m = _map.begin(), o = other._map.begin(); - m != _map.end(); - ++m, ++o) - { - const Dimension& d1 = m->first; - const Dimension& d2 = o->first; - if (d1 != d2) { - return d1 < d2; - } - const Label &l1 = m->second; - const Label &l2 = o->second; - if (l1 != l2) { - return l1 < l2; - } - } - // equal - return false; + // sizes equal, fall back to std::map::operator< + return _map < other._map; } using Guard = std::lock_guard; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h index 3474bff6188..adbd7f53725 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h @@ -15,7 +15,6 @@ private: const PointMap _map; size_t _hash; public: - HashedPointMap() : _map(), _hash(0) {} HashedPointMap(PointMap &&from); bool operator< (const HashedPointMap &other) const; -- cgit v1.2.3