Crashpad
 
Loading...
Searching...
No Matches
crashpad::RingBufferAnnotation< Capacity > Class Template Referencefinal

An Annotation which wraps a LengthDelimitedRingBuffer of up to Capacity bytes in length. More...

#include "client/ring_buffer_annotation.h"

Inheritance diagram for crashpad::RingBufferAnnotation< Capacity >:
[legend]
Collaboration diagram for crashpad::RingBufferAnnotation< Capacity >:
[legend]

Public Member Functions

constexpr RingBufferAnnotation (Annotation::Type type, const char name[])
 Constructs a RingBufferAnnotation.
 
 RingBufferAnnotation (const RingBufferAnnotation &)=delete
 
RingBufferAnnotationoperator= (const RingBufferAnnotation &)=delete
 
 RingBufferAnnotation (RingBufferAnnotation &&)=default
 
RingBufferAnnotationoperator= (RingBufferAnnotation &&)=default
 
bool Push (const void *const buffer, RingBufferAnnotationCapacity buffer_length)
 Pushes data onto this annotation's ring buffer.
 
void ResetForTesting ()
 Reset the annotation (e.g., for testing). This method is not thread-safe.
 
- Public Member Functions inherited from crashpad::Annotation
constexpr Annotation (Type type, const char name[], void *value_ptr)
 Constructs a new annotation.
 
 Annotation (const Annotation &)=delete
 
Annotationoperator= (const Annotation &)=delete
 
void SetSize (ValueSizeType size)
 Specifies the number of bytes in value_ptr_ to include when generating a crash report.
 
void Clear ()
 Marks the annotation as cleared, indicating the value_ptr_ should not be included in a crash report.
 
bool is_set () const
 Tests whether the annotation has been set.
 
Type type () const
 
ValueSizeType size () const
 
const char * name () const
 
const void * value () const
 
ConcurrentAccessGuardMode concurrent_access_guard_mode () const
 
std::optional< ScopedSpinGuardTryCreateScopedSpinGuard (uint64_t timeout_ns)
 If this Annotation guards concurrent access using ScopedSpinGuard, tries to obtain the spin guard and returns the result.
 

Additional Inherited Members

- Public Types inherited from crashpad::Annotation
enum class  Type : uint16_t
 The type of data stored in the annotation. More...
 
enum class  ConcurrentAccessGuardMode : bool
 Mode used to guard concurrent reads from writes. More...
 
using ValueSizeType = uint32_t
 The type used for SetSize().
 
- Static Public Member Functions inherited from crashpad::Annotation
static constexpr Type UserDefinedType (uint16_t value)
 Creates a user-defined Annotation::Type.
 
- Static Public Attributes inherited from crashpad::Annotation
static constexpr size_t kNameMaxLength = 256
 The maximum length of an annotation’s name, in bytes. Matches the behavior of Breakpad's SimpleStringDictionary.
 
static constexpr size_t kValueMaxSize = 5 * 4096
 The maximum size of an annotation’s value, in bytes.
 
- Protected Member Functions inherited from crashpad::Annotation
constexpr Annotation (Type type, const char name[], void *value_ptr, ConcurrentAccessGuardMode concurrent_access_guard_mode)
 Constructs a new annotation.
 
std::atomic< Annotation * > & link_node ()
 
AnnotationGetLinkNode (std::memory_order order=std::memory_order_seq_cst)
 
const AnnotationGetLinkNode (std::memory_order order=std::memory_order_seq_cst) const
 

Detailed Description

template<RingBufferAnnotationCapacity Capacity = internal::kDefaultRingBufferAnnotationCapacity>
class crashpad::RingBufferAnnotation< Capacity >

An Annotation which wraps a LengthDelimitedRingBuffer of up to Capacity bytes in length.

Supports writing variable-length data via Push(). When the ring buffer is full, it will drop old data items in FIFO order until enough space is available for the write.

Supports guarding concurrent reads from writes via ScopedSpinGuard, so writing to this object is thread-safe.

Clients which read this Annotation's memory can optionally invoke TryCreateScopedSpinGuard() on this object to ensure any pending write finishes before the memory is read.

Each item in this ring buffer is delimited by its length encoded in little-endian Base 128 varint encoding.

RingBufferAnnotation uses varint-encoded delimiters to enable zero-copy deserialization of the ringbuffer's contents when storing protobufs inside the ringbuffer, e.g. via google::protobuf::util::ParseDelimitedFromZeroCopyStream() or similar.

See also
https://github.com/protocolbuffers/protobuf/blob/3202b9da88ceb75b65bbabaf4033c95e872f828d/src/google/protobuf/util/delimited_message_util.h#L85
https://github.com/protocolbuffers/protobuf/blob/8bd49dea5e167a389d94b71d24c981d8f9fa0c99/src/google/protobuf/io/zero_copy_stream_impl_lite.h#L68
https://github.com/protocolbuffers/protobuf/blob/8bd49dea5e167a389d94b71d24c981d8f9fa0c99/src/google/protobuf/io/coded_stream.h#L171

To deserialize the items stored in this annotation, use LengthDelimitedRingBufferReader.

Constructor & Destructor Documentation

◆ RingBufferAnnotation()

template<RingBufferAnnotationCapacity Capacity = internal::kDefaultRingBufferAnnotationCapacity>
crashpad::RingBufferAnnotation< Capacity >::RingBufferAnnotation ( Annotation::Type type,
const char name[] )
inlineconstexpr

Constructs a RingBufferAnnotation.

Parameters
[in]typeA unique identifier for the type of data in the ring buffer.
[in]nameThe name of the annotation.

Member Function Documentation

◆ Push()

template<RingBufferAnnotationCapacity Capacity = internal::kDefaultRingBufferAnnotationCapacity>
bool crashpad::RingBufferAnnotation< Capacity >::Push ( const void *const buffer,
RingBufferAnnotationCapacity buffer_length )
inline

Pushes data onto this annotation's ring buffer.

If the ring buffer does not have enough space to store buffer_length bytes of data, old data items are dropped in FIFO order until enough space is available to store the new data.


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