Daniel P. BerrangĂ© <[email protected]> writes:

> Introduce a circular buffer concept to the data recorder that can be
> used to capture text based messages from subsystems. Support for
> multiple distinct "buckets" is provided, one per type of information
> to be captured. This ensures that data from subsystems which is
> captured at a high rate, does not prematurely wrap the buffer and
> overwrite (still relevant) messages from a subsystem that records
> at a low rate.
>
> Each bucket has a max capacity of 64 KB by default (though it is
> configurable), but grows on demand. IOW the bucket capacity puts
> an upper limit on memory usage, actual usage will be zero until
> data is recorded. Every captured message will be prefixed by a
> timestamp and suffixed by a newline, if one is not already present
> at the end of the message.
>
> While writing into the bufers is synchronized with mutex locks,
> when dumping from a signal handler the buffers are accessed
> without any locking to avoid deadlocks. Atomic loads/stores are
> used in certain places so the signal handler can dump data with
> acceptable accuracy even when racing with other threads still
> writing new messages.
>
> When the circular buffer wraps, old messages will be overwritten
> without attention to message boundaries. IOW, when later dumping
> the data recorder, the first printed message is likely to have
> its leading text and timestamp missing. This is considered an
> acceptable tradeoff to avoid tracking message boundaries which
> greatly adds complexity and is hard todo safely without locks
> when dumping.
>
> Signed-off-by: Daniel P. BerrangĂ© <[email protected]>

[...]

> diff --git a/qapi/qom.json b/qapi/qom.json
> index 1c9031fba9a..f1c37bce6c2 100644
> --- a/qapi/qom.json
> +++ b/qapi/qom.json
> @@ -8,6 +8,7 @@
>  { 'include': 'block-core.json' }
>  { 'include': 'common.json' }
>  { 'include': 'crypto.json' }
> +{ 'include': 'tldr.json' }
>  
>  ##
>  # ***********************
> @@ -1239,11 +1240,13 @@
>  #
>  # @crash-target: fully qualified path to perserve data recorder
>  #                contents on QEMU crash

Blank line, please.

> +# @messages: custom configuration for message buckets
>  #
>  # Since: 11.2.0
>  ##
>  { 'struct': 'QTLDRConfigProperties',
> -  'data': { '*crash-target': 'str' }
> +  'data': { '*crash-target': 'str',
> +            '*messages': ['QTLDRMsgBucketConfig'] }
>  }
>  
>  ##
> diff --git a/qapi/tldr.json b/qapi/tldr.json
> index 8e2b7cda324..987d36b91f8 100644
> --- a/qapi/tldr.json
> +++ b/qapi/tldr.json
> @@ -26,3 +26,37 @@
>  #     <- { "return": {} }
>  ##
>  { 'command': 'tldr-dump', 'data': 'QTLDRDumpOptions' }
> +
> +##
> +# @QTLDRMsgBucketType:
> +#     List of message bucket types

This isn't a list, it's an enum.  Simply scratch "List of".

> +#
> +# @error: error messages and warnings
> +# @command: QMP commands which change state and error responses
> +# @event: QMP events reflecting state changes
> +# @log: log messages from any subsystems

Blank lines between member descriptions, please.

> +#
> +# Since: 11.2.0

Make this 11.2 to match overwhelming existing practice.  Same elsewhere.

> +##
> +{ 'enum': 'QTLDRMsgBucketType',
> +  'data': ['error', 'command', 'event', 'log' ] }
> +
> +
> +##
> +# @QTLDRMsgBucketConfig:
> +#     Configuration for message buckets
> +#
> +# @type: the message bucket to enable

Blank line, please.

> +# @capacity: override the default bucket size, in bytes (64kb)

Let's use KiB.

> +#
> +# Each bucket allocates memory on demand, so capacity merely
> +# puts an upper limit on the memory usage in a bucket.  The
> +# capacity must be larger than the per-message size limit,
> +# which is 2048 bytes.
> +#
> +# Since: 11.2.0
> +##
> +{ 'struct': 'QTLDRMsgBucketConfig',
> +  'data': { 'type': 'QTLDRMsgBucketType',
> +            '*capacity': 'size' }
> +}
> diff --git a/qemu-options.hx b/qemu-options.hx
> index 5f96257cef0..da9d1e2b7bd 100644
> --- a/qemu-options.hx
> +++ b/qemu-options.hx
> @@ -6685,6 +6685,8 @@ SRST
>  
>  
>      ``-object tldr-config,id=id,crash-target=path``
> +        \
> +    ``-object 
> "{'qom-type':'tldr-config','id':'tldr','crash-target':'foo','messages':[{'type':'BUCKET','capacity':BYTES}]}"``
>          Creating the ``tldr-config`` object enables the thrifty live data
>          recorder, which continuously captures important information about
>          the operation of the QEMU process. When a SIGSEGV, SIGBUS,
> @@ -6695,6 +6697,12 @@ SRST
>          The ``tldr-dump`` QMP command can also be used at any time to
>          save the captured data to an arbitrary file.
>  
> +        The data recorder will capture upto 64kb of data by default in
> +        each bucket, but when using the JSON syntax for ``-object``, this
> +        can be tailored with the ``messages`` parameter. ``BUCKET`` takes
> +        one of ``error``, ``command``, ``event``, or ``log`` and the
> +        capacity value is in bytes.

JSON only because -object still uses QemuOpts for KEY=VALUE,...
arguments.  Arrays can be done with QemuOpts, but it's not worth the
bother here.

> +
>          The ``tldr-config`` object can be added at initial startup
>          or via QMP at runtime. Once created, however, it is not
>          permitted to disable it.

[...]


Reply via email to