9
9
10
10
namespace node {
11
11
12
- inline Histogram::Histogram (int64_t lowest, int64_t highest, int figures) {
12
+ Histogram::Histogram (int64_t lowest, int64_t highest, int figures) {
13
13
CHECK_EQ (0 , hdr_init (lowest, highest, figures, &histogram_));
14
14
}
15
15
16
- inline Histogram::~Histogram () {
16
+ Histogram::~Histogram () {
17
17
hdr_close (histogram_);
18
18
}
19
19
20
- inline void Histogram::Reset () {
20
+ void Histogram::Reset () {
21
21
hdr_reset (histogram_);
22
22
}
23
23
24
- inline bool Histogram::Record (int64_t value) {
24
+ bool Histogram::Record (int64_t value) {
25
25
return hdr_record_value (histogram_, value);
26
26
}
27
27
28
- inline int64_t Histogram::Min () {
28
+ int64_t Histogram::Min () {
29
29
return hdr_min (histogram_);
30
30
}
31
31
32
- inline int64_t Histogram::Max () {
32
+ int64_t Histogram::Max () {
33
33
return hdr_max (histogram_);
34
34
}
35
35
36
- inline double Histogram::Mean () {
36
+ double Histogram::Mean () {
37
37
return hdr_mean (histogram_);
38
38
}
39
39
40
- inline double Histogram::Stddev () {
40
+ double Histogram::Stddev () {
41
41
return hdr_stddev (histogram_);
42
42
}
43
43
44
- inline double Histogram::Percentile (double percentile) {
44
+ double Histogram::Percentile (double percentile) {
45
45
CHECK_GT (percentile, 0 );
46
46
CHECK_LE (percentile, 100 );
47
47
return static_cast <double >(hdr_value_at_percentile (histogram_, percentile));
48
48
}
49
49
50
- inline void Histogram::Percentiles (std::function<void (double , double )> fn) {
50
+ template <typename Iterator>
51
+ void Histogram::Percentiles (Iterator&& fn) {
51
52
hdr_iter iter;
52
53
hdr_iter_percentile_init (&iter, histogram_, 1 );
53
54
while (hdr_iter_next (&iter)) {
@@ -57,7 +58,7 @@ inline void Histogram::Percentiles(std::function<void(double, double)> fn) {
57
58
}
58
59
}
59
60
60
- inline HistogramBase::HistogramBase (
61
+ HistogramBase::HistogramBase (
61
62
Environment* env,
62
63
v8::Local<v8::Object> wrap,
63
64
int64_t lowest,
@@ -66,7 +67,7 @@ inline HistogramBase::HistogramBase(
66
67
BaseObject (env, wrap),
67
68
Histogram (lowest, highest, figures) {}
68
69
69
- inline bool HistogramBase::RecordDelta () {
70
+ bool HistogramBase::RecordDelta () {
70
71
uint64_t time = uv_hrtime ();
71
72
bool ret = true ;
72
73
if (prev_ > 0 ) {
@@ -85,110 +86,13 @@ inline bool HistogramBase::RecordDelta() {
85
86
return ret;
86
87
}
87
88
88
- inline void HistogramBase::ResetState () {
89
+ void HistogramBase::ResetState () {
89
90
Reset ();
90
91
exceeds_ = 0 ;
91
92
prev_ = 0 ;
92
93
}
93
94
94
- inline void HistogramBase::HistogramMin (
95
- const v8::FunctionCallbackInfo<v8::Value>& args) {
96
- HistogramBase* histogram;
97
- ASSIGN_OR_RETURN_UNWRAP (&histogram, args.Holder ());
98
- double value = static_cast <double >(histogram->Min ());
99
- args.GetReturnValue ().Set (value);
100
- }
101
-
102
- inline void HistogramBase::HistogramMax (
103
- const v8::FunctionCallbackInfo<v8::Value>& args) {
104
- HistogramBase* histogram;
105
- ASSIGN_OR_RETURN_UNWRAP (&histogram, args.Holder ());
106
- double value = static_cast <double >(histogram->Max ());
107
- args.GetReturnValue ().Set (value);
108
- }
109
-
110
- inline void HistogramBase::HistogramMean (
111
- const v8::FunctionCallbackInfo<v8::Value>& args) {
112
- HistogramBase* histogram;
113
- ASSIGN_OR_RETURN_UNWRAP (&histogram, args.Holder ());
114
- args.GetReturnValue ().Set (histogram->Mean ());
115
- }
116
-
117
- inline void HistogramBase::HistogramExceeds (
118
- const v8::FunctionCallbackInfo<v8::Value>& args) {
119
- HistogramBase* histogram;
120
- ASSIGN_OR_RETURN_UNWRAP (&histogram, args.Holder ());
121
- double value = static_cast <double >(histogram->Exceeds ());
122
- args.GetReturnValue ().Set (value);
123
- }
124
-
125
- inline void HistogramBase::HistogramStddev (
126
- const v8::FunctionCallbackInfo<v8::Value>& args) {
127
- HistogramBase* histogram;
128
- ASSIGN_OR_RETURN_UNWRAP (&histogram, args.Holder ());
129
- args.GetReturnValue ().Set (histogram->Stddev ());
130
- }
131
-
132
- inline void HistogramBase::HistogramPercentile (
133
- const v8::FunctionCallbackInfo<v8::Value>& args) {
134
- HistogramBase* histogram;
135
- ASSIGN_OR_RETURN_UNWRAP (&histogram, args.Holder ());
136
- CHECK (args[0 ]->IsNumber ());
137
- double percentile = args[0 ].As <v8::Number>()->Value ();
138
- args.GetReturnValue ().Set (histogram->Percentile (percentile));
139
- }
140
-
141
- inline void HistogramBase::HistogramPercentiles (
142
- const v8::FunctionCallbackInfo<v8::Value>& args) {
143
- Environment* env = Environment::GetCurrent (args);
144
- HistogramBase* histogram;
145
- ASSIGN_OR_RETURN_UNWRAP (&histogram, args.Holder ());
146
- CHECK (args[0 ]->IsMap ());
147
- v8::Local<v8::Map> map = args[0 ].As <v8::Map>();
148
- histogram->Percentiles ([&](double key, double value) {
149
- map->Set (
150
- env->context (),
151
- v8::Number::New (env->isolate (), key),
152
- v8::Number::New (env->isolate (), value)).IsEmpty ();
153
- });
154
- }
155
-
156
- inline void HistogramBase::HistogramReset (
157
- const v8::FunctionCallbackInfo<v8::Value>& args) {
158
- HistogramBase* histogram;
159
- ASSIGN_OR_RETURN_UNWRAP (&histogram, args.Holder ());
160
- histogram->ResetState ();
161
- }
162
-
163
- inline void HistogramBase::Initialize (Environment* env) {
164
- // Guard against multiple initializations
165
- if (!env->histogram_ctor_template ().IsEmpty ())
166
- return ;
167
-
168
- v8::Local<v8::String> classname =
169
- FIXED_ONE_BYTE_STRING (env->isolate (), " Histogram" );
170
-
171
- v8::Local<v8::FunctionTemplate> histogram =
172
- v8::FunctionTemplate::New (env->isolate ());
173
- histogram->SetClassName (classname);
174
-
175
- v8::Local<v8::ObjectTemplate> histogramt =
176
- histogram->InstanceTemplate ();
177
-
178
- histogramt->SetInternalFieldCount (1 );
179
- env->SetProtoMethod (histogram, " exceeds" , HistogramExceeds);
180
- env->SetProtoMethod (histogram, " min" , HistogramMin);
181
- env->SetProtoMethod (histogram, " max" , HistogramMax);
182
- env->SetProtoMethod (histogram, " mean" , HistogramMean);
183
- env->SetProtoMethod (histogram, " stddev" , HistogramStddev);
184
- env->SetProtoMethod (histogram, " percentile" , HistogramPercentile);
185
- env->SetProtoMethod (histogram, " percentiles" , HistogramPercentiles);
186
- env->SetProtoMethod (histogram, " reset" , HistogramReset);
187
-
188
- env->set_histogram_ctor_template (histogramt);
189
- }
190
-
191
- inline HistogramBase* HistogramBase::New (
95
+ HistogramBase* HistogramBase::New (
192
96
Environment* env,
193
97
int64_t lowest,
194
98
int64_t highest,
0 commit comments