aboutsummaryrefslogtreecommitdiffstats
path: root/searchcore/src/vespa/searchcore/proton/metrics/attribute_metrics.cpp
blob: e2ed0d52ba190477fa51d03c8b8c2c8b14d724cf (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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.

#include "attribute_metrics.h"

namespace proton {

using Entry = AttributeMetrics::Entry;

AttributeMetrics::Entry::Entry(const vespalib::string &attrName)
    : metrics::MetricSet("attribute", {{"field", attrName}}, "Metrics for a given attribute vector", nullptr),
      memoryUsage(this)
{
}

AttributeMetrics::AttributeMetrics(metrics::MetricSet *parent)
    : _parent(parent),
      _attributes()
{
}

Entry::SP
AttributeMetrics::add(const vespalib::string &attrName)
{
    if (get(attrName).get() != nullptr) {
        return Entry::SP();
    }
    Entry::SP result = std::make_shared<Entry>(attrName);
    _attributes.insert(std::make_pair(attrName, result));
    return result;
}

Entry::SP
AttributeMetrics::get(const vespalib::string &attrName) const
{
    auto itr = _attributes.find(attrName);
    if (itr != _attributes.end()) {
        return itr->second;
    }
    return Entry::SP();
}

Entry::SP
AttributeMetrics::remove(const vespalib::string &attrName)
{
    Entry::SP result = get(attrName);
    if (result.get() != nullptr) {
        _attributes.erase(attrName);
    }
    return result;
}

std::vector<Entry::SP>
AttributeMetrics::release()
{
    std::vector<Entry::SP> result;
    for (const auto &attr : _attributes) {
        result.push_back(attr.second);
    }
    _attributes.clear();
    return result;
}

} // namespace proton