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
77
78
79
80
81
82
83
84
85
86
87
|
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
/**
* \class metrics::MetricSet
* \ingroup metrics
*
* \brief Class containing a set of metrics.
*
* This is a class to bundle related metrics. Note that the metricsset is
* itself a metric so this generates a tree where metricssets are leaf nodes.
*/
#pragma once
#include "metric.h"
namespace metrics {
class MetricSet : public Metric
{
std::vector<Metric*> _metricOrder; // Keep added order for reporting
bool _registrationAltered; // Set to true if metrics have been
// registered/unregistered since last time
// it was reset
public:
MetricSet(const String& name, Tags dimensions, const String& description) :
MetricSet(name, std::move(dimensions), description, nullptr)
{}
MetricSet(const String& name, Tags dimensions, const String& description, MetricSet* owner);
MetricSet(const MetricSet&, std::vector<Metric::UP> &ownerList, CopyType, MetricSet* owner, bool includeUnused);
// Do not generate default copy constructor or assignment operator
// These would screw up metric registering
MetricSet(const MetricSet&) = delete;
MetricSet& operator=(const MetricSet&) = delete;
~MetricSet();
// If no path, this metric is not registered within another
bool isTopSet() const { return _owner == 0; }
/**
* Returns true if registration has been altered since it was last
* cleared. Used by the metric manager to know when it needs to recalculate
* which consumers will see what.
*/
bool isRegistrationAltered() const { return _registrationAltered; }
/** Clear all registration altered flags. */
void clearRegistrationAltered();
void registerMetric(Metric& m);
void unregisterMetric(Metric& m);
MetricSet* clone(std::vector<Metric::UP> &ownerList, CopyType type, MetricSet* owner, bool includeUnused) const override;
void reset() override;
bool visit(MetricVisitor&, bool tagAsAutoGenerated = false) const override;
void print(std::ostream&, bool verbose, const std::string& indent, uint64_t secondsPassed) const override;
// These should never be called on metrics set.
int64_t getLongValue(stringref id) const override;
double getDoubleValue(stringref id) const override;
const Metric* getMetric(stringref name) const;
Metric* getMetric(stringref name) {
return const_cast<Metric*>(const_cast<const MetricSet*>(this)->getMetric(name));
}
void addToSnapshot(Metric& m, std::vector<Metric::UP> &o) const override { addTo(m, &o); }
const std::vector<Metric*>& getRegisteredMetrics() const { return _metricOrder; }
bool used() const override;
void addMemoryUsage(MemoryConsumption&) const override;
void printDebug(std::ostream&, const std::string& indent="") const override;
bool isMetricSet() const override { return true; }
void addToPart(Metric& m) const override { addTo(m, 0); }
private:
void tagRegistrationAltered();
const Metric* getMetricInternal(stringref name) const;
virtual void addTo(Metric&, std::vector<Metric::UP> *ownerList) const;
};
} // metrics
|