Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Tracing

The memtrace feature allows to trace usage of memory allocators. This is a debug feature, so it is not meant to be used in production.

To use it, compile the kernel with the memtrace feature:

cargo build --features memtrace

When run, the kernel will then write tracing data to the COM2 serial port.

This data can then be fed to kern-profile to generate a FlameGraph.

Data format

The output data is a series of samples. A sample represents an operation on the allocator.

The following operations exist:

IDNameDescription
0allocAllocate memory
1reallocResize a previously allocated region of memory
2freeFrees a previously allocated region of memory

Each sample is written one after the other and has the following layout in memory:

OffsetSizeNameDescription
01nlenThe length of the name of the allocator
1nlennameThe name of the allocator
nlen + 11opThe ID of the operation (see table above)
nlen + 28ptrThe address of the region affected by the operation
nlen + 108sizeThe new size of the region affected by the operation
nlen + 181nframeThe number of frames in the callstack
nlen + 19nframe * 8framesThe pointers of the frames in the callstack