File: | out/../src/histogram.cc |
Warning: | line 593, column 11 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | #include "histogram.h" // NOLINT(build/include_inline) | |||
2 | #include "base_object-inl.h" | |||
3 | #include "histogram-inl.h" | |||
4 | #include "memory_tracker-inl.h" | |||
5 | #include "node_errors.h" | |||
6 | #include "node_external_reference.h" | |||
7 | ||||
8 | namespace node { | |||
9 | ||||
10 | using v8::BigInt; | |||
11 | using v8::FunctionCallbackInfo; | |||
12 | using v8::FunctionTemplate; | |||
13 | using v8::Integer; | |||
14 | using v8::Local; | |||
15 | using v8::Map; | |||
16 | using v8::Number; | |||
17 | using v8::Object; | |||
18 | using v8::String; | |||
19 | using v8::Uint32; | |||
20 | using v8::Value; | |||
21 | ||||
22 | Histogram::Histogram(const Options& options) { | |||
23 | hdr_histogram* histogram; | |||
24 | CHECK_EQ(0, hdr_init(options.lowest,do { if (__builtin_expect(!!(!((0) == (hdr_init(options.lowest , options.highest, options.figures, &histogram)))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "27", "(0) == (hdr_init(options.lowest, options.highest, options.figures, &histogram))" , __PRETTY_FUNCTION__ }; node::Assert(args); } while (0); } } while (0) | |||
25 | options.highest,do { if (__builtin_expect(!!(!((0) == (hdr_init(options.lowest , options.highest, options.figures, &histogram)))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "27", "(0) == (hdr_init(options.lowest, options.highest, options.figures, &histogram))" , __PRETTY_FUNCTION__ }; node::Assert(args); } while (0); } } while (0) | |||
26 | options.figures,do { if (__builtin_expect(!!(!((0) == (hdr_init(options.lowest , options.highest, options.figures, &histogram)))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "27", "(0) == (hdr_init(options.lowest, options.highest, options.figures, &histogram))" , __PRETTY_FUNCTION__ }; node::Assert(args); } while (0); } } while (0) | |||
27 | &histogram))do { if (__builtin_expect(!!(!((0) == (hdr_init(options.lowest , options.highest, options.figures, &histogram)))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "27", "(0) == (hdr_init(options.lowest, options.highest, options.figures, &histogram))" , __PRETTY_FUNCTION__ }; node::Assert(args); } while (0); } } while (0); | |||
28 | histogram_.reset(histogram); | |||
29 | } | |||
30 | ||||
31 | void Histogram::MemoryInfo(MemoryTracker* tracker) const { | |||
32 | tracker->TrackFieldWithSize("histogram", GetMemorySize()); | |||
33 | } | |||
34 | ||||
35 | HistogramImpl::HistogramImpl(const Histogram::Options& options) | |||
36 | : histogram_(new Histogram(options)) {} | |||
37 | ||||
38 | HistogramImpl::HistogramImpl(std::shared_ptr<Histogram> histogram) | |||
39 | : histogram_(std::move(histogram)) {} | |||
40 | ||||
41 | HistogramBase::HistogramBase( | |||
42 | Environment* env, | |||
43 | Local<Object> wrap, | |||
44 | const Histogram::Options& options) | |||
45 | : BaseObject(env, wrap), | |||
46 | HistogramImpl(options) { | |||
47 | MakeWeak(); | |||
48 | } | |||
49 | ||||
50 | HistogramBase::HistogramBase( | |||
51 | Environment* env, | |||
52 | Local<Object> wrap, | |||
53 | std::shared_ptr<Histogram> histogram) | |||
54 | : BaseObject(env, wrap), | |||
55 | HistogramImpl(std::move(histogram)) { | |||
56 | MakeWeak(); | |||
57 | } | |||
58 | ||||
59 | void HistogramBase::MemoryInfo(MemoryTracker* tracker) const { | |||
60 | tracker->TrackField("histogram", histogram()); | |||
61 | } | |||
62 | ||||
63 | void HistogramBase::GetCount(const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
64 | HistogramBase* histogram; | |||
65 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
66 | double value = static_cast<double>((*histogram)->Count()); | |||
67 | args.GetReturnValue().Set(value); | |||
68 | } | |||
69 | ||||
70 | void HistogramBase::GetCountBigInt( | |||
71 | const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
72 | Environment* env = Environment::GetCurrent(args); | |||
73 | HistogramBase* histogram; | |||
74 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
75 | args.GetReturnValue().Set( | |||
76 | BigInt::NewFromUnsigned(env->isolate(), (*histogram)->Count())); | |||
77 | } | |||
78 | ||||
79 | void HistogramBase::GetMin(const FunctionCallbackInfo<Value>& args) { | |||
80 | HistogramBase* histogram; | |||
81 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
82 | double value = static_cast<double>((*histogram)->Min()); | |||
83 | args.GetReturnValue().Set(value); | |||
84 | } | |||
85 | ||||
86 | void HistogramBase::GetMinBigInt(const FunctionCallbackInfo<Value>& args) { | |||
87 | Environment* env = Environment::GetCurrent(args); | |||
88 | HistogramBase* histogram; | |||
89 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
90 | args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Min())); | |||
91 | } | |||
92 | ||||
93 | void HistogramBase::GetMax(const FunctionCallbackInfo<Value>& args) { | |||
94 | HistogramBase* histogram; | |||
95 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
96 | double value = static_cast<double>((*histogram)->Max()); | |||
97 | args.GetReturnValue().Set(value); | |||
98 | } | |||
99 | ||||
100 | void HistogramBase::GetMaxBigInt(const FunctionCallbackInfo<Value>& args) { | |||
101 | Environment* env = Environment::GetCurrent(args); | |||
102 | HistogramBase* histogram; | |||
103 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
104 | args.GetReturnValue().Set( | |||
105 | BigInt::New(env->isolate(), (*histogram)->Max())); | |||
106 | } | |||
107 | ||||
108 | void HistogramBase::GetMean(const FunctionCallbackInfo<Value>& args) { | |||
109 | HistogramBase* histogram; | |||
110 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
111 | args.GetReturnValue().Set((*histogram)->Mean()); | |||
112 | } | |||
113 | ||||
114 | void HistogramBase::GetExceeds(const FunctionCallbackInfo<Value>& args) { | |||
115 | HistogramBase* histogram; | |||
116 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
117 | double value = static_cast<double>((*histogram)->Exceeds()); | |||
118 | args.GetReturnValue().Set(value); | |||
119 | } | |||
120 | ||||
121 | void HistogramBase::GetExceedsBigInt(const FunctionCallbackInfo<Value>& args) { | |||
122 | Environment* env = Environment::GetCurrent(args); | |||
123 | HistogramBase* histogram; | |||
124 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
125 | args.GetReturnValue().Set( | |||
126 | BigInt::NewFromUnsigned(env->isolate(), (*histogram)->Exceeds())); | |||
127 | } | |||
128 | ||||
129 | void HistogramBase::GetStddev(const FunctionCallbackInfo<Value>& args) { | |||
130 | HistogramBase* histogram; | |||
131 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
132 | args.GetReturnValue().Set((*histogram)->Stddev()); | |||
133 | } | |||
134 | ||||
135 | void HistogramBase::GetPercentile(const FunctionCallbackInfo<Value>& args) { | |||
136 | HistogramBase* histogram; | |||
137 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
138 | CHECK(args[0]->IsNumber())do { if (__builtin_expect(!!(!(args[0]->IsNumber())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "138", "args[0]->IsNumber()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
139 | double percentile = args[0].As<Number>()->Value(); | |||
140 | double value = static_cast<double>((*histogram)->Percentile(percentile)); | |||
141 | args.GetReturnValue().Set(value); | |||
142 | } | |||
143 | ||||
144 | void HistogramBase::GetPercentileBigInt( | |||
145 | const FunctionCallbackInfo<Value>& args) { | |||
146 | Environment* env = Environment::GetCurrent(args); | |||
147 | HistogramBase* histogram; | |||
148 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
149 | CHECK(args[0]->IsNumber())do { if (__builtin_expect(!!(!(args[0]->IsNumber())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "149", "args[0]->IsNumber()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
150 | double percentile = args[0].As<Number>()->Value(); | |||
151 | int64_t value = (*histogram)->Percentile(percentile); | |||
152 | args.GetReturnValue().Set(BigInt::New(env->isolate(), value)); | |||
153 | } | |||
154 | ||||
155 | void HistogramBase::GetPercentiles(const FunctionCallbackInfo<Value>& args) { | |||
156 | Environment* env = Environment::GetCurrent(args); | |||
157 | HistogramBase* histogram; | |||
158 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
159 | CHECK(args[0]->IsMap())do { if (__builtin_expect(!!(!(args[0]->IsMap())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "159", "args[0]->IsMap()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
160 | Local<Map> map = args[0].As<Map>(); | |||
161 | (*histogram)->Percentiles([map, env](double key, int64_t value) { | |||
162 | USE(map->Set( | |||
163 | env->context(), | |||
164 | Number::New(env->isolate(), key), | |||
165 | Number::New(env->isolate(), static_cast<double>(value)))); | |||
166 | }); | |||
167 | } | |||
168 | ||||
169 | void HistogramBase::GetPercentilesBigInt( | |||
170 | const FunctionCallbackInfo<Value>& args) { | |||
171 | Environment* env = Environment::GetCurrent(args); | |||
172 | HistogramBase* histogram; | |||
173 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
174 | CHECK(args[0]->IsMap())do { if (__builtin_expect(!!(!(args[0]->IsMap())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "174", "args[0]->IsMap()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
175 | Local<Map> map = args[0].As<Map>(); | |||
176 | (*histogram)->Percentiles([map, env](double key, int64_t value) { | |||
177 | USE(map->Set( | |||
178 | env->context(), | |||
179 | Number::New(env->isolate(), key), | |||
180 | BigInt::New(env->isolate(), value))); | |||
181 | }); | |||
182 | } | |||
183 | ||||
184 | void HistogramBase::DoReset(const FunctionCallbackInfo<Value>& args) { | |||
185 | HistogramBase* histogram; | |||
186 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
187 | (*histogram)->Reset(); | |||
188 | } | |||
189 | ||||
190 | void HistogramBase::RecordDelta(const FunctionCallbackInfo<Value>& args) { | |||
191 | HistogramBase* histogram; | |||
192 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
193 | (*histogram)->RecordDelta(); | |||
194 | } | |||
195 | ||||
196 | void HistogramBase::Record(const FunctionCallbackInfo<Value>& args) { | |||
197 | Environment* env = Environment::GetCurrent(args); | |||
198 | CHECK_IMPLIES(!args[0]->IsNumber(), args[0]->IsBigInt())do { if (__builtin_expect(!!(!(!(!args[0]->IsNumber()) || ( args[0]->IsBigInt()))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "198", "!(!args[0]->IsNumber()) || (args[0]->IsBigInt())" , __PRETTY_FUNCTION__ }; node::Assert(args); } while (0); } } while (0); | |||
199 | bool lossless = true; | |||
200 | int64_t value = args[0]->IsBigInt() | |||
201 | ? args[0].As<BigInt>()->Int64Value(&lossless) | |||
202 | : static_cast<int64_t>(args[0].As<Number>()->Value()); | |||
203 | if (!lossless || value < 1) | |||
204 | return THROW_ERR_OUT_OF_RANGE(env, "value is out of range"); | |||
205 | HistogramBase* histogram; | |||
206 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
207 | (*histogram)->Record(value); | |||
208 | } | |||
209 | ||||
210 | void HistogramBase::Add(const FunctionCallbackInfo<Value>& args) { | |||
211 | Environment* env = Environment::GetCurrent(args); | |||
212 | HistogramBase* histogram; | |||
213 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
214 | ||||
215 | CHECK(GetConstructorTemplate(env)->HasInstance(args[0]))do { if (__builtin_expect(!!(!(GetConstructorTemplate(env)-> HasInstance(args[0]))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "215", "GetConstructorTemplate(env)->HasInstance(args[0])" , __PRETTY_FUNCTION__ }; node::Assert(args); } while (0); } } while (0); | |||
216 | HistogramBase* other; | |||
217 | ASSIGN_OR_RETURN_UNWRAP(&other, args[0])do { *&other = static_cast<typename std::remove_reference <decltype(*&other)>::type>( BaseObject::FromJSObject (args[0])); if (*&other == nullptr) return ; } while (0); | |||
218 | ||||
219 | double count = (*histogram)->Add(*(other->histogram())); | |||
220 | args.GetReturnValue().Set(count); | |||
221 | } | |||
222 | ||||
223 | BaseObjectPtr<HistogramBase> HistogramBase::Create( | |||
224 | Environment* env, | |||
225 | const Histogram::Options& options) { | |||
226 | Local<Object> obj; | |||
227 | if (!GetConstructorTemplate(env) | |||
228 | ->InstanceTemplate() | |||
229 | ->NewInstance(env->context()).ToLocal(&obj)) { | |||
230 | return BaseObjectPtr<HistogramBase>(); | |||
231 | } | |||
232 | ||||
233 | return MakeBaseObject<HistogramBase>(env, obj, options); | |||
234 | } | |||
235 | ||||
236 | BaseObjectPtr<HistogramBase> HistogramBase::Create( | |||
237 | Environment* env, | |||
238 | std::shared_ptr<Histogram> histogram) { | |||
239 | Local<Object> obj; | |||
240 | if (!GetConstructorTemplate(env) | |||
241 | ->InstanceTemplate() | |||
242 | ->NewInstance(env->context()).ToLocal(&obj)) { | |||
243 | return BaseObjectPtr<HistogramBase>(); | |||
244 | } | |||
245 | return MakeBaseObject<HistogramBase>(env, obj, std::move(histogram)); | |||
246 | } | |||
247 | ||||
248 | void HistogramBase::New(const FunctionCallbackInfo<Value>& args) { | |||
249 | CHECK(args.IsConstructCall())do { if (__builtin_expect(!!(!(args.IsConstructCall())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "249", "args.IsConstructCall()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
250 | Environment* env = Environment::GetCurrent(args); | |||
251 | ||||
252 | CHECK_IMPLIES(!args[0]->IsNumber(), args[0]->IsBigInt())do { if (__builtin_expect(!!(!(!(!args[0]->IsNumber()) || ( args[0]->IsBigInt()))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "252", "!(!args[0]->IsNumber()) || (args[0]->IsBigInt())" , __PRETTY_FUNCTION__ }; node::Assert(args); } while (0); } } while (0); | |||
253 | CHECK_IMPLIES(!args[1]->IsNumber(), args[1]->IsBigInt())do { if (__builtin_expect(!!(!(!(!args[1]->IsNumber()) || ( args[1]->IsBigInt()))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "253", "!(!args[1]->IsNumber()) || (args[1]->IsBigInt())" , __PRETTY_FUNCTION__ }; node::Assert(args); } while (0); } } while (0); | |||
254 | CHECK(args[2]->IsUint32())do { if (__builtin_expect(!!(!(args[2]->IsUint32())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "254", "args[2]->IsUint32()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
255 | ||||
256 | int64_t lowest = 1; | |||
257 | int64_t highest = std::numeric_limits<int64_t>::max(); | |||
258 | ||||
259 | bool lossless_ignored; | |||
260 | ||||
261 | if (args[0]->IsNumber()) { | |||
262 | lowest = args[0].As<Integer>()->Value(); | |||
263 | } else if (args[0]->IsBigInt()) { | |||
264 | lowest = args[0].As<BigInt>()->Int64Value(&lossless_ignored); | |||
265 | } | |||
266 | ||||
267 | if (args[1]->IsNumber()) { | |||
268 | highest = args[1].As<Integer>()->Value(); | |||
269 | } else if (args[1]->IsBigInt()) { | |||
270 | highest = args[1].As<BigInt>()->Int64Value(&lossless_ignored); | |||
271 | } | |||
272 | ||||
273 | int32_t figures = args[2].As<Uint32>()->Value(); | |||
274 | new HistogramBase(env, args.This(), Histogram::Options { | |||
275 | lowest, highest, figures | |||
276 | }); | |||
277 | } | |||
278 | ||||
279 | Local<FunctionTemplate> HistogramBase::GetConstructorTemplate( | |||
280 | Environment* env) { | |||
281 | Local<FunctionTemplate> tmpl = env->histogram_ctor_template(); | |||
282 | if (tmpl.IsEmpty()) { | |||
283 | tmpl = env->NewFunctionTemplate(New); | |||
284 | Local<String> classname = | |||
285 | FIXED_ONE_BYTE_STRING(env->isolate(), "Histogram"); | |||
286 | tmpl->SetClassName(classname); | |||
287 | tmpl->Inherit(BaseObject::GetConstructorTemplate(env)); | |||
288 | ||||
289 | tmpl->InstanceTemplate()->SetInternalFieldCount( | |||
290 | HistogramBase::kInternalFieldCount); | |||
291 | env->SetProtoMethodNoSideEffect(tmpl, "count", GetCount); | |||
292 | env->SetProtoMethodNoSideEffect(tmpl, "countBigInt", GetCountBigInt); | |||
293 | env->SetProtoMethodNoSideEffect(tmpl, "exceeds", GetExceeds); | |||
294 | env->SetProtoMethodNoSideEffect(tmpl, "exceedsBigInt", GetExceedsBigInt); | |||
295 | env->SetProtoMethodNoSideEffect(tmpl, "min", GetMin); | |||
296 | env->SetProtoMethodNoSideEffect(tmpl, "minBigInt", GetMinBigInt); | |||
297 | env->SetProtoMethodNoSideEffect(tmpl, "max", GetMax); | |||
298 | env->SetProtoMethodNoSideEffect(tmpl, "maxBigInt", GetMaxBigInt); | |||
299 | env->SetProtoMethodNoSideEffect(tmpl, "mean", GetMean); | |||
300 | env->SetProtoMethodNoSideEffect(tmpl, "stddev", GetStddev); | |||
301 | env->SetProtoMethodNoSideEffect(tmpl, "percentile", GetPercentile); | |||
302 | env->SetProtoMethodNoSideEffect(tmpl, "percentileBigInt", | |||
303 | GetPercentileBigInt); | |||
304 | env->SetProtoMethodNoSideEffect(tmpl, "percentiles", GetPercentiles); | |||
305 | env->SetProtoMethodNoSideEffect(tmpl, "percentilesBigInt", | |||
306 | GetPercentilesBigInt); | |||
307 | env->SetProtoMethod(tmpl, "reset", DoReset); | |||
308 | env->SetProtoMethod(tmpl, "record", Record); | |||
309 | env->SetProtoMethod(tmpl, "recordDelta", RecordDelta); | |||
310 | env->SetProtoMethod(tmpl, "add", Add); | |||
311 | env->set_histogram_ctor_template(tmpl); | |||
312 | } | |||
313 | return tmpl; | |||
314 | } | |||
315 | ||||
316 | void HistogramBase::RegisterExternalReferences( | |||
317 | ExternalReferenceRegistry* registry) { | |||
318 | registry->Register(New); | |||
319 | registry->Register(GetCount); | |||
320 | registry->Register(GetCountBigInt); | |||
321 | registry->Register(GetExceeds); | |||
322 | registry->Register(GetExceedsBigInt); | |||
323 | registry->Register(GetMin); | |||
324 | registry->Register(GetMinBigInt); | |||
325 | registry->Register(GetMax); | |||
326 | registry->Register(GetMaxBigInt); | |||
327 | registry->Register(GetMean); | |||
328 | registry->Register(GetStddev); | |||
329 | registry->Register(GetPercentile); | |||
330 | registry->Register(GetPercentileBigInt); | |||
331 | registry->Register(GetPercentiles); | |||
332 | registry->Register(GetPercentilesBigInt); | |||
333 | registry->Register(DoReset); | |||
334 | registry->Register(Record); | |||
335 | registry->Register(RecordDelta); | |||
336 | registry->Register(Add); | |||
337 | } | |||
338 | ||||
339 | void HistogramBase::Initialize(Environment* env, Local<Object> target) { | |||
340 | env->SetConstructorFunction(target, "Histogram", GetConstructorTemplate(env)); | |||
341 | } | |||
342 | ||||
343 | BaseObjectPtr<BaseObject> HistogramBase::HistogramTransferData::Deserialize( | |||
344 | Environment* env, | |||
345 | v8::Local<v8::Context> context, | |||
346 | std::unique_ptr<worker::TransferData> self) { | |||
347 | return Create(env, std::move(histogram_)); | |||
348 | } | |||
349 | ||||
350 | std::unique_ptr<worker::TransferData> HistogramBase::CloneForMessaging() const { | |||
351 | return std::make_unique<HistogramTransferData>(this); | |||
352 | } | |||
353 | ||||
354 | void HistogramBase::HistogramTransferData::MemoryInfo( | |||
355 | MemoryTracker* tracker) const { | |||
356 | tracker->TrackField("histogram", histogram_); | |||
357 | } | |||
358 | ||||
359 | Local<FunctionTemplate> IntervalHistogram::GetConstructorTemplate( | |||
360 | Environment* env) { | |||
361 | Local<FunctionTemplate> tmpl = env->intervalhistogram_constructor_template(); | |||
362 | if (tmpl.IsEmpty()) { | |||
363 | tmpl = FunctionTemplate::New(env->isolate()); | |||
364 | tmpl->Inherit(HandleWrap::GetConstructorTemplate(env)); | |||
365 | tmpl->InstanceTemplate()->SetInternalFieldCount( | |||
366 | HistogramBase::kInternalFieldCount); | |||
367 | env->SetProtoMethodNoSideEffect(tmpl, "count", GetCount); | |||
368 | env->SetProtoMethodNoSideEffect(tmpl, "countBigInt", GetCountBigInt); | |||
369 | env->SetProtoMethodNoSideEffect(tmpl, "exceeds", GetExceeds); | |||
370 | env->SetProtoMethodNoSideEffect(tmpl, "exceedsBigInt", GetExceedsBigInt); | |||
371 | env->SetProtoMethodNoSideEffect(tmpl, "min", GetMin); | |||
372 | env->SetProtoMethodNoSideEffect(tmpl, "minBigInt", GetMinBigInt); | |||
373 | env->SetProtoMethodNoSideEffect(tmpl, "max", GetMax); | |||
374 | env->SetProtoMethodNoSideEffect(tmpl, "maxBigInt", GetMaxBigInt); | |||
375 | env->SetProtoMethodNoSideEffect(tmpl, "mean", GetMean); | |||
376 | env->SetProtoMethodNoSideEffect(tmpl, "stddev", GetStddev); | |||
377 | env->SetProtoMethodNoSideEffect(tmpl, "percentile", GetPercentile); | |||
378 | env->SetProtoMethodNoSideEffect(tmpl, "percentileBigInt", | |||
379 | GetPercentileBigInt); | |||
380 | env->SetProtoMethodNoSideEffect(tmpl, "percentiles", GetPercentiles); | |||
381 | env->SetProtoMethodNoSideEffect(tmpl, "percentilesBigInt", | |||
382 | GetPercentilesBigInt); | |||
383 | env->SetProtoMethod(tmpl, "reset", DoReset); | |||
384 | env->SetProtoMethod(tmpl, "start", Start); | |||
385 | env->SetProtoMethod(tmpl, "stop", Stop); | |||
386 | env->set_intervalhistogram_constructor_template(tmpl); | |||
387 | } | |||
388 | return tmpl; | |||
389 | } | |||
390 | ||||
391 | void IntervalHistogram::RegisterExternalReferences( | |||
392 | ExternalReferenceRegistry* registry) { | |||
393 | registry->Register(GetCount); | |||
394 | registry->Register(GetCountBigInt); | |||
395 | registry->Register(GetExceeds); | |||
396 | registry->Register(GetExceedsBigInt); | |||
397 | registry->Register(GetMin); | |||
398 | registry->Register(GetMinBigInt); | |||
399 | registry->Register(GetMax); | |||
400 | registry->Register(GetMaxBigInt); | |||
401 | registry->Register(GetMean); | |||
402 | registry->Register(GetStddev); | |||
403 | registry->Register(GetPercentile); | |||
404 | registry->Register(GetPercentileBigInt); | |||
405 | registry->Register(GetPercentiles); | |||
406 | registry->Register(GetPercentilesBigInt); | |||
407 | registry->Register(DoReset); | |||
408 | registry->Register(Start); | |||
409 | registry->Register(Stop); | |||
410 | } | |||
411 | ||||
412 | IntervalHistogram::IntervalHistogram( | |||
413 | Environment* env, | |||
414 | Local<Object> wrap, | |||
415 | AsyncWrap::ProviderType type, | |||
416 | int32_t interval, | |||
417 | std::function<void(Histogram&)> on_interval, | |||
418 | const Histogram::Options& options) | |||
419 | : HandleWrap( | |||
420 | env, | |||
421 | wrap, | |||
422 | reinterpret_cast<uv_handle_t*>(&timer_), | |||
423 | type), | |||
424 | HistogramImpl(options), | |||
425 | interval_(interval), | |||
426 | on_interval_(std::move(on_interval)) { | |||
427 | MakeWeak(); | |||
428 | uv_timer_init(env->event_loop(), &timer_); | |||
429 | } | |||
430 | ||||
431 | BaseObjectPtr<IntervalHistogram> IntervalHistogram::Create( | |||
432 | Environment* env, | |||
433 | int32_t interval, | |||
434 | std::function<void(Histogram&)> on_interval, | |||
435 | const Histogram::Options& options) { | |||
436 | Local<Object> obj; | |||
437 | if (!GetConstructorTemplate(env) | |||
438 | ->InstanceTemplate() | |||
439 | ->NewInstance(env->context()).ToLocal(&obj)) { | |||
440 | return BaseObjectPtr<IntervalHistogram>(); | |||
441 | } | |||
442 | ||||
443 | return MakeBaseObject<IntervalHistogram>( | |||
444 | env, | |||
445 | obj, | |||
446 | AsyncWrap::PROVIDER_ELDHISTOGRAM, | |||
447 | interval, | |||
448 | std::move(on_interval), | |||
449 | options); | |||
450 | } | |||
451 | ||||
452 | void IntervalHistogram::TimerCB(uv_timer_t* handle) { | |||
453 | IntervalHistogram* histogram = | |||
454 | ContainerOf(&IntervalHistogram::timer_, handle); | |||
455 | ||||
456 | Histogram* h = histogram->histogram().get(); | |||
457 | ||||
458 | histogram->on_interval_(*h); | |||
459 | } | |||
460 | ||||
461 | void IntervalHistogram::MemoryInfo(MemoryTracker* tracker) const { | |||
462 | tracker->TrackField("histogram", histogram()); | |||
463 | } | |||
464 | ||||
465 | void IntervalHistogram::OnStart(StartFlags flags) { | |||
466 | if (enabled_ || IsHandleClosing()) return; | |||
467 | enabled_ = true; | |||
468 | if (flags == StartFlags::RESET) | |||
469 | histogram()->Reset(); | |||
470 | uv_timer_start(&timer_, TimerCB, interval_, interval_); | |||
471 | uv_unref(reinterpret_cast<uv_handle_t*>(&timer_)); | |||
472 | } | |||
473 | ||||
474 | void IntervalHistogram::OnStop() { | |||
475 | if (!enabled_ || IsHandleClosing()) return; | |||
476 | enabled_ = false; | |||
477 | uv_timer_stop(&timer_); | |||
478 | } | |||
479 | ||||
480 | void IntervalHistogram::Start(const FunctionCallbackInfo<Value>& args) { | |||
481 | IntervalHistogram* histogram; | |||
482 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
483 | histogram->OnStart(args[0]->IsTrue() ? StartFlags::RESET : StartFlags::NONE); | |||
484 | } | |||
485 | ||||
486 | void IntervalHistogram::Stop(const FunctionCallbackInfo<Value>& args) { | |||
487 | IntervalHistogram* histogram; | |||
488 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
489 | histogram->OnStop(); | |||
490 | } | |||
491 | ||||
492 | void IntervalHistogram::GetCount(const FunctionCallbackInfo<Value>& args) { | |||
493 | IntervalHistogram* histogram; | |||
494 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
495 | double value = static_cast<double>((*histogram)->Count()); | |||
496 | args.GetReturnValue().Set(value); | |||
497 | } | |||
498 | ||||
499 | void IntervalHistogram::GetCountBigInt( | |||
500 | const v8::FunctionCallbackInfo<v8::Value>& args) { | |||
501 | Environment* env = Environment::GetCurrent(args); | |||
502 | IntervalHistogram* histogram; | |||
503 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
504 | args.GetReturnValue().Set( | |||
505 | BigInt::NewFromUnsigned(env->isolate(), (*histogram)->Count())); | |||
506 | } | |||
507 | ||||
508 | void IntervalHistogram::GetMin(const FunctionCallbackInfo<Value>& args) { | |||
509 | IntervalHistogram* histogram; | |||
510 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
511 | double value = static_cast<double>((*histogram)->Min()); | |||
512 | args.GetReturnValue().Set(value); | |||
513 | } | |||
514 | ||||
515 | void IntervalHistogram::GetMinBigInt(const FunctionCallbackInfo<Value>& args) { | |||
516 | Environment* env = Environment::GetCurrent(args); | |||
517 | IntervalHistogram* histogram; | |||
518 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
519 | args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Min())); | |||
520 | } | |||
521 | ||||
522 | void IntervalHistogram::GetMax(const FunctionCallbackInfo<Value>& args) { | |||
523 | IntervalHistogram* histogram; | |||
524 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
525 | double value = static_cast<double>((*histogram)->Max()); | |||
526 | args.GetReturnValue().Set(value); | |||
527 | } | |||
528 | ||||
529 | void IntervalHistogram::GetMaxBigInt(const FunctionCallbackInfo<Value>& args) { | |||
530 | Environment* env = Environment::GetCurrent(args); | |||
531 | IntervalHistogram* histogram; | |||
532 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
533 | args.GetReturnValue().Set(BigInt::New(env->isolate(), (*histogram)->Min())); | |||
534 | } | |||
535 | ||||
536 | void IntervalHistogram::GetMean(const FunctionCallbackInfo<Value>& args) { | |||
537 | IntervalHistogram* histogram; | |||
538 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
539 | args.GetReturnValue().Set((*histogram)->Mean()); | |||
540 | } | |||
541 | ||||
542 | void IntervalHistogram::GetExceeds(const FunctionCallbackInfo<Value>& args) { | |||
543 | IntervalHistogram* histogram; | |||
544 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
545 | double value = static_cast<double>((*histogram)->Exceeds()); | |||
546 | args.GetReturnValue().Set(value); | |||
547 | } | |||
548 | ||||
549 | void IntervalHistogram::GetExceedsBigInt( | |||
550 | const FunctionCallbackInfo<Value>& args) { | |||
551 | Environment* env = Environment::GetCurrent(args); | |||
552 | IntervalHistogram* histogram; | |||
553 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
554 | args.GetReturnValue().Set( | |||
555 | BigInt::New(env->isolate(), (*histogram)->Exceeds())); | |||
556 | } | |||
557 | ||||
558 | void IntervalHistogram::GetStddev(const FunctionCallbackInfo<Value>& args) { | |||
559 | IntervalHistogram* histogram; | |||
560 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
561 | args.GetReturnValue().Set((*histogram)->Stddev()); | |||
562 | } | |||
563 | ||||
564 | void IntervalHistogram::GetPercentile(const FunctionCallbackInfo<Value>& args) { | |||
565 | IntervalHistogram* histogram; | |||
566 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
567 | CHECK(args[0]->IsNumber())do { if (__builtin_expect(!!(!(args[0]->IsNumber())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "567", "args[0]->IsNumber()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
568 | double percentile = args[0].As<Number>()->Value(); | |||
569 | double value = static_cast<double>((*histogram)->Percentile(percentile)); | |||
570 | args.GetReturnValue().Set(value); | |||
571 | } | |||
572 | ||||
573 | void IntervalHistogram::GetPercentileBigInt( | |||
574 | const FunctionCallbackInfo<Value>& args) { | |||
575 | Environment* env = Environment::GetCurrent(args); | |||
576 | IntervalHistogram* histogram; | |||
577 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
578 | CHECK(args[0]->IsNumber())do { if (__builtin_expect(!!(!(args[0]->IsNumber())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "578", "args[0]->IsNumber()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
579 | double percentile = args[0].As<Number>()->Value(); | |||
580 | int64_t value = (*histogram)->Percentile(percentile); | |||
581 | args.GetReturnValue().Set(BigInt::New(env->isolate(), value)); | |||
582 | } | |||
583 | ||||
584 | void IntervalHistogram::GetPercentiles( | |||
585 | const FunctionCallbackInfo<Value>& args) { | |||
586 | Environment* env = Environment::GetCurrent(args); | |||
587 | IntervalHistogram* histogram; | |||
588 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
| ||||
589 | CHECK(args[0]->IsMap())do { if (__builtin_expect(!!(!(args[0]->IsMap())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "589", "args[0]->IsMap()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
590 | Local<Map> map = args[0].As<Map>(); | |||
591 | (*histogram)->Percentiles([map, env](double key, int64_t value) { | |||
592 | USE(map->Set( | |||
593 | env->context(), | |||
| ||||
594 | Number::New(env->isolate(), key), | |||
595 | Number::New(env->isolate(), static_cast<double>(value)))); | |||
596 | }); | |||
597 | } | |||
598 | ||||
599 | void IntervalHistogram::GetPercentilesBigInt( | |||
600 | const FunctionCallbackInfo<Value>& args) { | |||
601 | Environment* env = Environment::GetCurrent(args); | |||
602 | IntervalHistogram* histogram; | |||
603 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
604 | CHECK(args[0]->IsMap())do { if (__builtin_expect(!!(!(args[0]->IsMap())), 0)) { do { static const node::AssertionInfo args = { "../src/histogram.cc" ":" "604", "args[0]->IsMap()", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); | |||
605 | Local<Map> map = args[0].As<Map>(); | |||
606 | (*histogram)->Percentiles([map, env](double key, int64_t value) { | |||
607 | USE(map->Set( | |||
608 | env->context(), | |||
609 | Number::New(env->isolate(), key), | |||
610 | BigInt::New(env->isolate(), value))); | |||
611 | }); | |||
612 | } | |||
613 | ||||
614 | void IntervalHistogram::DoReset(const FunctionCallbackInfo<Value>& args) { | |||
615 | IntervalHistogram* histogram; | |||
616 | ASSIGN_OR_RETURN_UNWRAP(&histogram, args.Holder())do { *&histogram = static_cast<typename std::remove_reference <decltype(*&histogram)>::type>( BaseObject::FromJSObject (args.Holder())); if (*&histogram == nullptr) return ; } while (0); | |||
617 | (*histogram)->Reset(); | |||
618 | } | |||
619 | ||||
620 | std::unique_ptr<worker::TransferData> | |||
621 | IntervalHistogram::CloneForMessaging() const { | |||
622 | return std::make_unique<HistogramBase::HistogramTransferData>(histogram()); | |||
623 | } | |||
624 | ||||
625 | } // namespace node |
1 | #ifndef SRC_HISTOGRAM_INL_H_ |
2 | #define SRC_HISTOGRAM_INL_H_ |
3 | |
4 | #if defined(NODE_WANT_INTERNALS1) && NODE_WANT_INTERNALS1 |
5 | |
6 | #include "histogram.h" |
7 | #include "base_object-inl.h" |
8 | #include "node_internals.h" |
9 | |
10 | namespace node { |
11 | |
12 | void Histogram::Reset() { |
13 | Mutex::ScopedLock lock(mutex_); |
14 | hdr_reset(histogram_.get()); |
15 | exceeds_ = 0; |
16 | count_ = 0; |
17 | prev_ = 0; |
18 | } |
19 | |
20 | double Histogram::Add(const Histogram& other) { |
21 | Mutex::ScopedLock lock(mutex_); |
22 | count_ += other.count_; |
23 | exceeds_ += other.exceeds_; |
24 | if (other.prev_ > prev_) |
25 | prev_ = other.prev_; |
26 | return static_cast<double>(hdr_add(histogram_.get(), other.histogram_.get())); |
27 | } |
28 | |
29 | size_t Histogram::Count() const { |
30 | Mutex::ScopedLock lock(mutex_); |
31 | return count_; |
32 | } |
33 | |
34 | int64_t Histogram::Min() const { |
35 | Mutex::ScopedLock lock(mutex_); |
36 | return hdr_min(histogram_.get()); |
37 | } |
38 | |
39 | int64_t Histogram::Max() const { |
40 | Mutex::ScopedLock lock(mutex_); |
41 | return hdr_max(histogram_.get()); |
42 | } |
43 | |
44 | double Histogram::Mean() const { |
45 | Mutex::ScopedLock lock(mutex_); |
46 | return hdr_mean(histogram_.get()); |
47 | } |
48 | |
49 | double Histogram::Stddev() const { |
50 | Mutex::ScopedLock lock(mutex_); |
51 | return hdr_stddev(histogram_.get()); |
52 | } |
53 | |
54 | int64_t Histogram::Percentile(double percentile) const { |
55 | Mutex::ScopedLock lock(mutex_); |
56 | CHECK_GT(percentile, 0)do { if (__builtin_expect(!!(!((percentile) > (0))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram-inl.h" ":" "56", "(percentile) > (0)", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); |
57 | CHECK_LE(percentile, 100)do { if (__builtin_expect(!!(!((percentile) <= (100))), 0) ) { do { static const node::AssertionInfo args = { "../src/histogram-inl.h" ":" "57", "(percentile) <= (100)", __PRETTY_FUNCTION__ }; node::Assert(args); } while (0); } } while (0); |
58 | return hdr_value_at_percentile(histogram_.get(), percentile); |
59 | } |
60 | |
61 | template <typename Iterator> |
62 | void Histogram::Percentiles(Iterator&& fn) { |
63 | Mutex::ScopedLock lock(mutex_); |
64 | hdr_iter iter; |
65 | hdr_iter_percentile_init(&iter, histogram_.get(), 1); |
66 | while (hdr_iter_next(&iter)) { |
67 | double key = iter.specifics.percentiles.percentile; |
68 | fn(key, iter.value); |
69 | } |
70 | } |
71 | |
72 | bool Histogram::Record(int64_t value) { |
73 | Mutex::ScopedLock lock(mutex_); |
74 | bool recorded = hdr_record_value(histogram_.get(), value); |
75 | if (!recorded) |
76 | exceeds_++; |
77 | else |
78 | count_++; |
79 | return recorded; |
80 | } |
81 | |
82 | uint64_t Histogram::RecordDelta() { |
83 | Mutex::ScopedLock lock(mutex_); |
84 | uint64_t time = uv_hrtime(); |
85 | int64_t delta = 0; |
86 | if (prev_ > 0) { |
87 | CHECK_GE(time, prev_)do { if (__builtin_expect(!!(!((time) >= (prev_))), 0)) { do { static const node::AssertionInfo args = { "../src/histogram-inl.h" ":" "87", "(time) >= (prev_)", __PRETTY_FUNCTION__ }; node ::Assert(args); } while (0); } } while (0); |
88 | delta = time - prev_; |
89 | if (hdr_record_value(histogram_.get(), delta)) |
90 | count_++; |
91 | else |
92 | exceeds_++; |
93 | } |
94 | prev_ = time; |
95 | return delta; |
96 | } |
97 | |
98 | size_t Histogram::GetMemorySize() const { |
99 | Mutex::ScopedLock lock(mutex_); |
100 | return hdr_get_memory_size(histogram_.get()); |
101 | } |
102 | |
103 | } // namespace node |
104 | |
105 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
106 | |
107 | #endif // SRC_HISTOGRAM_INL_H_ |