You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
qemu/util
Daniel P. Berrangé 012842c075 log: make '-msg timestamp=on' apply to all qemu_log usage
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>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
Message-id: 20250721185452.3016488-1-berrange@redhat.com
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
3 weeks ago
..
aio-posix.c aio-posix: Adjust polling time also for new handlers 5 months ago
aio-posix.h aio-posix: Separate AioPolledEvent per AioHandler 5 months ago
aio-wait.c aio-wait: avoid AioContext lock in aio_wait_bh_oneshot() 2 years ago
aio-win32.c include: Move QemuLockCnt APIs to their own header 10 months ago
aiocb.c block: move AioContext, QEMUTimer, main-loop to libqemuutil 9 years ago
async.c include/exec: Split out icount.h 4 months ago
atomic64.c osdep: Move memalign-related functions to their own header 3 years ago
base64.c nomaintainer: Fix Lesser GPL version number 5 years ago
bitmap.c migration: Use non-atomic ops for clear log bitmap 3 years ago
bitops.c replace TABs with spaces 2 years ago
block-helpers.c block: Adjust check_block_size() signature 10 months ago
block-helpers.h block: Adjust check_block_size() signature 10 months ago
buffer.c nomaintainer: Fix Lesser GPL version number 5 years ago
bufferiszero.c util/bufferiszero: Split out host include files 1 year ago
cacheflush.c util/cacheflush.c: Update cache flushing mechanism for Emscripten 3 months ago
chardev_open.c util/char_dev: Add open_cdev() 2 years ago
compatfd.c util: replace pipe()+cloexec with g_unix_open_pipe() 3 years ago
coroutine-sigaltstack.c osdep: set _FORTIFY_SOURCE=2 when optimization is enabled 2 years ago
coroutine-ucontext.c coroutine-ucontext: Save fake stack for pooled coroutine 2 years ago
coroutine-wasm.c util: Add coroutine backend for emscripten 3 months ago
coroutine-windows.c build: move coroutine backend selection to meson 2 years ago
cpuinfo-aarch64.c util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD 1 year ago
cpuinfo-i386.c target/i386/hvf: fix handling of XSAVE-related CPUID bits 9 months ago
cpuinfo-loongarch.c util/loongarch64: Detect LASX vector support 1 year ago
cpuinfo-ppc.c util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD 1 year ago
cpuinfo-riscv.c util/cpuinfo-riscv: Detect Zbs 7 months ago
crc-ccitt.c util: Add CRC16 (CCITT) calculation routines 5 years ago
crc32c.c igb: Implement Rx SCTP CSO 2 years ago
cutils.c util/cutils: Remove unused qemu_get_exec_dir 11 months ago
dbus.c util: add dbus helper unit 6 years ago
defer-call.c util/defer-call: move defer_call() to util/ 2 years ago
drm.c util/drm: make portable by avoiding struct dirent d_type 5 years ago
envlist.c envlist: Remove unused envlist_parse 11 months ago
error-report.c Remove glib compatibility code that is not required anymore 1 year ago
error.c util/error: make func optional 2 months ago
event.c qemu-thread: Use futex for QemuEvent on Windows 2 months ago
event_notifier-posix.c Replace qemu_pipe() with g_unix_open_pipe() 3 years ago
event_notifier-win32.c Remove qemu-common.h include from most units 3 years ago
fdmon-epoll.c include: Move QemuLockCnt APIs to their own header 10 months ago
fdmon-io_uring.c remove unnecessary casts from uintptr_t 2 years ago
fdmon-poll.c aio: remove aio_disable_external() API 2 years ago
fifo8.c fifo8: introduce fifo8_peek() function 11 months ago
filemonitor-inotify.c util/filemonitor-inotify.c: spelling fix: kenel 2 years ago
filemonitor-stub.c nomaintainer: Fix Lesser GPL version number 5 years ago
getauxval.c util/cpuinfo: Make use of elf_aux_info(3) on OpenBSD 1 year ago
guest-random.c util/guest-random: Clean up global variable shadowing 2 years ago
hbitmap.c qapi/crypto: Rename QCryptoHashAlgorithm to *Algo, and drop prefix 11 months ago
hexdump.c hw/vmapple/aes: Introduce aes engine 5 months ago
host-utils.c host-utils: Implemented signed 256-by-128 division 3 years ago
id.c net: Use id_generate() in the network subsystem, too 4 years ago
int128.c include/qemu/int128: Use Int128 structure for TCI 3 years ago
interval-tree.c util/interval-tree: Check root for null in interval_tree_iter_first 2 years ago
iov.c util/iov: Do not assert offset is in iov 5 months ago
iova-tree.c vhost-iova-tree, svq: Implement GPA->IOVA & partial IOVA->HVA trees 6 months ago
keyval.c qapi: Move include/qapi/qmp/ to include/qobject/ 6 months ago
lockcnt.c qemu-thread: Use futex if available for QemuLockCnt 2 months ago
log.c log: make '-msg timestamp=on' apply to all qemu_log usage 3 weeks ago
main-loop.c qom: Have class_init() take a const data argument 4 months ago
memalign.c osdep: Move memalign-related functions to their own header 3 years ago
memfd.c physmem: fd-based shared memory 6 months ago
meson.build qemu-thread: Use futex for QemuEvent on Windows 2 months ago
mmap-alloc.c util/mmap-alloc: qemu_fd_getfs() 2 years ago
module.c overall: Remove unnecessary g_strdup_printf() calls 6 months ago
notify.c notify: pass error to notifier with return 1 year ago
nvdimm-utils.c Clean up includes 5 years ago
osdep.c migration: Add direct-io parameter 1 year ago
oslib-posix.c util: exclude mmap-alloc.c from compilation target on Emscripten 3 months ago
oslib-win32.c backends/hostmem-shm: factor out allocation of "anonymous shared memory with an fd" 6 months ago
path.c util/path: Do not cache all filenames at startup 6 years ago
qdist.c util: spelling fixes 2 years ago
qemu-co-shared-resource.c util/co-shared-resource: Remove unused co_try_get_from_shres 11 months ago
qemu-co-timeout.c util: add qemu-co-timeout 3 years ago
qemu-config.c qapi: Move include/qapi/qmp/ to include/qobject/ 6 months ago
qemu-coroutine-io.c aio: remove aio_disable_external() API 2 years ago
qemu-coroutine-lock.c atomics: eliminate mb_read/mb_set 2 years ago
qemu-coroutine-sleep.c coroutine: Clean up superfluous inclusion of qemu/coroutine.h 3 years ago
qemu-coroutine.c util/coroutine: fix -Werror=maybe-uninitialized false-positive 10 months ago
qemu-option.c qapi: Move include/qapi/qmp/ to include/qobject/ 6 months ago
qemu-print.c monitor: Use getter/setter functions for cur_mon 5 years ago
qemu-progress.c include: move progress API to qemu-progress.h 3 years ago
qemu-sockets.c util/qemu-sockets: Introduce inet socket options controlling TCP keep-alive 3 months ago
qemu-thread-common.h Clean up includes 7 years ago
qemu-thread-posix.c qemu-thread: Use futex for QemuEvent on Windows 2 months ago
qemu-thread-win32.c qemu-thread: Use futex for QemuEvent on Windows 2 months ago
qemu-timer-common.c semihosting: Implement SYS_ELAPSED and SYS_TICKFREQ 5 years ago
qemu-timer.c include/exec: Split out icount.h 4 months ago
qht.c cleanup: Drop pointless return at end of function 4 months ago
qsp.c system/cpus: rename qemu_mutex_lock_iothread() to bql_lock() 2 years ago
qtree.c tcg: use QTree instead of GTree 2 years ago
range.c util/range.c: spelling fix: inbetween 2 years ago
rcu.c util/rcu.c: replace FSF postal address with licenses URL 2 months ago
readline.c util/readline: Add C-u shortcut 1 year ago
reserved-region.c util/reserved-region: Add new ReservedRegion helpers 2 years ago
s390x_pci_mmio.c util: Add functions for s390x mmio read/write 3 months ago
selfmap.c util/selfmap: Use dev_t and ino_t in MapInfo 2 years ago
stats64.c stat64: Add stat64_set() operation 2 years ago
sys_membarrier.c sys_membarrier: fix up include directives 7 years ago
systemd.c systemd: Also clear LISTEN_FDNAMES during systemd socket activation 2 years ago
thread-context.c qom: Make InterfaceInfo[] uses const 4 months ago
thread-pool.c thread-pool: Implement generic (non-AIO) pool support 5 months ago
throttle.c throttle: use THROTTLE_MAX/ARRAY_SIZE for hard code 2 years ago
timed-average.c license: Simplify GPL-2.0-or-later license descriptions 11 months ago
trace-events thread-pool: Rename AIO pool functions to *_aio() and data types to *Aio 5 months ago
trace.h trace: switch position of headers to what Meson requires 5 years ago
transactions.c transactions: Invoke clean() after everything else 4 years ago
unicode.c json: Reject invalid UTF-8 sequences 7 years ago
userfaultfd.c util/userfaultfd: Remove unused uffd_poll_events 10 months ago
uuid.c util/uuid: Add UUID_STR_LEN definition 2 years ago
vfio-helpers.c include/system: Move exec/memory.h to system/memory.h 4 months ago
vhost-user-server.c vhost-user-server: do not set memory fd non-blocking 1 year ago
yank.c qapi: Fix dangling references to docs/devel/qapi-code-gen.txt 2 years ago