class SharedMemoryABI

Defined at line 144 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

Use only explicitly-sized types below. DO NOT use size_t or any architecture

dependent size (e.g. size_t) in the struct fields. This buffer will be read

and written by processes that have a different bitness in the same OS.

Instead it's fine to assume little-endianess. Big-endian is a dream we are

not currently pursuing.

Public Members

static const size_t kMinPageSize
static const size_t kMaxPageSize
static const size_t kMaxChunksPerPage
static const size_t kPacketHeaderSize
static const size_t kPacketSizeDropPacket
static const char *const[] kChunkStateStr
static const uint32_t[] kNumChunksForLayout
static const uint32_t kChunkAlignment
static const uint32_t kChunkShift
static const uint32_t kChunkMask
static const uint32_t kLayoutMask
static const uint32_t kLayoutShift
static const uint32_t kAllChunksMask
static const uint32_t kAllChunksComplete
static const uint32_t kAllChunksFree
static const size_t kInvalidPageIdx

Public Methods

uint8_t * start ()

Defined at line 468 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

uint8_t * end ()

Defined at line 469 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

size_t size ()

Defined at line 470 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

size_t page_size ()

Defined at line 471 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

size_t num_pages ()

Defined at line 472 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

bool is_valid ()

Defined at line 473 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

bool use_shmem_emulation ()

Defined at line 474 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

uint8_t * page_start (size_t page_idx)

Defined at line 476 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

PageHeader * page_header (size_t page_idx)

Defined at line 481 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

bool is_page_free (size_t page_idx)

Returns true if the page is fully clear and has not been partitioned yet.

The state of the page can change at any point after this returns (or even

before). The Producer should use this only as a hint to decide out whether

it should TryPartitionPage() or acquire an individual chunk.

Defined at line 489 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

bool is_page_complete (size_t page_idx)

Returns true if all chunks in the page are kChunkComplete. As above, this

is advisory only. The Service is supposed to use this only to decide

whether to TryAcquireAllChunksForReading() or not.

Defined at line 496 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

std::string page_header_dbg (size_t page_idx)

For testing / debugging only.

Defined at line 506 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

uint32_t GetPageHeaderBitmap (size_t page_idx, std::memory_order order)

Returns the page header bitmap, which is a bitmap that specifies the

chunking layout of the page and each chunk's current state. Unless

explicitly specified, reads with an acquire-load semantic to ensure a

producer's writes corresponding to an update of the bitmap (e.g. clearing

a chunk's header) are observed consistently.

Defined at line 516 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

Chunk TryAcquireChunkForWriting (size_t page_idx, size_t chunk_idx, const ChunkHeader * header)

Tries to atomically mark a single chunk within the page as

kChunkBeingWritten. Returns an invalid chunk if the page is not partitioned

or the chunk is not in the kChunkFree state. If succeeds sets the chunk

header to |header|.

Defined at line 537 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

Chunk TryAcquireChunkForReading (size_t page_idx, size_t chunk_idx)

Similar to TryAcquireChunkForWriting. Fails if the chunk isn't in the

kChunkComplete state.

Defined at line 545 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

Chunk MakeChunkFromSerializedData (uint8_t * data, uint16_t size, uint8_t chunk_idx)

Creates a Chunk by adopting the given buffer (|data| and |size|) and chunk

index. This is used for chunk data passed over the wire (e.g. tcp or

vsock). The chunk should *not* be freed to the shared memory.

Defined at line 559 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

size_t ReleaseChunkAsComplete (Chunk chunk)

Puts a chunk into the kChunkComplete state. Returns the page index.

Defined at line 566 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

size_t ReleaseChunkAsFree (Chunk chunk)

Puts a chunk into the kChunkFree state. Returns the page index.

Defined at line 571 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

ChunkState GetChunkState (size_t page_idx, size_t chunk_idx)

Defined at line 575 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

uint16_t GetChunkSizeFromHeaderBitmap (uint32_t header_bitmap)

Defined at line 582 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

ChunkState GetChunkStateFromHeaderBitmap (uint32_t header_bitmap, size_t chunk_idx)

Defined at line 586 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

uint32_t GetFreeChunks (size_t page_idx)

Returns a bitmap in which each bit is set if the corresponding Chunk exists

in the page (according to the page header bitmap) and is free. If the page

is not partitioned it returns 0 (as if the page had no free chunks).

Chunk GetChunkUnchecked (size_t page_idx, uint32_t header_bitmap, size_t chunk_idx)

The caller must have successfully TryAcquireAllChunksForReading() or it

needs to guarantee that the chunk is already in the kChunkBeingWritten

state.

PageLayout GetLayoutFromHeaderBitmap (uint32_t header_bitmap)

Defined at line 592 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

uint32_t GetNumChunksFromHeaderBitmap (uint32_t header_bitmap)

Defined at line 598 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

std::pair<size_t, size_t> GetPageAndChunkIndex (const Chunk & chunk)
uint32_t GetUsedChunks (uint32_t header_bitmap)

Returns a bitmap in which each bit is set if the corresponding Chunk exists

in the page (according to the page layout) and is not free. If the page is

not partitioned it returns 0 (as if the page had no used chunks). Bit N

corresponds to Chunk N.

Defined at line 607 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

void SharedMemoryABI (uint8_t * start, size_t size, size_t page_size, ShmemMode mode)

Construct an instance from an existing shared memory buffer.

void SharedMemoryABI ()
void Initialize (uint8_t * start, size_t size, size_t page_size, ShmemMode mode)
bool TryPartitionPage (size_t page_idx, PageLayout layout)

Tries to atomically partition a page with the given |layout|. Returns true

if the page was free and has been partitioned with the given |layout|,

false if the page wasn't free anymore by the time we got there.

If succeeds all the chunks are atomically set in the kChunkFree state.

Enumerations

enum ChunkState
Name Value
kChunkFree 0
kChunkBeingWritten 1
kChunkBeingRead 2
kChunkComplete 3

Chunk states and transitions:

kChunkFree

<

----------------+

| (Producer) |

V |

kChunkBeingWritten |

| (Producer) |

V |

kChunkComplete |

| (Service) |

V |

kChunkBeingRead |

| (Service) |

+------------------------+

The ABI has an "emulation mode" for transports where shared memory isn't

supported. In this mode, kChunkBeingRead is skipped. A chunk in the

kChunkComplete state is released as free after the producer serializes

chunk content to the protobuf message.

Defined at line 186 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

enum PageLayout
Name Value
kPageNotPartitioned 0
kPageDiv1 1
kPageDiv2 2
kPageDiv4 3
kPageDiv7 4
kPageDiv14 5
kPageDivReserved1 6
kPageDivReserved2 7
kNumPageLayouts 8

Defined at line 207 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

enum ShmemMode
Name Value
kDefault 0
kShmemEmulation 1

Defined at line 236 of file ../../third_party/perfetto/include/perfetto/ext/tracing/core/shared_memory_abi.h

Records