From: Fabiano Rosas <farosas@suse.de>
To: "Daniel P. Berrangé" <berrange@redhat.com>, qemu-devel@nongnu.org
Cc: "Marc-André Lureau" <marcandre.lureau@redhat.com>,
"Michael Roth" <michael.roth@amd.com>,
"Philippe Mathieu-Daudé" <philmd@oss.qualcomm.com>,
"Richard Henderson" <richard.henderson@linaro.org>,
"Dr. David Alan Gilbert" <dave@treblig.org>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Markus Armbruster" <armbru@redhat.com>,
"Pierrick Bouvier" <pierrick.bouvier@oss.qualcomm.com>,
"Eric Blake" <eblake@redhat.com>,
"Daniel P. Berrangé" <berrange@redhat.com>,
"Laurent Vivier" <lvivier@redhat.com>
Subject: Re: [PATCH 14/21] util: introduce capture of textual messages in data recorder
Date: Tue, 17 Nov 2026 17:29:19 -0300 [thread overview]
Message-ID: <87v75vqk0w.fsf@suse.de> (raw)
In-Reply-To: <20261015112044.1999748-15-berrange@redhat.com>
Daniel P. Berrangé <berrange@redhat.com> 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é <berrange@redhat.com>
> ---
> include/qemu/tldr.h | 52 +++++++
> qapi/qom.json | 5 +-
> qapi/tldr.json | 34 +++++
> qemu-options.hx | 8 +
> tests/unit/test-util-tldr.c | 272 ++++++++++++++++++++++++++++++++++
> util/tldr-internal.h | 31 ++++
> util/tldr.c | 282 +++++++++++++++++++++++++++++++++++-
> 7 files changed, 682 insertions(+), 2 deletions(-)
>
> diff --git a/include/qemu/tldr.h b/include/qemu/tldr.h
> index 67152b136b3..5766acecb64 100644
> --- a/include/qemu/tldr.h
> +++ b/include/qemu/tldr.h
> @@ -9,6 +9,58 @@
> #ifndef QEMU_TLDR_H__
> #define QEMU_TLDR_H__
>
> +#include "qapi/qapi-types-tldr.h"
> +
> +extern unsigned int qtldr_msg_enabled_mask;
> +
> +/**
> + * qtldr_msg_enabled:
> + * @bucket: bucket to check status for
> + *
> + * Returns: true if @bucket is enabled for recording
> + */
> +#define qtldr_msg_enabled(bucket) \
> + (qtldr_msg_enabled_mask & (1 << bucket))
> +
> +/**
> + * qtldr_msg_record:
> + * @bucket: bucket to record into
> + * @msg: the message text to record
> + *
> + * Records @msg into @bucket, potentially overwriting
> + * old messages if the capacity is at its maximum
> + */
> +void qtldr_msg_record(QTLDRMsgBucketType bucket,
> + const char *msg);
> +
> +/**
> + * qtldr_msg_record_printf:
> + * @bucket: bucket to record into
> + * @fmt: the message format string to record
> + * @...: the arguments for @fmt
> + *
> + * Formats @fmt as a printf string and records the
> + * result into @bucket, potentially overwriting
> + * old messages if the capacity is at its maximum
> + */
> +void qtldr_msg_record_printf(QTLDRMsgBucketType bucket,
> + const char *fmt, ...)
> + G_GNUC_PRINTF(2, 3);
> +
> +/**
> + * qtldr_msg_record_vprintf:
> + * @bucket: bucket to record into
> + * @fmt: the message format string to record
> + * @ap: the arguments for @fmt
> + *
> + * Formats @fmt as a printf string and records the
> + * result into @bucket, potentially overwriting
> + * old messages if the capacity is at its maximum
> + */
> +void qtldr_msg_record_vprintf(QTLDRMsgBucketType bucket,
> + const char *fmt, va_list ap)
> + G_GNUC_PRINTF(2, 0);
> +
> /**
> * qtldr_crash_dump_signal:
> * @si: signal information
> 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
> +# @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
> +#
> +# @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
Hm, all of these are generic and shared between subsystems, I'm not sure
how the "high rate vs. low rate" property is to be kept if some code
just runs fast over all of these classes of messages.
> +#
> +# Since: 11.2.0
> +##
> +{ 'enum': 'QTLDRMsgBucketType',
> + 'data': ['error', 'command', 'event', 'log' ] }
> +
> +
> +##
> +# @QTLDRMsgBucketConfig:
> +# Configuration for message buckets
> +#
> +# @type: the message bucket to enable
> +# @capacity: override the default bucket size, in bytes (64kb)
kB
> +#
> +# 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}]}"``
So it's not possible to add new message buckets later on because the
singleton tldr-config is already created?
> 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
up to 64 KiB
> + 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.
> +
> 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.
next prev parent reply other threads:[~2026-11-17 20:30 UTC|newest]
Thread overview: 45+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-15 11:20 [PATCH 00/21] system: introduce a live data recorder facility Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 01/21] osdep: add 'ignore_value(x)' macro Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 02/21] system: move SIGBUS signal handling to signal.c Daniel P. Berrangé
2026-10-15 12:15 ` marcandre.lureau
2026-10-15 11:20 ` [PATCH 03/21] system: rename qemu_init_sigbus to qemu_init_crash_signals Daniel P. Berrangé
2026-10-15 12:15 ` marcandre.lureau
2026-10-15 11:20 ` [PATCH 04/21] system: run SIGBUS handler on alternate signal stack Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 05/21] util: expand alternate signal stack to all threads Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 06/21] osdep: provide dummy siginfo_t definition Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 07/21] util: introduce 'tldr', a system data recorder for crash handling Daniel P. Berrangé
2026-10-29 8:29 ` Markus Armbruster
2026-10-29 15:35 ` Daniel P. Berrangé
2026-10-30 8:59 ` Markus Armbruster
2026-11-17 19:52 ` Fabiano Rosas
2026-10-15 11:20 ` [PATCH 08/21] qapi: add 'tldr-dump' command for on-demand data recorder output Daniel P. Berrangé
2026-10-29 8:35 ` Markus Armbruster
2026-10-29 15:37 ` Daniel P. Berrangé
2026-11-17 19:55 ` Fabiano Rosas
2026-10-15 11:20 ` [PATCH 09/21] system: trigger TLDR crash dump on unhandled SIGBUS Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 10/21] system: simplify signal handler logic Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 11/21] main: allow SIGBUS in the main loop Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 12/21] system: enable SIGBUS handling on non-Linux platforms Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 13/21] system: enable crash dumps on SIGSEGV, SIGILL, SIGFPE and SIGABRT Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 14/21] util: introduce capture of textual messages in data recorder Daniel P. Berrangé
2026-10-29 8:49 ` Markus Armbruster
2026-11-17 20:29 ` Fabiano Rosas [this message]
2026-10-15 11:20 ` [PATCH 15/21] util: capture warnings and errors in the " Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 16/21] monitor: remove obsolete/redundant exports Daniel P. Berrangé
2026-10-29 8:51 ` Markus Armbruster
2026-10-15 11:20 ` [PATCH 17/21] monitor: capture monitor commands and events in data recorder Daniel P. Berrangé
2026-10-15 15:57 ` Dr. David Alan Gilbert
2026-10-15 16:11 ` Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 18/21] log: enable directing log messages to " Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 19/21] tests/qtest: add API to declare an expected crash signal Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 20/21] qtest: add 'crash' command to generate 'authentic' process crashes Daniel P. Berrangé
2026-10-15 11:20 ` [PATCH 21/21] tests/qtest: add test to validate data recorder on crashes Daniel P. Berrangé
2026-10-15 12:15 ` [PATCH 00/21] system: introduce a live data recorder facility marcandre.lureau
2026-10-15 12:32 ` Daniel P. Berrangé
2026-10-16 7:20 ` Marc-André Lureau
2026-10-29 17:32 ` Daniel P. Berrangé
2026-10-29 18:15 ` Marc-André Lureau
2026-10-29 18:28 ` Daniel P. Berrangé
2026-10-30 8:47 ` Marc-André Lureau
2026-10-15 17:34 ` Pierrick Bouvier
2026-10-29 17:39 ` Daniel P. Berrangé
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87v75vqk0w.fsf@suse.de \
--to=farosas@suse.de \
--cc=armbru@redhat.com \
--cc=berrange@redhat.com \
--cc=dave@treblig.org \
--cc=eblake@redhat.com \
--cc=lvivier@redhat.com \
--cc=marcandre.lureau@redhat.com \
--cc=michael.roth@amd.com \
--cc=pbonzini@redhat.com \
--cc=philmd@oss.qualcomm.com \
--cc=pierrick.bouvier@oss.qualcomm.com \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.