From: Stefan Hajnoczi <stefanha@redhat.com>
To: "Daniel P. Berrangé" <berrange@redhat.com>
Cc: qemu-devel@nongnu.org, Mads Ynddal <mads@ynddal.dk>
Subject: Re: [PATCH] log: make '-msg timestamp=on' apply to all qemu_log usage
Date: Thu, 24 Jul 2025 10:12:43 -0400 [thread overview]
Message-ID: <20250724141243.GA95708@fedora> (raw)
In-Reply-To: <20250721185452.3016488-1-berrange@redhat.com>
[-- Attachment #1: Type: text/plain, Size: 4485 bytes --]
On Mon, Jul 21, 2025 at 07:54:52PM +0100, Daniel P. Berrangé wrote:
> Currently the tracing 'log' back emits special code to add timestamps
> to trace points sent via qemu_log(). This current impl is a bad design
> for a number of reasons.
>
> * It changes the QEMU headers, such that 'error-report.h' content
> is visible to all files using tracing, but only when the 'log'
> backend is enabled. This has led to build failure bugs as devs
> rarely test without the (default) 'log' backend enabled, and
> CI can't cover every scenario for every trace backend.
>
> * It bloats the trace points definitions which are inlined into
> every probe location due to repeated inlining of timestamp
> formatting code, adding MBs of overhead to QEMU.
>
> * The tracing subsystem should not be treated any differently
> from other users of qemu_log. They all would benefit from
> having timestamps present.
>
> * The timestamp emitted with the tracepoints is in a needlessly
> different format to that used by error_report() in response
> to '-msg timestamp=on'.
>
> This fixes all these issues simply by moving timestamp formatting
> into qemu_log, using the same approach as for error_report.
>
> The code before:
>
> static inline void _nocheck__trace_qcrypto_tls_creds_get_path(void * creds, const char * filename, const char * path)
> {
> if (trace_event_get_state(TRACE_QCRYPTO_TLS_CREDS_GET_PATH) && qemu_loglevel_mask(LOG_TRACE)) {
> if (message_with_timestamp) {
> struct timeval _now;
> gettimeofday(&_now, NULL);
> qemu_log("%d@%zu.%06zu:qcrypto_tls_creds_get_path " "TLS creds path creds=%p filename=%s path=%s" "\n",
> qemu_get_thread_id(),
> (size_t)_now.tv_sec, (size_t)_now.tv_usec
> , creds, filename, path);
> } else {
> qemu_log("qcrypto_tls_creds_get_path " "TLS creds path creds=%p filename=%s path=%s" "\n", creds, filename, path);
> }
> }
> }
>
> and after:
>
> static inline void _nocheck__trace_qcrypto_tls_creds_get_path(void * creds, const char * filename, const char * path)
> {
> if (trace_event_get_state(TRACE_QCRYPTO_TLS_CREDS_GET_PATH) && qemu_loglevel_mask(LOG_TRACE)) {
> qemu_log("qcrypto_tls_creds_get_path " "TLS creds path creds=%p filename=%s path=%s" "\n", creds, filename, path);
> }
> }
>
> The log and error messages before:
>
> $ qemu-system-x86_64 -trace qcrypto* -object tls-creds-x509,id=tls0,dir=$HOME/tls -msg timestamp=on
> 2986097@1753122905.917608:qcrypto_tls_creds_x509_load TLS creds x509 load creds=0x55d925bd9490 dir=/var/home/berrange/tls
> 2986097@1753122905.917621:qcrypto_tls_creds_get_path TLS creds path creds=0x55d925bd9490 filename=ca-cert.pem path=<none>
> 2025-07-21T18:35:05.917626Z qemu-system-x86_64: Unable to access credentials /var/home/berrange/tls/ca-cert.pem: No such file or directory
>
> and after:
>
> $ qemu-system-x86_64 -trace qcrypto* -object tls-creds-x509,id=tls0,dir=$HOME/tls -msg timestamp=on
> 2025-07-21T18:43:28.089797Z qcrypto_tls_creds_x509_load TLS creds x509 load creds=0x55bf5bf12380 dir=/var/home/berrange/tls
> 2025-07-21T18:43:28.089815Z qcrypto_tls_creds_get_path TLS creds path creds=0x55bf5bf12380 filename=ca-cert.pem path=<none>
> 2025-07-21T18:43:28.089819Z qemu-system-x86_64: Unable to access credentials /var/home/berrange/tls/ca-cert.pem: No such file or directory
>
> The binary size before:
>
> $ ls -alh qemu-system-x86_64
> -rwxr-xr-x. 1 berrange berrange 87M Jul 21 19:39 qemu-system-x86_64
> $ strip qemu-system-x86_64
> $ ls -alh qemu-system-x86_64
> -rwxr-xr-x. 1 berrange berrange 30M Jul 21 19:39 qemu-system-x86_64
>
> and after:
>
> $ ls -alh qemu-system-x86_64
> -rwxr-xr-x. 1 berrange berrange 85M Jul 21 19:41 qemu-system-x86_64
> $ strip qemu-system-x86_64
> $ ls -alh qemu-system-x86_64
> -rwxr-xr-x. 1 berrange berrange 29M Jul 21 19:41 qemu-system-x86_64
>
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
> scripts/tracetool/backend/log.py | 14 +-------------
> util/log.c | 20 +++++++++++++++++++-
> 2 files changed, 20 insertions(+), 14 deletions(-)
Thanks, applied to my tracing tree:
https://gitlab.com/stefanha/qemu/commits/tracing
Stefan
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]
prev parent reply other threads:[~2025-07-24 14:13 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-07-21 18:54 [PATCH] log: make '-msg timestamp=on' apply to all qemu_log usage Daniel P. Berrangé
2025-07-21 20:22 ` Stefan Hajnoczi
2025-07-22 15:21 ` Vladimir Sementsov-Ogievskiy
2025-07-22 8:27 ` Markus Armbruster
2025-07-22 15:38 ` Vladimir Sementsov-Ogievskiy
2025-07-24 14:12 ` Stefan Hajnoczi [this message]
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=20250724141243.GA95708@fedora \
--to=stefanha@redhat.com \
--cc=berrange@redhat.com \
--cc=mads@ynddal.dk \
--cc=qemu-devel@nongnu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).