Skip to content

Commit

Permalink
ref(profiling): unref timer
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Jun 3, 2024
1 parent 8b926ea commit d6c3332
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions packages/profiling-node/bindings/cpu_profiler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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(&timer, this);
uv_unref(reinterpret_cast<uv_handle_t *>(&timer));
}

static void ticker(uv_timer_t *);
Expand Down Expand Up @@ -196,6 +197,10 @@ void MeasurementsTicker::cpu_callback() {
};

void MeasurementsTicker::ticker(uv_timer_t *handle) {
if(handle == nullptr) {
return;
}

MeasurementsTicker *self = static_cast<MeasurementsTicker *>(handle->data);
self->heap_callback();
self->cpu_callback();
Expand Down Expand Up @@ -231,6 +236,19 @@ class Profiler {
: measurements_ticker(uv_default_loop()),
cpu_profiler(
v8::CpuProfiler::New(isolate, kNamingMode, GetLoggingMode())) {}

~Profiler() {
for (auto &profile : active_profiles) {
CleanupSentryProfile(this, profile.second, profile.first);
}

active_profiles.clear();

if (cpu_profiler) {
cpu_profiler->Dispose();
cpu_profiler = nullptr;
}
}
};

class SentryProfile {
Expand Down Expand Up @@ -1041,16 +1059,6 @@ void FreeAddonData(napi_env env, void *data, void *hint) {
return;
}

if (!profiler->active_profiles.empty()) {
for (auto &profile : profiler->active_profiles) {
CleanupSentryProfile(profiler, profile.second, profile.first);
}
}

if (profiler->cpu_profiler != nullptr) {
profiler->cpu_profiler->Dispose();
}

delete profiler;
}

Expand Down

0 comments on commit d6c3332

Please sign in to comment.