Is there a thread-safe way to get the current heap usage for an isolate? What I observed is that if one thread is performing an allocation, attempting to call v8::Isolate::getHeapUsage from another triggers a data race. Apologies if I missed it, but I didn't see anything relevant in the documentation or past discussion threads. The use case is that I'd like to be able to track heap usage over time as a long-running call into a JavaScript function executes. The output I get (under a recent Clang with TSan) is of the form below. Thanks in advance!
2024-12-16 20:49:36,949 WARNING: ThreadSanitizer: data race (pid=21642)
2024-12-16 20:49:36,949 Write of size 8 at 0x725000002be8 by main thread (mutexes: write M0):
2024-12-16 20:49:36,949 #0 v8::internal::LinearAllocationArea::IncrementTop(unsigned long) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x36fed5d)
2024-12-16 20:49:36,949 #1 v8::internal::SpaceWithLinearArea::AllocateFastUnaligned(int, v8::internal::AllocationOrigin) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x384ab82)
2024-12-16 20:49:36,949 #2 v8::internal::SpaceWithLinearArea::AllocateRaw(int, v8::internal::AllocationAlignment, v8::internal::AllocationOrigin) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x384a807)
2024-12-16 20:49:36,949 #3 v8::internal::AllocationResult v8::internal::HeapAllocator::AllocateRaw<(v8::internal::AllocationType)2>(int, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x3849227)
2024-12-16 20:49:36,949 #4 v8::internal::HeapAllocator::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x3848498)
2024-12-16 20:49:36,949 #5 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x39aae43)
2024-12-16 20:49:36,949 #6 v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x39ab103)
...
2024-12-16 20:49:36,951 Previous read of size 8 at 0x725000002be8 by thread T17 (mutexes: write M1):
2024-12-16 20:49:36,951 #0 v8::internal::LinearAllocationArea::top() const <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x36fd936)
2024-12-16 20:49:36,951 #1 v8::internal::PagedSpaceBase::CommittedPhysicalMemory() const <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x3b4c1c1)
2024-12-16 20:49:36,951 #2 v8::internal::Heap::CommittedPhysicalMemory() <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x390d3a1)
2024-12-16 20:49:36,951 #3 v8::Isolate::GetHeapStatistics(v8::HeapStatistics*) <null> (libexternal_Sv8_Slibv8_Ulibshared_Uicu.so+0x2ec38ad)
...