GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: histogram-inl.h Lines: 56 62 90.3 %
Date: 2022-08-16 04:20:39 Branches: 10 16 62.5 %

Line Branch Exec Source
1
#ifndef SRC_HISTOGRAM_INL_H_
2
#define SRC_HISTOGRAM_INL_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "histogram.h"
7
#include "base_object-inl.h"
8
#include "node_internals.h"
9
10
namespace node {
11
12
2
void Histogram::Reset() {
13
2
  Mutex::ScopedLock lock(mutex_);
14
2
  hdr_reset(histogram_.get());
15
2
  exceeds_ = 0;
16
2
  count_ = 0;
17
2
  prev_ = 0;
18
2
}
19
20
1
double Histogram::Add(const Histogram& other) {
21
1
  Mutex::ScopedLock lock(mutex_);
22
1
  count_ += other.count_;
23
1
  exceeds_ += other.exceeds_;
24
1
  if (other.prev_ > prev_)
25
    prev_ = other.prev_;
26
1
  return static_cast<double>(hdr_add(histogram_.get(), other.histogram_.get()));
27
}
28
29
11
size_t Histogram::Count() const {
30
11
  Mutex::ScopedLock lock(mutex_);
31
11
  return count_;
32
}
33
34
10
int64_t Histogram::Min() const {
35
20
  Mutex::ScopedLock lock(mutex_);
36
10
  return hdr_min(histogram_.get());
37
}
38
39
13
int64_t Histogram::Max() const {
40
26
  Mutex::ScopedLock lock(mutex_);
41
13
  return hdr_max(histogram_.get());
42
}
43
44
6
double Histogram::Mean() const {
45
12
  Mutex::ScopedLock lock(mutex_);
46
6
  return hdr_mean(histogram_.get());
47
}
48
49
6
double Histogram::Stddev() const {
50
12
  Mutex::ScopedLock lock(mutex_);
51
6
  return hdr_stddev(histogram_.get());
52
}
53
54
995
int64_t Histogram::Percentile(double percentile) const {
55
1990
  Mutex::ScopedLock lock(mutex_);
56
995
  CHECK_GT(percentile, 0);
57
995
  CHECK_LE(percentile, 100);
58
995
  return hdr_value_at_percentile(histogram_.get(), percentile);
59
}
60
61
template <typename Iterator>
62
6
void Histogram::Percentiles(Iterator&& fn) {
63
12
  Mutex::ScopedLock lock(mutex_);
64
  hdr_iter iter;
65
6
  hdr_iter_percentile_init(&iter, histogram_.get(), 1);
66
36
  while (hdr_iter_next(&iter)) {
67
30
    double key = iter.specifics.percentiles.percentile;
68
30
    fn(key, iter.value);
69
  }
70
}
71
72
23
bool Histogram::Record(int64_t value) {
73
23
  Mutex::ScopedLock lock(mutex_);
74
23
  bool recorded = hdr_record_value(histogram_.get(), value);
75
23
  if (!recorded)
76
    exceeds_++;
77
  else
78
23
    count_++;
79
23
  return recorded;
80
}
81
82
1764
uint64_t Histogram::RecordDelta() {
83
1764
  Mutex::ScopedLock lock(mutex_);
84
1764
  uint64_t time = uv_hrtime();
85
1764
  int64_t delta = 0;
86
1764
  if (prev_ > 0) {
87
1761
    CHECK_GE(time, prev_);
88
1761
    delta = time - prev_;
89
1761
    if (hdr_record_value(histogram_.get(), delta))
90
1761
      count_++;
91
    else
92
      exceeds_++;
93
  }
94
1764
  prev_ = time;
95
1764
  return delta;
96
}
97
98
size_t Histogram::GetMemorySize() const {
99
  Mutex::ScopedLock lock(mutex_);
100
  return hdr_get_memory_size(histogram_.get());
101
}
102
103
}  // namespace node
104
105
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
106
107
#endif  // SRC_HISTOGRAM_INL_H_