This repository was archived by the owner on Aug 11, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathhistogram-inl.h
More file actions
114 lines (93 loc) · 2.4 KB
/
histogram-inl.h
File metadata and controls
114 lines (93 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#ifndef SRC_HISTOGRAM_INL_H_
#define SRC_HISTOGRAM_INL_H_
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#include "histogram.h"
#include "base_object-inl.h"
#include "node_internals.h"
namespace node {
Histogram::Histogram(int64_t lowest, int64_t highest, int figures) {
CHECK_EQ(0, hdr_init(lowest, highest, figures, &histogram_));
}
Histogram::~Histogram() {
hdr_close(histogram_);
}
void Histogram::Reset() {
hdr_reset(histogram_);
}
bool Histogram::Record(int64_t value) {
return hdr_record_value(histogram_, value);
}
int64_t Histogram::Min() {
return hdr_min(histogram_);
}
int64_t Histogram::Max() {
return hdr_max(histogram_);
}
double Histogram::Mean() {
return hdr_mean(histogram_);
}
double Histogram::Stddev() {
return hdr_stddev(histogram_);
}
double Histogram::Percentile(double percentile) {
CHECK_GT(percentile, 0);
CHECK_LE(percentile, 100);
return static_cast<double>(hdr_value_at_percentile(histogram_, percentile));
}
template <typename Iterator>
void Histogram::Percentiles(Iterator&& fn) {
hdr_iter iter;
hdr_iter_percentile_init(&iter, histogram_, 1);
while (hdr_iter_next(&iter)) {
double key = iter.specifics.percentiles.percentile;
double value = static_cast<double>(iter.value);
fn(key, value);
}
}
HistogramBase::HistogramBase(
Environment* env,
v8::Local<v8::Object> wrap,
int64_t lowest,
int64_t highest,
int figures) :
BaseObject(env, wrap),
Histogram(lowest, highest, figures) {}
bool HistogramBase::RecordDelta() {
uint64_t time = uv_hrtime();
bool ret = true;
if (prev_ > 0) {
int64_t delta = time - prev_;
if (delta > 0) {
ret = Record(delta);
TraceDelta(delta);
if (!ret) {
if (exceeds_ < 0xFFFFFFFF)
exceeds_++;
TraceExceeds(delta);
}
}
}
prev_ = time;
return ret;
}
void HistogramBase::ResetState() {
Reset();
exceeds_ = 0;
prev_ = 0;
}
HistogramBase* HistogramBase::New(
Environment* env,
int64_t lowest,
int64_t highest,
int figures) {
CHECK_LE(lowest, highest);
CHECK_GT(figures, 0);
v8::Local<v8::Object> obj;
auto tmpl = env->histogram_ctor_template();
if (!tmpl->NewInstance(env->context()).ToLocal(&obj))
return nullptr;
return new HistogramBase(env, obj, lowest, highest, figures);
}
} // namespace node
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
#endif // SRC_HISTOGRAM_INL_H_