aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/vespa/vespalib/metrics/current_samples.cpp
blob: 67d56d6f7488712e4c9cc2784708d42ac00653e0 (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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include "current_samples.h"

namespace vespalib {
namespace metrics {

using Guard = std::lock_guard<std::mutex>;

void
CurrentSamples::add(Counter::Increment inc)
{
    Guard guard(lock);
    counterIncrements.add(inc);
}

void
CurrentSamples::sample(Gauge::Measurement value)
{
    Guard guard(lock);
    gaugeMeasurements.add(value);
}

void
CurrentSamples::extract(CurrentSamples &into)
{
    Guard guard(lock);
    swap(into.counterIncrements, counterIncrements);
    swap(into.gaugeMeasurements, gaugeMeasurements);
}

} // namespace vespalib::metrics
} // namespace vespalib