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-06-02 04:11:51 Branches: 11 18 61.1 %

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
8
int64_t Histogram::Min() {
20
16
  Mutex::ScopedLock lock(mutex_);
21
16
  return hdr_min(histogram_.get());
22
}
23
24
11
int64_t Histogram::Max() {
25
22
  Mutex::ScopedLock lock(mutex_);
26
22
  return hdr_max(histogram_.get());
27
}
28
29
6
double Histogram::Mean() {
30
12
  Mutex::ScopedLock lock(mutex_);
31
12
  return hdr_mean(histogram_.get());
32
}
33
34
6
double Histogram::Stddev() {
35
12
  Mutex::ScopedLock lock(mutex_);
36
12
  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
3
void Histogram::Percentiles(Iterator&& fn) {
49
6
  Mutex::ScopedLock lock(mutex_);
50
  hdr_iter iter;
51
3
  hdr_iter_percentile_init(&iter, histogram_.get(), 1);
52

33
  while (hdr_iter_next(&iter)) {
53
15
    double key = iter.specifics.percentiles.percentile;
54
15
    double value = static_cast<double>(iter.value);
55
15
    fn(key, value);
56
  }
57
3
}
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
1769
uint64_t Histogram::RecordDelta() {
65
3538
  Mutex::ScopedLock lock(mutex_);
66
1769
  uint64_t time = uv_hrtime();
67
1769
  uint64_t delta = 0;
68
1769
  if (prev_ > 0) {
69
1766
    delta = time - prev_;
70
1766
    if (delta > 0) {
71

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