Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/rust/jsg-test/ffi.c++
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,10 @@ size_t used_global_handles_size(Isolate* isolate) {
return stats.used_global_handles_size();
}

int64_t external_memory(Isolate* isolate) {
return isolate->GetExternalMemory();
}

::rust::String take_heap_snapshot(Isolate* isolate) {
kj::Vector<char> serialized;
::workerd::jsg::HeapSnapshotActivity activity([](auto, auto) { return true; });
Expand Down
4 changes: 4 additions & 0 deletions src/rust/jsg-test/ffi.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,10 @@ void run_unlocked(Isolate* isolate, size_t data, ::rust::Fn<void(size_t)> callba
// v8::HeapStatistics::used_global_handles_size() of the isolate.
size_t used_global_handles_size(Isolate* isolate);

// The external memory that embedders have attributed to the isolate: the total V8 keeps of
// AdjustAmountOfExternalAllocatedMemory() calls, which v8::HeapStatistics does not report.
int64_t external_memory(Isolate* isolate);

// Takes a heap snapshot of the isolate and returns it serialized as JSON.
::rust::String take_heap_snapshot(Isolate* isolate);

Expand Down
13 changes: 13 additions & 0 deletions src/rust/jsg-test/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ mod ffi {
#[allow(dead_code)]
pub unsafe fn used_global_handles_size(isolate: *mut Isolate) -> usize;

/// The external memory that embedders have attributed to the isolate; see
/// `external_memory` in `ffi.h`.
pub unsafe fn external_memory(isolate: *mut Isolate) -> i64;

/// Takes a heap snapshot of the isolate, which includes what `jsg::MemoryTracker`
/// reports, and returns it serialized as JSON.
pub unsafe fn take_heap_snapshot(isolate: *mut Isolate) -> Result<String>;
Expand Down Expand Up @@ -698,6 +702,15 @@ impl Harness {
unsafe { ffi::used_global_handles_size(lock.isolate().as_ffi()) }
}

/// The external memory that `jsg::ExternalMemoryAdjustment`s, of Rust or C++, have
/// attributed to the isolate and that has reached V8. Tests compare it with amounts taken
/// earlier.
#[must_use]
pub fn external_memory(lock: &mut jsg::Lock<'_>) -> i64 {
// SAFETY: isolate is valid and locked (guaranteed by Lock).
unsafe { ffi::external_memory(lock.isolate().as_ffi()) }
}

/// Takes a heap snapshot, as the inspector's `HeapProfiler.takeHeapSnapshot` does, and
/// returns it in V8's JSON format.
///
Expand Down
Loading
Loading