GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: histogram-inl.h Lines: 44 48 91.7 %
Date: 2021-09-20 04:12:42 Branches: 9 16 56.2 %

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
  prev_ = 0;
17
2
}
18
19
8
int64_t Histogram::Min() {
20
16
  Mutex::ScopedLock lock(mutex_);
21
8
  return hdr_min(histogram_.get());
22
}
23
24
11
int64_t Histogram::Max() {
25
22
  Mutex::ScopedLock lock(mutex_);
26
11
  return hdr_max(histogram_.get());
27
}
28
29
6
double Histogram::Mean() {
30
12
  Mutex::ScopedLock lock(mutex_);
31
6
  return hdr_mean(histogram_.get());
32
}
33
34
6
double Histogram::Stddev() {
35
12
  Mutex::ScopedLock lock(mutex_);
36
6
  return hdr_stddev(histogram_.get());
37
}
38
39
993
double Histogram::Percentile(double percentile) {
40
993
  Mutex::ScopedLock lock(mutex_);
41
993
  CHECK_GT(percentile, 0);
42
993
  CHECK_LE(percentile, 100);
43
  return static_cast<double>(
44
993
      hdr_value_at_percentile(histogram_.get(), percentile));
45
}
46
47
template <typename Iterator>
48
6
void Histogram::Percentiles(Iterator&& fn) {
49
12
  Mutex::ScopedLock lock(mutex_);
50
  hdr_iter iter;
51
6
  hdr_iter_percentile_init(&iter, histogram_.get(), 1);
52
36
  while (hdr_iter_next(&iter)) {
53
30
    double key = iter.specifics.percentiles.percentile;
54
30
    double value = static_cast<double>(iter.value);
55
30
    fn(key, value);
56
  }
57
6
}
58
59
22
bool Histogram::Record(int64_t value) {
60
44
  Mutex::ScopedLock lock(mutex_);
61
22
  return hdr_record_value(histogram_.get(), value);
62
}
63
64
1760
uint64_t Histogram::RecordDelta() {
65
1760
  Mutex::ScopedLock lock(mutex_);
66
1760
  uint64_t time = uv_hrtime();
67
1760
  uint64_t delta = 0;
68
1760
  if (prev_ > 0) {
69
1757
    delta = time - prev_;
70
1757
    if (delta > 0) {
71

1757
      if (!hdr_record_value(histogram_.get(), delta) && exceeds_ < 0xFFFFFFFF)
72
        exceeds_++;
73
    }
74
  }
75
1760
  prev_ = time;
76
1760
  return delta;
77
}
78
79
size_t Histogram::GetMemorySize() const {
80
  Mutex::ScopedLock lock(mutex_);
81
  return hdr_get_memory_size(histogram_.get());
82
}
83
84
}  // namespace node
85
86
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
87
88
#endif  // SRC_HISTOGRAM_INL_H_