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