class ScatteredStreamWriter
Defined at line 47 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
This class deals with the following problem: append-only proto messages want
to write a stream of bytes, without caring about the implementation of the
underlying buffer (which concretely will be either the trace ring buffer
or a heap-allocated buffer). The main deal is: proto messages don't know in
advance what their size will be.
Due to the tracing buffer being split into fixed-size chunks, on some
occasions, these writes need to be spread over two (or more) non-contiguous
chunks of memory. Similarly, when the buffer is backed by the heap, we want
to avoid realloc() calls, as they might cause a full copy of the contents
of the buffer.
The purpose of this class is to abstract away the non-contiguous write logic.
This class knows how to deal with writes as long as they fall in the same
ContiguousMemoryRange and defers the chunk-chaining logic to the Delegate.
Public Methods
void ScatteredStreamWriter (Delegate * delegate)
void WriteByte (uint8_t value)
Defined at line 73 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
void WriteBytesUnsafe (const uint8_t * src, size_t size)
Assumes that the caller checked that there is enough headroom.
TODO(primiano): perf optimization, this is a tracing hot path. The
compiler can make strong optimization on std::copy if the size arg is a
constexpr. Make a templated variant of this for fixed-size writes.
TODO(primiano): restrict / noalias might also help.
Defined at line 84 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
void WriteBytes (const uint8_t * src, size_t size)
Defined at line 91 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
void ~ScatteredStreamWriter ()
void WriteBytesSlowPath (const uint8_t * src, size_t size)
uint8_t * ReserveBytes (size_t size)
Reserves a fixed amount of bytes to be backfilled later. The reserved range
is guaranteed to be contiguous and not span across chunks. |size| has to be
<
= than the size of a new buffer returned by the Delegate::GetNewBuffer().
uint8_t * ReserveBytesUnsafe (size_t size)
Fast (but unsafe) version of the above. The caller must have previously
checked that there are at least |size| contiguous bytes available.
Returns only the start pointer of the reservation.
Defined at line 113 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
void Reset (ContiguousMemoryRange range)
Resets the buffer boundaries and the write pointer to the given |range|.
Subsequent WriteByte(s) will write into |range|.
void Extend ()
Commits the current chunk and gets a new chunk from the delegate.
void Rewind (size_t size, size_t offset)
Shifts the previously written `size` bytes backwards in memory by `offset`
bytes, moving the write pointer back accordingly. The shifted result must
still be fully contained by the current range.
Defined at line 123 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
size_t bytes_available ()
Number of contiguous free bytes in |cur_range_| that can be written without
requesting a new buffer.
Defined at line 143 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
ContiguousMemoryRange cur_range ()
Defined at line 147 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
uint8_t * write_ptr ()
Defined at line 149 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
void set_write_ptr (uint8_t * write_ptr)
Defined at line 151 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
uint64_t written ()
Defined at line 156 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
uint64_t written_previously ()
Defined at line 161 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h
uint8_t * AnnotatePatch (uint8_t * patch_addr)
Defined at line 163 of file ../../third_party/perfetto/include/perfetto/protozero/scattered_stream_writer.h