From 78ead065d954823d06ad8ad05424a740b521f5e2 Mon Sep 17 00:00:00 2001 From: JonasBa Date: Mon, 3 Jun 2024 19:33:04 -0400 Subject: [PATCH 1/2] ref(profiling): unref timer --- .../profiling-node/bindings/cpu_profiler.cc | 32 +++++++++++-------- 1 file changed, 19 insertions(+), 13 deletions(-) diff --git a/packages/profiling-node/bindings/cpu_profiler.cc b/packages/profiling-node/bindings/cpu_profiler.cc index 64a82ba61910..96a5bbfeaf62 100644 --- a/packages/profiling-node/bindings/cpu_profiler.cc +++ b/packages/profiling-node/bindings/cpu_profiler.cc @@ -76,7 +76,8 @@ class MeasurementsTicker { MeasurementsTicker(uv_loop_t *loop) : period_ms(100), isolate(v8::Isolate::GetCurrent()) { uv_timer_init(loop, &timer); - timer.data = this; + uv_handle_set_data(reinterpret_cast(&timer), this); + uv_unref(reinterpret_cast(&timer)); } static void ticker(uv_timer_t *); @@ -196,6 +197,10 @@ void MeasurementsTicker::cpu_callback() { }; void MeasurementsTicker::ticker(uv_timer_t *handle) { + if(handle == nullptr) { + return; + } + MeasurementsTicker *self = static_cast(handle->data); self->heap_callback(); self->cpu_callback(); @@ -323,18 +328,6 @@ void SentryProfile::Start(Profiler *profiler) { status = ProfileStatus::kStarted; } -static void CleanupSentryProfile(Profiler *profiler, - SentryProfile *sentry_profile, - const std::string &profile_id) { - if (sentry_profile == nullptr) { - return; - } - - sentry_profile->Stop(profiler); - profiler->active_profiles.erase(profile_id); - delete sentry_profile; -}; - v8::CpuProfile *SentryProfile::Stop(Profiler *profiler) { // Stop the CPU Profiler v8::CpuProfile *profile = profiler->cpu_profiler->StopProfiling( @@ -376,6 +369,18 @@ const uint16_t &SentryProfile::cpu_usage_write_index() const { return cpu_write_index; }; +static void CleanupSentryProfile(Profiler *profiler, + SentryProfile *sentry_profile, + const std::string &profile_id) { + if (sentry_profile == nullptr) { + return; + } + + sentry_profile->Stop(profiler); + profiler->active_profiles.erase(profile_id); + delete sentry_profile; +}; + #ifdef _WIN32 static const char kPlatformSeparator = '\\'; static const char kWinDiskPrefix = ':'; @@ -1049,6 +1054,7 @@ void FreeAddonData(napi_env env, void *data, void *hint) { if (profiler->cpu_profiler != nullptr) { profiler->cpu_profiler->Dispose(); + profiler->cpu_profiler = nullptr; } delete profiler; From 74e1b8cc67b9ef9d2baaeb6ebcccb3ea589bf7d3 Mon Sep 17 00:00:00 2001 From: JonasBa Date: Mon, 3 Jun 2024 21:05:19 -0400 Subject: [PATCH 2/2] lint --- packages/profiling-node/bindings/cpu_profiler.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/profiling-node/bindings/cpu_profiler.cc b/packages/profiling-node/bindings/cpu_profiler.cc index 96a5bbfeaf62..6f9651bcd6a4 100644 --- a/packages/profiling-node/bindings/cpu_profiler.cc +++ b/packages/profiling-node/bindings/cpu_profiler.cc @@ -197,7 +197,7 @@ void MeasurementsTicker::cpu_callback() { }; void MeasurementsTicker::ticker(uv_timer_t *handle) { - if(handle == nullptr) { + if (handle == nullptr) { return; }