| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,6 +2,7 @@ | |||
| 2 | 2 | #include "base_object-inl.h" | |
| 3 | 3 | #include "histogram-inl.h" | |
| 4 | 4 | #include "memory_tracker-inl.h" | |
| 5 | + #include "node_debug.h" | ||
| 5 | 6 | #include "node_errors.h" | |
| 6 | 7 | #include "node_external_reference.h" | |
| 7 | 8 | #include "util.h" | |
@@ -11,10 +12,8 @@ namespace node { | |||
| 11 | 12 | using v8::BigInt; | |
| 12 | 13 | using v8::CFunction; | |
| 13 | 14 | using v8::Context; | |
| 14 | - using v8::FastApiCallbackOptions; | ||
| 15 | 15 | using v8::FunctionCallbackInfo; | |
| 16 | 16 | using v8::FunctionTemplate; | |
| 17 | - using v8::HandleScope; | ||
| 18 | 17 | using v8::Integer; | |
| 19 | 18 | using v8::Isolate; | |
| 20 | 19 | using v8::Local; | |
@@ -162,8 +161,8 @@ void HistogramBase::RecordDelta(const FunctionCallbackInfo<Value>& args) { | |||
| 162 | 161 | (*histogram)->RecordDelta(); | |
| 163 | 162 | } | |
| 164 | 163 | ||
| 165 | - void HistogramBase::FastRecordDelta(Local<Value> unused, | ||
| 166 | - Local<Value> receiver) { | ||
| 164 | + void HistogramBase::FastRecordDelta(Local<Value> receiver) { | ||
| 165 | + TRACK_V8_FAST_API_CALL("histogram.recordDelta"); | ||
| 167 | 166 | HistogramBase* histogram; | |
| 168 | 167 | ASSIGN_OR_RETURN_UNWRAP(&histogram, receiver); | |
| 169 | 168 | (*histogram)->RecordDelta(); | |
@@ -183,15 +182,9 @@ void HistogramBase::Record(const FunctionCallbackInfo<Value>& args) { | |||
| 183 | 182 | (*histogram)->Record(value); | |
| 184 | 183 | } | |
| 185 | 184 | ||
| 186 | - void HistogramBase::FastRecord(Local<Value> unused, | ||
| 187 | - Local<Value> receiver, | ||
| 188 | - const int64_t value, | ||
| 189 | - FastApiCallbackOptions& options) { | ||
| 190 | - if (value < 1) { | ||
| 191 | - HandleScope scope(options.isolate); | ||
| 192 | - THROW_ERR_OUT_OF_RANGE(options.isolate, "value is out of range"); | ||
| 193 | - return; | ||
| 194 | - } | ||
| 185 | + void HistogramBase::FastRecord(Local<Value> receiver, const int64_t value) { | ||
| 186 | + CHECK_GE(value, 1); | ||
| 187 | + TRACK_V8_FAST_API_CALL("histogram.record"); | ||
| 195 | 188 | HistogramBase* histogram; | |
| 196 | 189 | ASSIGN_OR_RETURN_UNWRAP(&histogram, receiver); | |
| 197 | 190 | (*histogram)->Record(value); | |
@@ -428,9 +421,8 @@ void IntervalHistogram::Start(const FunctionCallbackInfo<Value>& args) { | |||
| 428 | 421 | histogram->OnStart(args[0]->IsTrue() ? StartFlags::RESET : StartFlags::NONE); | |
| 429 | 422 | } | |
| 430 | 423 | ||
| 431 | - void IntervalHistogram::FastStart(Local<Value> unused, | ||
| 432 | - Local<Value> receiver, | ||
| 433 | - bool reset) { | ||
| 424 | + void IntervalHistogram::FastStart(Local<Value> receiver, bool reset) { | ||
| 425 | + TRACK_V8_FAST_API_CALL("histogram.start"); | ||
| 434 | 426 | IntervalHistogram* histogram; | |
| 435 | 427 | ASSIGN_OR_RETURN_UNWRAP(&histogram, receiver); | |
| 436 | 428 | histogram->OnStart(reset ? StartFlags::RESET : StartFlags::NONE); | |
@@ -442,7 +434,8 @@ void IntervalHistogram::Stop(const FunctionCallbackInfo<Value>& args) { | |||
| 442 | 434 | histogram->OnStop(); | |
| 443 | 435 | } | |
| 444 | 436 | ||
| 445 | - void IntervalHistogram::FastStop(Local<Value> unused, Local<Value> receiver) { | ||
| 437 | + void IntervalHistogram::FastStop(Local<Value> receiver) { | ||
| 438 | + TRACK_V8_FAST_API_CALL("histogram.stop"); | ||
| 446 | 439 | IntervalHistogram* histogram; | |
| 447 | 440 | ASSIGN_OR_RETURN_UNWRAP(&histogram, receiver); | |
| 448 | 441 | histogram->OnStop(); | |
@@ -555,46 +548,51 @@ void HistogramImpl::DoReset(const FunctionCallbackInfo<Value>& args) { | |||
| 555 | 548 | (*histogram)->Reset(); | |
| 556 | 549 | } | |
| 557 | 550 | ||
| 558 | - void HistogramImpl::FastReset(Local<Value> unused, Local<Value> receiver) { | ||
| 551 | + void HistogramImpl::FastReset(Local<Value> receiver) { | ||
| 552 | + TRACK_V8_FAST_API_CALL("histogram.reset"); | ||
| 559 | 553 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 560 | 554 | (*histogram)->Reset(); | |
| 561 | 555 | } | |
| 562 | 556 | ||
| 563 | - double HistogramImpl::FastGetCount(Local<Value> unused, Local<Value> receiver) { | ||
| 557 | + double HistogramImpl::FastGetCount(Local<Value> receiver) { | ||
| 558 | + TRACK_V8_FAST_API_CALL("histogram.count"); | ||
| 564 | 559 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 565 | 560 | return static_cast<double>((*histogram)->Count()); | |
| 566 | 561 | } | |
| 567 | 562 | ||
| 568 | - double HistogramImpl::FastGetMin(Local<Value> unused, Local<Value> receiver) { | ||
| 563 | + double HistogramImpl::FastGetMin(Local<Value> receiver) { | ||
| 564 | + TRACK_V8_FAST_API_CALL("histogram.min"); | ||
| 569 | 565 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 570 | 566 | return static_cast<double>((*histogram)->Min()); | |
| 571 | 567 | } | |
| 572 | 568 | ||
| 573 | - double HistogramImpl::FastGetMax(Local<Value> unused, Local<Value> receiver) { | ||
| 569 | + double HistogramImpl::FastGetMax(Local<Value> receiver) { | ||
| 570 | + TRACK_V8_FAST_API_CALL("histogram.max"); | ||
| 574 | 571 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 575 | 572 | return static_cast<double>((*histogram)->Max()); | |
| 576 | 573 | } | |
| 577 | 574 | ||
| 578 | - double HistogramImpl::FastGetMean(Local<Value> unused, Local<Value> receiver) { | ||
| 575 | + double HistogramImpl::FastGetMean(Local<Value> receiver) { | ||
| 576 | + TRACK_V8_FAST_API_CALL("histogram.mean"); | ||
| 579 | 577 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 580 | 578 | return (*histogram)->Mean(); | |
| 581 | 579 | } | |
| 582 | 580 | ||
| 583 | - double HistogramImpl::FastGetExceeds(Local<Value> unused, | ||
| 584 | - Local<Value> receiver) { | ||
| 581 | + double HistogramImpl::FastGetExceeds(Local<Value> receiver) { | ||
| 582 | + TRACK_V8_FAST_API_CALL("histogram.exceeds"); | ||
| 585 | 583 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 586 | 584 | return static_cast<double>((*histogram)->Exceeds()); | |
| 587 | 585 | } | |
| 588 | 586 | ||
| 589 | - double HistogramImpl::FastGetStddev(Local<Value> unused, | ||
| 590 | - Local<Value> receiver) { | ||
| 587 | + double HistogramImpl::FastGetStddev(Local<Value> receiver) { | ||
| 588 | + TRACK_V8_FAST_API_CALL("histogram.stddev"); | ||
| 591 | 589 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 592 | 590 | return (*histogram)->Stddev(); | |
| 593 | 591 | } | |
| 594 | 592 | ||
| 595 | - double HistogramImpl::FastGetPercentile(Local<Value> unused, | ||
| 596 | - Local<Value> receiver, | ||
| 593 | + double HistogramImpl::FastGetPercentile(Local<Value> receiver, | ||
| 597 | 594 | const double percentile) { | |
| 595 | + TRACK_V8_FAST_API_CALL("histogram.percentile"); | ||
| 598 | 596 | HistogramImpl* histogram = HistogramImpl::FromJSObject(receiver); | |
| 599 | 597 | return static_cast<double>((*histogram)->Percentile(percentile)); | |
| 600 | 598 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -101,22 +101,14 @@ class HistogramImpl { | |||
| 101 | 101 | static void GetPercentilesBigInt( | |
| 102 | 102 | const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 103 | 103 | ||
| 104 | - static void FastReset(v8::Local<v8::Value> unused, | ||
| 105 | - v8::Local<v8::Value> receiver); | ||
| 106 | - static double FastGetCount(v8::Local<v8::Value> unused, | ||
| 107 | - v8::Local<v8::Value> receiver); | ||
| 108 | - static double FastGetMin(v8::Local<v8::Value> unused, | ||
| 109 | - v8::Local<v8::Value> receiver); | ||
| 110 | - static double FastGetMax(v8::Local<v8::Value> unused, | ||
| 111 | - v8::Local<v8::Value> receiver); | ||
| 112 | - static double FastGetMean(v8::Local<v8::Value> unused, | ||
| 113 | - v8::Local<v8::Value> receiver); | ||
| 114 | - static double FastGetExceeds(v8::Local<v8::Value> unused, | ||
| 115 | - v8::Local<v8::Value> receiver); | ||
| 116 | - static double FastGetStddev(v8::Local<v8::Value> unused, | ||
| 117 | - v8::Local<v8::Value> receiver); | ||
| 118 | - static double FastGetPercentile(v8::Local<v8::Value> unused, | ||
| 119 | - v8::Local<v8::Value> receiver, | ||
| 104 | + static void FastReset(v8::Local<v8::Value> receiver); | ||
| 105 | + static double FastGetCount(v8::Local<v8::Value> receiver); | ||
| 106 | + static double FastGetMin(v8::Local<v8::Value> receiver); | ||
| 107 | + static double FastGetMax(v8::Local<v8::Value> receiver); | ||
| 108 | + static double FastGetMean(v8::Local<v8::Value> receiver); | ||
| 109 | + static double FastGetExceeds(v8::Local<v8::Value> receiver); | ||
| 110 | + static double FastGetStddev(v8::Local<v8::Value> receiver); | ||
| 111 | + static double FastGetPercentile(v8::Local<v8::Value> receiver, | ||
| 120 | 112 | const double percentile); | |
| 121 | 113 | ||
| 122 | 114 | static void AddMethods(v8::Isolate* isolate, | |
@@ -165,13 +157,8 @@ class HistogramBase final : public BaseObject, public HistogramImpl { | |||
| 165 | 157 | static void RecordDelta(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 166 | 158 | static void Add(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 167 | 159 | ||
| 168 | - static void FastRecord( | ||
| 169 | - v8::Local<v8::Value> unused, | ||
| 170 | - v8::Local<v8::Value> receiver, | ||
| 171 | - const int64_t value, | ||
| 172 | - v8::FastApiCallbackOptions& options); // NOLINT(runtime/references) | ||
| 173 | - static void FastRecordDelta(v8::Local<v8::Value> unused, | ||
| 174 | - v8::Local<v8::Value> receiver); | ||
| 160 | + static void FastRecord(v8::Local<v8::Value> receiver, const int64_t value); | ||
| 161 | + static void FastRecordDelta(v8::Local<v8::Value> receiver); | ||
| 175 | 162 | ||
| 176 | 163 | HistogramBase( | |
| 177 | 164 | Environment* env, | |
@@ -243,11 +230,8 @@ class IntervalHistogram final : public HandleWrap, public HistogramImpl { | |||
| 243 | 230 | static void Start(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 244 | 231 | static void Stop(const v8::FunctionCallbackInfo<v8::Value>& args); | |
| 245 | 232 | ||
| 246 | - static void FastStart(v8::Local<v8::Value> unused, | ||
| 247 | - v8::Local<v8::Value> receiver, | ||
| 248 | - bool reset); | ||
| 249 | - static void FastStop(v8::Local<v8::Value> unused, | ||
| 250 | - v8::Local<v8::Value> receiver); | ||
| 233 | + static void FastStart(v8::Local<v8::Value> receiver, bool reset); | ||
| 234 | + static void FastStop(v8::Local<v8::Value> receiver); | ||
| 251 | 235 | ||
| 252 | 236 | BaseObject::TransferMode GetTransferMode() const override { | |
| 253 | 237 | return TransferMode::kCloneable; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,35 @@ | |||
| 1 | + // Flags: --expose-internals --no-warnings --allow-natives-syntax | ||
| 2 | + 'use strict'; | ||
| 3 | + | ||
| 4 | + const common = require('../common'); | ||
| 5 | + const assert = require('assert'); | ||
| 6 | + | ||
| 7 | + const { internalBinding } = require('internal/test/binding'); | ||
| 8 | + | ||
| 9 | + const histogram = require('perf_hooks').createHistogram(); | ||
| 10 | + | ||
| 11 | + function testFastMethods() { | ||
| 12 | + histogram.record(1); | ||
| 13 | + histogram.recordDelta(); | ||
| 14 | + histogram.percentile(50); | ||
| 15 | + histogram.reset(); | ||
| 16 | + } | ||
| 17 | + | ||
| 18 | + eval('%PrepareFunctionForOptimization(histogram.record)'); | ||
| 19 | + eval('%PrepareFunctionForOptimization(histogram.recordDelta)'); | ||
| 20 | + eval('%PrepareFunctionForOptimization(histogram.percentile)'); | ||
| 21 | + eval('%PrepareFunctionForOptimization(histogram.reset)'); | ||
| 22 | + testFastMethods(); | ||
| 23 | + eval('%OptimizeFunctionOnNextCall(histogram.record)'); | ||
| 24 | + eval('%OptimizeFunctionOnNextCall(histogram.recordDelta)'); | ||
| 25 | + eval('%OptimizeFunctionOnNextCall(histogram.percentile)'); | ||
| 26 | + eval('%OptimizeFunctionOnNextCall(histogram.reset)'); | ||
| 27 | + testFastMethods(); | ||
| 28 | + | ||
| 29 | + if (common.isDebug) { | ||
| 30 | + const { getV8FastApiCallCount } = internalBinding('debug'); | ||
| 31 | + assert.strictEqual(getV8FastApiCallCount('histogram.record'), 1); | ||
| 32 | + assert.strictEqual(getV8FastApiCallCount('histogram.recordDelta'), 1); | ||
| 33 | + assert.strictEqual(getV8FastApiCallCount('histogram.percentile'), 1); | ||
| 34 | + assert.strictEqual(getV8FastApiCallCount('histogram.reset'), 1); | ||
| 35 | + } | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -41,8 +41,10 @@ const { inspect } = require('util'); | |||
| 41 | 41 | code: 'ERR_INVALID_ARG_TYPE' | |
| 42 | 42 | }); | |
| 43 | 43 | }); | |
| 44 | - throws(() => h.record(0, Number.MAX_SAFE_INTEGER + 1), { | ||
| 45 | - code: 'ERR_OUT_OF_RANGE' | ||
| 44 | + [0, Number.MAX_SAFE_INTEGER + 1].forEach((i) => { | ||
| 45 | + throws(() => h.record(i), { | ||
| 46 | + code: 'ERR_OUT_OF_RANGE' | ||
| 47 | + }); | ||
| 46 | 48 | }); | |
| 47 | 49 | ||
| 48 | 50 | strictEqual(h.min, 1); | |
| Back | FazBrowse Home | New Git URL |
0 commit comments