Bug Summary

File:out/../src/histogram.cc
Warning:line 593, column 11
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-unknown-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name histogram.cc -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/home/maurizio/node-v18.6.0/out -resource-dir /usr/local/lib/clang/16.0.0 -D V8_DEPRECATION_WARNINGS -D V8_IMMINENT_DEPRECATION_WARNINGS -D _GLIBCXX_USE_CXX11_ABI=1 -D NODE_OPENSSL_CONF_NAME=nodejs_conf -D NODE_OPENSSL_HAS_QUIC -D __STDC_FORMAT_MACROS -D OPENSSL_NO_PINSHARED -D OPENSSL_THREADS -D NODE_ARCH="x64" -D NODE_PLATFORM="linux" -D NODE_WANT_INTERNALS=1 -D V8_DEPRECATION_WARNINGS=1 -D NODE_OPENSSL_SYSTEM_CERT_PATH="" -D NODE_USE_NODE_CODE_CACHE=1 -D HAVE_INSPECTOR=1 -D NODE_ENABLE_LARGE_CODE_PAGES=1 -D __POSIX__ -D NODE_USE_V8_PLATFORM=1 -D NODE_HAVE_I18N_SUPPORT=1 -D HAVE_OPENSSL=1 -D OPENSSL_API_COMPAT=0x10100000L -D UCONFIG_NO_SERVICE=1 -D U_ENABLE_DYLOAD=0 -D U_STATIC_IMPLEMENTATION=1 -D U_HAVE_STD_STRING=1 -D UCONFIG_NO_BREAK_ITERATION=0 -D _LARGEFILE_SOURCE -D _FILE_OFFSET_BITS=64 -D _POSIX_C_SOURCE=200112 -D NGHTTP2_STATICLIB -D NDEBUG -D OPENSSL_USE_NODELETE -D L_ENDIAN -D OPENSSL_BUILDING_OPENSSL -D AES_ASM -D BSAES_ASM -D CMLL_ASM -D ECP_NISTZ256_ASM -D GHASH_ASM -D KECCAK1600_ASM -D MD5_ASM -D OPENSSL_BN_ASM_GF2m -D OPENSSL_BN_ASM_MONT -D OPENSSL_BN_ASM_MONT5 -D OPENSSL_CPUID_OBJ -D OPENSSL_IA32_SSE2 -D PADLOCK_ASM -D POLY1305_ASM -D SHA1_ASM -D SHA256_ASM -D SHA512_ASM -D VPAES_ASM -D WHIRLPOOL_ASM -D X25519_ASM -D OPENSSL_PIC -D NGTCP2_STATICLIB -D NGHTTP3_STATICLIB -I ../src -I /home/maurizio/node-v18.6.0/out/Release/obj/gen -I /home/maurizio/node-v18.6.0/out/Release/obj/gen/include -I /home/maurizio/node-v18.6.0/out/Release/obj/gen/src -I ../deps/googletest/include -I ../deps/histogram/src -I ../deps/uvwasi/include -I ../deps/v8/include -I ../deps/icu-small/source/i18n -I ../deps/icu-small/source/common -I ../deps/zlib -I ../deps/llhttp/include -I ../deps/cares/include -I ../deps/uv/include -I ../deps/nghttp2/lib/includes -I ../deps/brotli/c/include -I ../deps/openssl/openssl/include -I ../deps/openssl/openssl/crypto/include -I ../deps/openssl/config/archs/linux-x86_64/asm/include -I ../deps/openssl/config/archs/linux-x86_64/asm -I ../deps/ngtcp2 -I ../deps/ngtcp2/ngtcp2/lib/includes -I ../deps/ngtcp2/ngtcp2/crypto/includes -I ../deps/ngtcp2/nghttp3/lib/includes -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8 -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/x86_64-redhat-linux -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../include/c++/8/backward -internal-isystem /usr/local/lib/clang/16.0.0/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-redhat-linux/8/../../../../x86_64-redhat-linux/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -O3 -Wno-unused-parameter -Wno-unused-parameter -std=gnu++17 -fdeprecated-macro -fdebug-compilation-dir=/home/maurizio/node-v18.6.0/out -ferror-limit 19 -fno-rtti -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/scan-build-2022-08-22-142216-507842-1 -x c++ ../src/histogram.cc

../src/histogram.cc

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
8namespace node {
9
10using v8::BigInt;
11using v8::FunctionCallbackInfo;
12using v8::FunctionTemplate;
13using v8::Integer;
14using v8::Local;
15using v8::Map;
16using v8::Number;
17using v8::Object;
18using v8::String;
19using v8::Uint32;
20using v8::Value;
21
22Histogram::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
31void Histogram::MemoryInfo(MemoryTracker* tracker) const {
32 tracker->TrackFieldWithSize("histogram", GetMemorySize());
33}
34
35HistogramImpl::HistogramImpl(const Histogram::Options& options)
36 : histogram_(new Histogram(options)) {}
37
38HistogramImpl::HistogramImpl(std::shared_ptr<Histogram> histogram)
39 : histogram_(std::move(histogram)) {}
40
41HistogramBase::HistogramBase(
42 Environment* env,
43 Local<Object> wrap,
44 const Histogram::Options& options)
45 : BaseObject(env, wrap),
46 HistogramImpl(options) {
47 MakeWeak();
48}
49
50HistogramBase::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
59void HistogramBase::MemoryInfo(MemoryTracker* tracker) const {
60 tracker->TrackField("histogram", histogram());
61}
62
63void 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
70void 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
79void 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
86void 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
93void 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
100void 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
108void 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
114void 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
121void 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
129void 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
135void 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
144void 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
155void 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
169void 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
184void 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
190void 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
196void 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
210void 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
223BaseObjectPtr<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
236BaseObjectPtr<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
248void 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
279Local<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
316void 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
339void HistogramBase::Initialize(Environment* env, Local<Object> target) {
340 env->SetConstructorFunction(target, "Histogram", GetConstructorTemplate(env));
341}
342
343BaseObjectPtr<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
350std::unique_ptr<worker::TransferData> HistogramBase::CloneForMessaging() const {
351 return std::make_unique<HistogramTransferData>(this);
352}
353
354void HistogramBase::HistogramTransferData::MemoryInfo(
355 MemoryTracker* tracker) const {
356 tracker->TrackField("histogram", histogram_);
357}
358
359Local<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
391void 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
412IntervalHistogram::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
431BaseObjectPtr<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
452void 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
461void IntervalHistogram::MemoryInfo(MemoryTracker* tracker) const {
462 tracker->TrackField("histogram", histogram());
463}
464
465void 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
474void IntervalHistogram::OnStop() {
475 if (!enabled_ || IsHandleClosing()) return;
476 enabled_ = false;
477 uv_timer_stop(&timer_);
478}
479
480void 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
486void 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
492void 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
499void 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
508void 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
515void 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
522void 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
529void 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
536void 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
542void 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
549void 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
558void 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
564void 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
573void 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
584void 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)
;
1
Assuming the condition is false
2
Taking false branch
3
Loop condition is false. Exiting loop
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)
;
4
Assuming the condition is false
5
Taking false branch
6
Loop condition is false. Exiting loop
590 Local<Map> map = args[0].As<Map>();
591 (*histogram)->Percentiles([map, env](double key, int64_t value) {
7
Null pointer value stored to field ''
8
Calling 'Histogram::Percentiles'
592 USE(map->Set(
593 env->context(),
11
Called C++ object pointer is null
594 Number::New(env->isolate(), key),
595 Number::New(env->isolate(), static_cast<double>(value))));
596 });
597}
598
599void 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
614void 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
620std::unique_ptr<worker::TransferData>
621IntervalHistogram::CloneForMessaging() const {
622 return std::make_unique<HistogramBase::HistogramTransferData>(histogram());
623}
624
625} // namespace node

../src/histogram-inl.h

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
10namespace node {
11
12void Histogram::Reset() {
13 Mutex::ScopedLock lock(mutex_);
14 hdr_reset(histogram_.get());
15 exceeds_ = 0;
16 count_ = 0;
17 prev_ = 0;
18}
19
20double 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
29size_t Histogram::Count() const {
30 Mutex::ScopedLock lock(mutex_);
31 return count_;
32}
33
34int64_t Histogram::Min() const {
35 Mutex::ScopedLock lock(mutex_);
36 return hdr_min(histogram_.get());
37}
38
39int64_t Histogram::Max() const {
40 Mutex::ScopedLock lock(mutex_);
41 return hdr_max(histogram_.get());
42}
43
44double Histogram::Mean() const {
45 Mutex::ScopedLock lock(mutex_);
46 return hdr_mean(histogram_.get());
47}
48
49double Histogram::Stddev() const {
50 Mutex::ScopedLock lock(mutex_);
51 return hdr_stddev(histogram_.get());
52}
53
54int64_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
61template <typename Iterator>
62void 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)) {
9
Loop condition is true. Entering loop body
67 double key = iter.specifics.percentiles.percentile;
68 fn(key, iter.value);
10
Calling 'operator()'
69 }
70}
71
72bool 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
82uint64_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
98size_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_