diff options
author | HÃ¥vard Pettersen <havardpe@gmail.com> | 2018-10-08 12:44:55 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-10-08 12:44:55 +0200 |
commit | b568099cd11227ce015841594d0b2a050355f051 (patch) | |
tree | 02996dd3c5b135240385665aa8a4176c3dfe3d10 | |
parent | 678fef85eb8f67049ba57046bcf3579ac1f7f6e4 (diff) | |
parent | b391bbe70f32c125645f39f299a906ff2aaaed9a (diff) |
Merge pull request #7238 from vespa-engine/arnej/rename-metrics-classes
Arnej/rename metrics classes
34 files changed, 215 insertions, 158 deletions
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 4a28734b85d..5112286b359 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt +++ b/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt @@ -13,8 +13,8 @@ vespa_add_library(staging_vespalib_vespalib_metrics OBJECT handle.cpp json_formatter.cpp label.cpp - metric_identifier.cpp - metric_name.cpp + metric_point_id.cpp + metric_id.cpp metrics_manager.cpp metric_types.cpp name_collection.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<typename T::sample_type> &source) { using Aggregator = typename T::aggregator_type; using Sample = typename T::sample_type; - using Map = std::map<MetricIdentifier, Aggregator>; + using Map = std::map<MetricPointId, Aggregator>; 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 <mutex> #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..192a08aba66 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 <memory> -#include "metric_identifier.h" +#include "metric_point_id.h" #include "point.h" namespace vespalib { @@ -17,14 +17,14 @@ class CounterAggregator; **/ class Counter { std::shared_ptr<MetricsManager> _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<MetricsManager> m, MetricName id) + Counter(std::shared_ptr<MetricsManager> m, MetricId id) : _manager(std::move(m)), _id(id) {} @@ -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/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<DimensionTag>; +struct Dimension : Handle<DimensionTag> +{ + 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/dummy_metrics_manager.h b/staging_vespalib/src/vespa/vespalib/metrics/dummy_metrics_manager.h index 52e9c6a608c..e4ca1e0ec49 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 { @@ -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/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..c4542ac87e4 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 <memory> -#include "metric_identifier.h" +#include "metric_point_id.h" #include "point.h" namespace vespalib { @@ -17,9 +17,9 @@ class GaugeAggregator; class Gauge { private: std::shared_ptr<MetricsManager> _manager; - MetricName _id; + MetricId _id; public: - Gauge(std::shared_ptr<MetricsManager> m, MetricName id) + Gauge(std::shared_ptr<MetricsManager> m, MetricId id) : _manager(std::move(m)), _id(id) {} @@ -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/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<LabelTag>; +struct Label : Handle<LabelTag> +{ + 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 new file mode 100644 index 00000000000..2b8c0705a9f --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.cpp @@ -0,0 +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_name.h b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.h index 60dfa0aa00f..5f337e6decd 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_name.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_id.h @@ -2,14 +2,20 @@ #pragma once #include "handle.h" +#include <vespa/vespalib/stllike/string.h> namespace vespalib::metrics { -struct MetricNameTag {}; +struct MetricIdTag {}; /** * Opaque handle representing an uniquely named metric. **/ -using MetricName = Handle<MetricNameTag>; +struct MetricId : Handle<MetricIdTag> +{ + explicit MetricId(size_t id) : Handle(id) {} + static MetricId from_name(const vespalib::string& name); + const vespalib::string& as_name() const; +}; } // namespace vespalib::metrics 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_name.cpp b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.cpp index 2a58d55e945..90ecabdb75f 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_name.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.cpp @@ -1,2 +1,2 @@ // Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. -#include "metric_name.h" +#include "metric_point_id.h" diff --git a/staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.h b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h index 0fc5af41a81..f9d788a0f92 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/metric_identifier.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/metric_point_id.h @@ -1,35 +1,35 @@ // 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 <functional> namespace vespalib { namespace metrics { -// internal -struct MetricIdentifier { - const MetricName _name; +/** class to use as a map key, identifying a metric and a point */ +struct MetricPointId { + const MetricId _name; const Point _point; - MetricIdentifier() = delete; + MetricPointId() = delete; - MetricIdentifier(MetricName name, Point point) + MetricPointId(MetricId name, Point point) : _name(name), _point(point) {} - bool operator< (const MetricIdentifier &other) const { + bool operator< (const MetricPointId &other) const { if (_name != other._name) { return _name < other._name; } return _point < other._point; } - bool operator== (const MetricIdentifier &other) const { + bool operator== (const MetricPointId &other) const { return (_name == other._name && _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/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 f8294661c77..9e3683d465f 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,35 +32,34 @@ NameRepo::label(const vespalib::string &value) } const vespalib::string& -NameRepo::metricName(MetricName 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) +const PointMap& +NameRepo::pointMap(Point from) const { - const PointMap &map = _pointMaps.lookup(from.id()); - return map.backingMap(); + return _pointMaps.lookup(from.id()); } Point -NameRepo::pointFrom(PointMap::BackingMap map) +NameRepo::pointFrom(PointMap map) { - size_t id = _pointMaps.resolve(PointMap(std::move(map))); + size_t id = _pointMaps.resolve(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 f6972091ff1..217fc2e3219 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 <vespa/vespalib/stllike/string.h> #include "dimension.h" #include "label.h" -#include "metric_name.h" +#include "metric_id.h" #include "point.h" #include "name_collection.h" @@ -28,16 +28,16 @@ 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& 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); - 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.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<Point> { public: static Point empty; explicit Point(size_t id) : Handle<Point>(id) {} + + static Point from_map(const PointMap& map); + static Point from_map(PointMap&& map); + const PointMap& as_map() const; }; } // namespace vespalib::metrics diff --git a/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp b/staging_vespalib/src/vespa/vespalib/metrics/point_builder.cpp index a89336b4399..7d99ce8a0a2 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<MetricsManager> m) {} PointBuilder::PointBuilder(std::shared_ptr<MetricsManager> 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(_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<MetricsManager> _owner; - PointMap::BackingMap _map; + PointMap _map; public: // for use from MetricsManager PointBuilder(std::shared_ptr<MetricsManager> m); - PointBuilder(std::shared_ptr<MetricsManager> m, const PointMap::BackingMap &from); + PointBuilder(std::shared_ptr<MetricsManager> 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..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 { - -PointMap::PointMap(BackingMap &&from) - : _map(std::move(from)), - _hash(0) -{ - for (const BackingMap::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 -{ - // 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 2ed50a85842..a1063ce944a 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map.h @@ -8,20 +8,7 @@ namespace vespalib { namespace metrics { -// internal -class PointMap { -public: - using BackingMap = std::map<Dimension, Label>; -private: - const PointMap::BackingMap _map; - size_t _hash; -public: - PointMap() : _map(), _hash(0) {} - PointMap(BackingMap &&from); - bool operator< (const PointMap &other) const; - - const BackingMap &backingMap() const { return _map; } -}; +using PointMap = std::map<Dimension, Label>; } // 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 7b09fbf7746..892a1abcb36 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.cpp @@ -5,15 +5,39 @@ 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, fall back to std::map::operator< + return _map < other._map; +} + using Guard = std::lock_guard<std::mutex>; const PointMap & -PointMapCollection::lookup(size_t id) +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 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..adbd7f53725 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/point_map_collection.h @@ -10,15 +10,27 @@ namespace vespalib { namespace metrics { // internal +class HashedPointMap { +private: + const PointMap _map; + size_t _hash; +public: + HashedPointMap(PointMap &&from); + bool operator< (const HashedPointMap &other) const; + + const PointMap &backingMap() const { return _map; } +}; + +// internal class PointMapCollection { private: - using PointMapMap = std::map<PointMap, size_t>; + using PointMapMap = std::map<HashedPointMap, size_t>; mutable std::mutex _lock; PointMapMap _map; std::vector<PointMapMap::const_iterator> _vec; public: - const PointMap &lookup(size_t id); + const PointMap &lookup(size_t id) const; size_t resolve(PointMap map); size_t size() const; diff --git a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h index 6e6cff55b1f..34959146928 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics.h @@ -13,8 +13,8 @@ #include "gauge.h" #include "json_formatter.h" #include "label.h" -#include "metric_identifier.h" -#include "metric_name.h" +#include "metric_point_id.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..50dd30efc5a 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp +++ b/staging_vespalib/src/vespa/vespalib/metrics/simple_metrics_manager.cpp @@ -24,7 +24,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); } @@ -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 = 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 +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 = 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); @@ -109,25 +109,25 @@ 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 = Point(point_id).as_map(); PointSnapshot point; - for (const PointMap::BackingMap::value_type &kv : map) { - point.dimensions.emplace_back(nameFor(kv.first), valueFor(kv.second)); + for (const PointMap::value_type &kv : map) { + point.dimensions.emplace_back(kv.first.as_name(), kv.second.as_value()); } snap.add(point); } } 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); + const vespalib::string &name = mn.as_name(); 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); + const vespalib::string &name = mn.as_name(); GaugeSnapshot val(name, snap.points()[pi], entry); snap.add(val); } @@ -170,7 +170,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 +178,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; } @@ -186,17 +186,16 @@ SimpleMetricsManager::label(const vespalib::string &value) PointBuilder SimpleMetricsManager::pointBuilder(Point from) { - const PointMap::BackingMap &map = NameRepo::instance.pointMap(from); + const PointMap &map = from.as_map(); return PointBuilder(shared_from_this(), map); } Point -SimpleMetricsManager::pointFrom(PointMap::BackingMap map) +SimpleMetricsManager::pointFrom(PointMap map) { - return NameRepo::instance.pointFrom(std::move(map)); + return Point::from_map(std::move(map)); } - void SimpleMetricsManager::tickerLoop() { 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..f41f3355bfa 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 <memory> #include <thread> #include <vespa/vespalib/stllike/string.h> -#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; @@ -78,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; |