@@ -315,9 +315,7 @@ void SignalHandler::HandleProfilerSignal(int sig,
315
315
auto time_from = Now ();
316
316
old_handler (sig, info, context);
317
317
auto time_to = Now ();
318
- int64_t async_id = -1 ;
319
- // don't capture for now until we work out the issues with GC and thread start
320
- // static_cast<int64_t>(node::AsyncHooksGetExecutionAsyncId(isolate));
318
+ auto async_id = prof->GetAsyncId (isolate);
321
319
prof->PushContext (time_from, time_to, cpu_time, async_id);
322
320
}
323
321
#else
@@ -492,6 +490,20 @@ std::shared_ptr<ContextsByNode> WallProfiler::GetContextsByNode(
492
490
return contextsByNode;
493
491
}
494
492
493
+ void GCPrologueCallback (Isolate* isolate,
494
+ GCType type,
495
+ GCCallbackFlags flags,
496
+ void * data) {
497
+ static_cast <WallProfiler*>(data)->OnGCStart (isolate);
498
+ }
499
+
500
+ void GCEpilogueCallback (Isolate* isolate,
501
+ GCType type,
502
+ GCCallbackFlags flags,
503
+ void * data) {
504
+ static_cast <WallProfiler*>(data)->OnGCEnd ();
505
+ }
506
+
495
507
WallProfiler::WallProfiler (std::chrono::microseconds samplingPeriod,
496
508
std::chrono::microseconds duration,
497
509
bool includeLines,
@@ -517,6 +529,7 @@ WallProfiler::WallProfiler(std::chrono::microseconds samplingPeriod,
517
529
curContext_.store (&context1_, std::memory_order_relaxed);
518
530
collectionMode_.store (CollectionMode::kNoCollect , std::memory_order_relaxed);
519
531
532
+ // TODO: bind to this isolate? Would fix the Dispose(nullptr) issue.
520
533
auto isolate = v8::Isolate::GetCurrent ();
521
534
v8::Local<v8::ArrayBuffer> buffer =
522
535
v8::ArrayBuffer::New (isolate, sizeof (uint32_t ) * kFieldCount );
@@ -526,6 +539,10 @@ WallProfiler::WallProfiler(std::chrono::microseconds samplingPeriod,
526
539
fields_ = static_cast <uint32_t *>(buffer->GetBackingStore ()->Data ());
527
540
jsArray_ = v8::Global<v8::Uint32Array>(isolate, jsArray);
528
541
std::fill (fields_, fields_ + kFieldCount , 0 );
542
+
543
+ gcCount = 0 ;
544
+ isolate->AddGCPrologueCallback (&GCPrologueCallback, this );
545
+ isolate->AddGCEpilogueCallback (&GCEpilogueCallback, this );
529
546
}
530
547
531
548
WallProfiler::~WallProfiler () {
@@ -538,6 +555,11 @@ void WallProfiler::Dispose(Isolate* isolate) {
538
555
cpuProfiler_ = nullptr ;
539
556
540
557
g_profilers.RemoveProfiler (isolate, this );
558
+
559
+ if (isolate != nullptr ) {
560
+ isolate->RemoveGCPrologueCallback (&GCPrologueCallback, this );
561
+ isolate->RemoveGCEpilogueCallback (&GCEpilogueCallback, this );
562
+ }
541
563
}
542
564
}
543
565
0 commit comments