GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/histogram-inl.h Lines: 44 48 91.7 %
Date: 2021-05-04 04:12:26 Branches: 9 18 50.0 %

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
4
  Mutex::ScopedLock lock(mutex_);
14
2
  hdr_reset(histogram_.get());
15
2
  exceeds_ = 0;
16
2
  prev_ = 0;
17
2
}
18
19
7
int64_t Histogram::Min() {
20
14
  Mutex::ScopedLock lock(mutex_);
21
14
  return hdr_min(histogram_.get());
22
}
23
24
10
int64_t Histogram::Max() {
25
20
  Mutex::ScopedLock lock(mutex_);
26
20
  return hdr_max(histogram_.get());
27
}
28
29
5
double Histogram::Mean() {
30
10
  Mutex::ScopedLock lock(mutex_);
31
10
  return hdr_mean(histogram_.get());
32
}
33
34
5
double Histogram::Stddev() {
35
10
  Mutex::ScopedLock lock(mutex_);
36
10
  return hdr_stddev(histogram_.get());
37
}
38
39
993
double Histogram::Percentile(double percentile) {
40
1986
  Mutex::ScopedLock lock(mutex_);
41
993
  CHECK_GT(percentile, 0);
42
993
  CHECK_LE(percentile, 100);
43
  return static_cast<double>(
44
1986
      hdr_value_at_percentile(histogram_.get(), percentile));
45
}
46
47
template <typename Iterator>
48
2
void Histogram::Percentiles(Iterator&& fn) {
49
4
  Mutex::ScopedLock lock(mutex_);
50
  hdr_iter iter;
51
2
  hdr_iter_percentile_init(&iter, histogram_.get(), 1);
52

30
  while (hdr_iter_next(&iter)) {
53
14
    double key = iter.specifics.percentiles.percentile;
54
14
    double value = static_cast<double>(iter.value);
55
14
    fn(key, value);
56
  }
57
2
}
58
59
22
bool Histogram::Record(int64_t value) {
60
44
  Mutex::ScopedLock lock(mutex_);
61
44
  return hdr_record_value(histogram_.get(), value);
62
}
63
64
1773
uint64_t Histogram::RecordDelta() {
65
3546
  Mutex::ScopedLock lock(mutex_);
66
1773
  uint64_t time = uv_hrtime();
67
1773
  uint64_t delta = 0;
68
1773
  if (prev_ > 0) {
69
1770
    delta = time - prev_;
70
1770
    if (delta > 0) {
71

1770
      if (!hdr_record_value(histogram_.get(), delta) && exceeds_ < 0xFFFFFFFF)
72
        exceeds_++;
73
    }
74
  }
75
1773
  prev_ = time;
76
3546
  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_