Coverage Report

Created: 2025-04-25 12:58

/root/doris/be/src/util/interval_histogram.cpp
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#include "util/interval_histogram.h"
19
20
#include <algorithm>
21
#include <mutex>
22
#include <numeric>
23
#include <vector>
24
25
#include "gutil/integral_types.h"
26
27
namespace doris {
28
29
template <typename T>
30
484
IntervalHistogramStat<T>::IntervalHistogramStat(size_t N) : window(N) {}
_ZN5doris21IntervalHistogramStatIlEC2Em
Line
Count
Source
30
482
IntervalHistogramStat<T>::IntervalHistogramStat(size_t N) : window(N) {}
_ZN5doris21IntervalHistogramStatIiEC2Em
Line
Count
Source
30
2
IntervalHistogramStat<T>::IntervalHistogramStat(size_t N) : window(N) {}
31
32
template <typename T>
33
10.5k
void IntervalHistogramStat<T>::add(T value) {
34
10.5k
    std::unique_lock<std::shared_mutex> lock(mutex);
35
10.5k
    if (window.full()) {
36
4.62k
        window.pop_front();
37
4.62k
    }
38
10.5k
    window.push_back(value);
39
10.5k
}
_ZN5doris21IntervalHistogramStatIlE3addEl
Line
Count
Source
33
10.4k
void IntervalHistogramStat<T>::add(T value) {
34
10.4k
    std::unique_lock<std::shared_mutex> lock(mutex);
35
10.4k
    if (window.full()) {
36
4.62k
        window.pop_front();
37
4.62k
    }
38
10.4k
    window.push_back(value);
39
10.4k
}
_ZN5doris21IntervalHistogramStatIiE3addEi
Line
Count
Source
33
107
void IntervalHistogramStat<T>::add(T value) {
34
107
    std::unique_lock<std::shared_mutex> lock(mutex);
35
107
    if (window.full()) {
36
2
        window.pop_front();
37
2
    }
38
107
    window.push_back(value);
39
107
}
40
41
template <typename T>
42
3
T IntervalHistogramStat<T>::mean() {
43
3
    std::shared_lock<std::shared_mutex> lock(mutex);
44
3
    if (window.empty()) {
45
0
        return T();
46
0
    }
47
3
    T sum = std::accumulate(window.begin(), window.end(), T());
48
3
    return sum / window.size();
49
3
}
Unexecuted instantiation: _ZN5doris21IntervalHistogramStatIlE4meanEv
_ZN5doris21IntervalHistogramStatIiE4meanEv
Line
Count
Source
42
3
T IntervalHistogramStat<T>::mean() {
43
3
    std::shared_lock<std::shared_mutex> lock(mutex);
44
3
    if (window.empty()) {
45
0
        return T();
46
0
    }
47
3
    T sum = std::accumulate(window.begin(), window.end(), T());
48
3
    return sum / window.size();
49
3
}
50
51
template <typename T>
52
3
T IntervalHistogramStat<T>::median() {
53
3
    std::shared_lock<std::shared_mutex> lock(mutex);
54
3
    if (window.empty()) {
55
0
        return T();
56
0
    }
57
58
3
    std::vector<T> sorted(window.begin(), window.end());
59
3
    std::sort(sorted.begin(), sorted.end());
60
61
3
    size_t mid = sorted.size() / 2;
62
3
    return sorted.size() % 2 == 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
63
3
}
Unexecuted instantiation: _ZN5doris21IntervalHistogramStatIlE6medianEv
_ZN5doris21IntervalHistogramStatIiE6medianEv
Line
Count
Source
52
3
T IntervalHistogramStat<T>::median() {
53
3
    std::shared_lock<std::shared_mutex> lock(mutex);
54
3
    if (window.empty()) {
55
0
        return T();
56
0
    }
57
58
3
    std::vector<T> sorted(window.begin(), window.end());
59
3
    std::sort(sorted.begin(), sorted.end());
60
61
3
    size_t mid = sorted.size() / 2;
62
3
    return sorted.size() % 2 == 0 ? (sorted[mid - 1] + sorted[mid]) / 2 : sorted[mid];
63
3
}
64
65
template <typename T>
66
3
T IntervalHistogramStat<T>::max() {
67
3
    std::shared_lock<std::shared_mutex> lock(mutex);
68
3
    return *std::max_element(window.begin(), window.end());
69
3
}
Unexecuted instantiation: _ZN5doris21IntervalHistogramStatIlE3maxEv
_ZN5doris21IntervalHistogramStatIiE3maxEv
Line
Count
Source
66
3
T IntervalHistogramStat<T>::max() {
67
3
    std::shared_lock<std::shared_mutex> lock(mutex);
68
3
    return *std::max_element(window.begin(), window.end());
69
3
}
70
71
template <typename T>
72
3
T IntervalHistogramStat<T>::min() {
73
3
    std::shared_lock<std::shared_mutex> lock(mutex);
74
3
    return *std::min_element(window.begin(), window.end());
75
3
}
Unexecuted instantiation: _ZN5doris21IntervalHistogramStatIlE3minEv
_ZN5doris21IntervalHistogramStatIiE3minEv
Line
Count
Source
72
3
T IntervalHistogramStat<T>::min() {
73
3
    std::shared_lock<std::shared_mutex> lock(mutex);
74
3
    return *std::min_element(window.begin(), window.end());
75
3
}
76
77
template class doris::IntervalHistogramStat<int64>;
78
template class doris::IntervalHistogramStat<int32>;
79
80
} // namespace doris