diff options
author | Arne Juul <arnej@yahoo-inc.com> | 2018-10-03 13:00:48 +0000 |
---|---|---|
committer | Arne Juul <arnej@yahoo-inc.com> | 2018-10-03 13:00:48 +0000 |
commit | a079d81802d56010c85d9cf144ac87b9717346c4 (patch) | |
tree | 93b948a612ef4d8c86f95f4497a23a8ccbec937d /staging_vespalib | |
parent | 948490aa3556e05e536cf7326dcbce2afc14b49b (diff) |
add NameRepo class
Diffstat (limited to 'staging_vespalib')
3 files changed, 120 insertions, 0 deletions
diff --git a/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt b/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt index 34cc5453304..4a28734b85d 100644 --- a/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt +++ b/staging_vespalib/src/vespa/vespalib/metrics/CMakeLists.txt @@ -18,6 +18,7 @@ vespa_add_library(staging_vespalib_vespalib_metrics OBJECT metrics_manager.cpp metric_types.cpp name_collection.cpp + name_repo.cpp point_builder.cpp point.cpp point_map_collection.cpp diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp new file mode 100644 index 00000000000..f8294661c77 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.cpp @@ -0,0 +1,72 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#include "name_repo.h" + +#include <vespa/log/log.h> +LOG_SETUP(".vespalib.metrics.name_repo"); + +namespace vespalib { +namespace metrics { + +MetricName +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); +} + +Dimension +NameRepo::dimension(const vespalib::string &name) +{ + size_t id = _dimensionNames.resolve(name); + LOG(debug, "dimension name %s -> %zu", name.c_str(), id); + return Dimension(id); +} + +Label +NameRepo::label(const vespalib::string &value) +{ + size_t id = _labelValues.resolve(value); + LOG(debug, "label value %s -> %zu", value.c_str(), id); + return Label(id); +} + +const vespalib::string& +NameRepo::metricName(MetricName metric) +{ + return _metricNames.lookup(metric.id()); +} + +const vespalib::string& +NameRepo::dimensionName(Dimension dim) +{ + return _dimensionNames.lookup(dim.id()); +} + +const vespalib::string& +NameRepo::labelValue(Label l) +{ + return _labelValues.lookup(l.id()); +} + + +const PointMap::BackingMap& +NameRepo::pointMap(Point from) +{ + const PointMap &map = _pointMaps.lookup(from.id()); + return map.backingMap(); +} + +Point +NameRepo::pointFrom(PointMap::BackingMap map) +{ + size_t id = _pointMaps.resolve(PointMap(std::move(map))); + return Point(id); +} + + +NameRepo NameRepo::instance; + + +} // namespace vespalib::metrics +} // namespace vespalib diff --git a/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h new file mode 100644 index 00000000000..6095bea1293 --- /dev/null +++ b/staging_vespalib/src/vespa/vespalib/metrics/name_repo.h @@ -0,0 +1,47 @@ +// Copyright 2018 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +#pragma once + +#include <vespa/vespalib/stllike/string.h> +#include "dimension.h" +#include "label.h" +#include "metric_name.h" +#include "point.h" + +#include "name_collection.h" +#include "point_map_collection.h" + +namespace vespalib { +namespace metrics { + +/** + * Simple repo class + **/ +class NameRepo +{ +private: + NameCollection _metricNames; + NameCollection _dimensionNames; + NameCollection _labelValues; + PointMapCollection _pointMaps; + +public: + NameRepo() = default; + ~NameRepo() = default; + + MetricName 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 PointMap::BackingMap& pointMap(Point from); + Point pointFrom(PointMap::BackingMap map); + + static NameRepo instance; +}; + +} // namespace vespalib::metrics +} // namespace vespalib + |