Nebula
Loading...
Searching...
No Matches
Nebula.MemoryProfile Class Reference

Detailed Description

The managed memory contract the editor's c# memory panel reads.

This side only answers with cumulative numbers. The panel keeps the history and computes the per frame deltas itself, so nothing here has to remember what it said last frame, and a hot reload does not take a history with it.

Read allocates nothing on a frame where nothing was collected. The running total is read precise: read approximate, the runtime publishes it in allocation quanta of about 8 KB rather than per allocation, so a steady few hundred bytes a frame shows as nothing for ten frames and then as one jump, which reads as a spike that never happened. The per generation numbers come from the snapshot of the last collection, and the only API that answers with them is GC.GetGCMemoryInfo, which allocates about 288 bytes per call because the spans it hands back are arrays the runtime makes for the call. That call is made only on the frame a collection happened, which is the only frame those numbers change.

Sample is the layout contract between the two sides and is copied to an unmanaged buffer, so it has to stay blittable, sequential and free of reference fields. Keep the 8 byte fields before the 4 byte fields so both sides agree on the offsets. The C++ mirror asserts its size in nsharp/memoryprofile.cc.

Classes

struct  Sample
 One snapshot of the managed GC state. More...

Static Public Member Functions

static unsafe void Read (IntPtr outBuffer)
 Write a sample into an unmanaged buffer that is at least sizeof(Sample) bytes large.
static void Collect ()
 Run a full blocking collection.

Static Private Member Functions

static unsafe void ReadSnapshot ()
 Read the runtime's snapshot of its last collection.

Static Private Attributes

static Sample snapshot
static int snapshotCollections
static bool snapshotRead

Member Function Documentation

◆ Collect()

void Nebula.MemoryProfile.Collect ( )
inlinestatic

Run a full blocking collection.

Called by the panel, which is the only side that asks for one.

◆ Read()

unsafe void Nebula.MemoryProfile.Read ( IntPtr outBuffer)
inlinestatic

Write a sample into an unmanaged buffer that is at least sizeof(Sample) bytes large.

◆ ReadSnapshot()

unsafe void Nebula.MemoryProfile.ReadSnapshot ( )
inlinestaticprivate

Read the runtime's snapshot of its last collection.

Called only on the frame a collection happened, because every field it answers with is what that collection measured.

Member Data Documentation

◆ snapshot

Sample Nebula.MemoryProfile.snapshot
staticprivate

◆ snapshotCollections

int Nebula.MemoryProfile.snapshotCollections
staticprivate

◆ snapshotRead

bool Nebula.MemoryProfile.snapshotRead
staticprivate

The documentation for this class was generated from the following file: