| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 7dd897f commit 67aa5ef
6 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -34,6 +34,7 @@ namespace node { | |||
| 34 | 34 | #define NODE_ASYNC_NON_CRYPTO_PROVIDER_TYPES(V) \ | |
| 35 | 35 | V(NONE) \ | |
| 36 | 36 | V(DNSCHANNEL) \ | |
| 37 | + V(ELDHISTOGRAM) \ | ||
| 37 | 38 | V(FILEHANDLE) \ | |
| 38 | 39 | V(FILEHANDLECLOSEREQ) \ | |
| 39 | 40 | V(FSEVENTWRAP) \ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -84,6 +84,17 @@ void HandleWrap::Close(Local<Value> close_callback) { | |||
| 84 | 84 | } | |
| 85 | 85 | ||
| 86 | 86 | ||
| 87 | + void HandleWrap::MakeWeak() { | ||
| 88 | + persistent().SetWeak( | ||
| 89 | + this, | ||
| 90 | + [](const v8::WeakCallbackInfo<HandleWrap>& data) { | ||
| 91 | + HandleWrap* handle_wrap = data.GetParameter(); | ||
| 92 | + handle_wrap->persistent().Reset(); | ||
| 93 | + handle_wrap->Close(); | ||
| 94 | + }, v8::WeakCallbackType::kParameter); | ||
| 95 | + } | ||
| 96 | + | ||
| 97 | + | ||
| 87 | 98 | void HandleWrap::MarkAsInitialized() { | |
| 88 | 99 | env()->handle_wrap_queue()->PushBack(this); | |
| 89 | 100 | state_ = kInitialized; | |
@@ -115,15 +126,14 @@ void HandleWrap::OnClose(uv_handle_t* handle) { | |||
| 115 | 126 | HandleScope scope(env->isolate()); | |
| 116 | 127 | Context::Scope context_scope(env->context()); | |
| 117 | 128 | ||
| 118 | - // The wrap object should still be there. | ||
| 119 | - CHECK_EQ(wrap->persistent().IsEmpty(), false); | ||
| 120 | 129 | CHECK_EQ(wrap->state_, kClosing); | |
| 121 | 130 | ||
| 122 | 131 | wrap->state_ = kClosed; | |
| 123 | 132 | ||
| 124 | 133 | wrap->OnClose(); | |
| 125 | 134 | ||
| 126 | - if (wrap->object()->Has(env->context(), env->handle_onclose_symbol()) | ||
| 135 | + if (!wrap->persistent().IsEmpty() && | ||
| 136 | + wrap->object()->Has(env->context(), env->handle_onclose_symbol()) | ||
| 127 | 137 | .FromMaybe(false)) { | |
| 128 | 138 | wrap->MakeCallback(env->handle_onclose_symbol(), 0, nullptr); | |
| 129 | 139 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -76,6 +76,8 @@ class HandleWrap : public AsyncWrap { | |||
| 76 | 76 | static v8::Local<v8::FunctionTemplate> GetConstructorTemplate( | |
| 77 | 77 | Environment* env); | |
| 78 | 78 | ||
| 79 | + void MakeWeak(); // This hides BaseObject::MakeWeak() | ||
| 80 | + | ||
| 79 | 81 | protected: | |
| 80 | 82 | HandleWrap(Environment* env, | |
| 81 | 83 | v8::Local<v8::Object> object, | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -477,31 +477,18 @@ static void ELDHistogramNew(const FunctionCallbackInfo<Value>& args) { | |||
| 477 | 477 | ELDHistogram::ELDHistogram( | |
| 478 | 478 | Environment* env, | |
| 479 | 479 | Local<Object> wrap, | |
| 480 | - int32_t resolution) : BaseObject(env, wrap), | ||
| 480 | + int32_t resolution) : HandleWrap(env, | ||
| 481 | + wrap, | ||
| 482 | + reinterpret_cast<uv_handle_t*>(&timer_), | ||
| 483 | + AsyncWrap::PROVIDER_ELDHISTOGRAM), | ||
| 481 | 484 | Histogram(1, 3.6e12), | |
| 482 | 485 | resolution_(resolution) { | |
| 483 | 486 | MakeWeak(); | |
| 484 | - timer_ = new uv_timer_t(); | ||
| 485 | - uv_timer_init(env->event_loop(), timer_); | ||
| 486 | - timer_->data = this; | ||
| 487 | + uv_timer_init(env->event_loop(), &timer_); | ||
| 487 | 488 | } | |
| 488 | 489 | ||
| 489 | - void ELDHistogram::CloseTimer() { | ||
| 490 | - if (timer_ == nullptr) | ||
| 491 | - return; | ||
| 492 | - | ||
| 493 | - env()->CloseHandle(timer_, [](uv_timer_t* handle) { delete handle; }); | ||
| 494 | - timer_ = nullptr; | ||
| 495 | - } | ||
| 496 | - | ||
| 497 | - ELDHistogram::~ELDHistogram() { | ||
| 498 | - Disable(); | ||
| 499 | - CloseTimer(); | ||
| 500 | - } | ||
| 501 | - | ||
| 502 | - void ELDHistogramDelayInterval(uv_timer_t* req) { | ||
| 503 | - ELDHistogram* histogram = | ||
| 504 | - reinterpret_cast<ELDHistogram*>(req->data); | ||
| 490 | + void ELDHistogram::DelayIntervalCallback(uv_timer_t* req) { | ||
| 491 | + ELDHistogram* histogram = ContainerOf(&ELDHistogram::timer_, req); | ||
| 505 | 492 | histogram->RecordDelta(); | |
| 506 | 493 | TRACE_COUNTER1(TRACING_CATEGORY_NODE2(perf, event_loop), | |
| 507 | 494 | "min", histogram->Min()); | |
@@ -537,21 +524,21 @@ bool ELDHistogram::RecordDelta() { | |||
| 537 | 524 | } | |
| 538 | 525 | ||
| 539 | 526 | bool ELDHistogram::Enable() { | |
| 540 | - if (enabled_) return false; | ||
| 527 | + if (enabled_ || IsHandleClosing()) return false; | ||
| 541 | 528 | enabled_ = true; | |
| 542 | 529 | prev_ = 0; | |
| 543 | - uv_timer_start(timer_, | ||
| 544 | - ELDHistogramDelayInterval, | ||
| 530 | + uv_timer_start(&timer_, | ||
| 531 | + DelayIntervalCallback, | ||
| 545 | 532 | resolution_, | |
| 546 | 533 | resolution_); | |
| 547 | - uv_unref(reinterpret_cast<uv_handle_t*>(timer_)); | ||
| 534 | + uv_unref(reinterpret_cast<uv_handle_t*>(&timer_)); | ||
| 548 | 535 | return true; | |
| 549 | 536 | } | |
| 550 | 537 | ||
| 551 | 538 | bool ELDHistogram::Disable() { | |
| 552 | - if (!enabled_) return false; | ||
| 539 | + if (!enabled_ || IsHandleClosing()) return false; | ||
| 553 | 540 | enabled_ = false; | |
| 554 | - uv_timer_stop(timer_); | ||
| 541 | + uv_timer_stop(&timer_); | ||
| 555 | 542 | return true; | |
| 556 | 543 | } | |
| 557 | 544 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -123,14 +123,12 @@ class GCPerformanceEntry : public PerformanceEntry { | |||
| 123 | 123 | PerformanceGCKind gckind_; | |
| 124 | 124 | }; | |
| 125 | 125 | ||
| 126 | - class ELDHistogram : public BaseObject, public Histogram { | ||
| 126 | + class ELDHistogram : public HandleWrap, public Histogram { | ||
| 127 | 127 | public: | |
| 128 | 128 | ELDHistogram(Environment* env, | |
| 129 | 129 | Local<Object> wrap, | |
| 130 | 130 | int32_t resolution); | |
| 131 | 131 | ||
| 132 | - ~ELDHistogram() override; | ||
| 133 | - | ||
| 134 | 132 | bool RecordDelta(); | |
| 135 | 133 | bool Enable(); | |
| 136 | 134 | bool Disable(); | |
@@ -149,13 +147,13 @@ class ELDHistogram : public BaseObject, public Histogram { | |||
| 149 | 147 | SET_SELF_SIZE(ELDHistogram) | |
| 150 | 148 | ||
| 151 | 149 | private: | |
| 152 | - void CloseTimer(); | ||
| 150 | + static void DelayIntervalCallback(uv_timer_t* req); | ||
| 153 | 151 | ||
| 154 | 152 | bool enabled_ = false; | |
| 155 | 153 | int32_t resolution_ = 0; | |
| 156 | 154 | int64_t exceeds_ = 0; | |
| 157 | 155 | uint64_t prev_ = 0; | |
| 158 | - uv_timer_t* timer_; | ||
| 156 | + uv_timer_t timer_; | ||
| 159 | 157 | }; | |
| 160 | 158 | ||
| 161 | 159 | } // namespace performance | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -50,6 +50,7 @@ const { getSystemErrorName } = require('util'); | |||
| 50 | 50 | delete providers.KEYPAIRGENREQUEST; | |
| 51 | 51 | delete providers.HTTPCLIENTREQUEST; | |
| 52 | 52 | delete providers.HTTPINCOMINGMESSAGE; | |
| 53 | + delete providers.ELDHISTOGRAM; | ||
| 53 | 54 | ||
| 54 | 55 | const objKeys = Object.keys(providers); | |
| 55 | 56 | if (objKeys.length > 0) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments