aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/metrics/legacy_attribute_metrics.cpp
blob: 7d182e5ccc5c115b4cc992649c6d74e8f70592ee (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2017 Yahoo Holdings. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "legacy_attribute_metrics.h"

namespace proton {

LegacyAttributeMetrics::List::Entry::Entry(const std::string &name)
    : metrics::MetricSet(name, {}, "Attribute vector metrics", 0),
      memoryUsage("memoryusage", {}, "Memory usage", this),
      bitVectors("bitvectors", {}, "Number of bitvectors", this)
{
}

LegacyAttributeMetrics::List::Entry *
LegacyAttributeMetrics::List::add(const std::string &name)
{
    if (metrics.find(name) != metrics.end()) {
        return nullptr;
    }
    auto &pos = metrics[name];
    pos = std::make_unique<Entry>(name);
    return pos.get();
}

LegacyAttributeMetrics::List::Entry *
LegacyAttributeMetrics::List::get(const std::string &name) const
{
    const auto pos = metrics.find(name);
    if (pos == metrics.end()) {
        return nullptr;
    }
    return pos->second.get();
}

LegacyAttributeMetrics::List::Entry::UP
LegacyAttributeMetrics::List::remove(const std::string &name)
{
    auto pos = metrics.find(name);
    if (pos == metrics.end()) {
        return Entry::UP();
    }
    Entry::UP retval = std::move(pos->second);
    metrics.erase(name);
    return retval;
}

std::vector<LegacyAttributeMetrics::List::Entry::UP>
LegacyAttributeMetrics::List::release()
{
    std::vector<Entry::UP> entries;
    for (auto &pos: metrics) {
        entries.push_back(std::move(pos.second));
    }
    metrics.clear();
    return entries;
}

LegacyAttributeMetrics::List::List(metrics::MetricSet *parent)
    : metrics::MetricSet("list", {}, "Metrics per attribute vector", parent),
      metrics()
{
}

LegacyAttributeMetrics::List::~List() = default;

LegacyAttributeMetrics::LegacyAttributeMetrics(metrics::MetricSet *parent)
    : metrics::MetricSet("attributes", {}, "Attribute metrics", parent),
      list(this),
      memoryUsage("memoryusage", {}, "Memory usage for attributes", this),
      bitVectors("bitvectors", {}, "Number of bitvectors for attributes", this)
{
}

LegacyAttributeMetrics::~LegacyAttributeMetrics() = default;

} // namespace proton