Skip to contentSkip to conversation

utils/log: add qemu_log_timestamp() to encapsulate timestamp logging

PATCH In review Tanish Desai 3 participants 6 messages Jun 9, 2025 – Jun 12, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 utils/log: add qemu_log_timestamp() to encapsulate timestamp logging

Moved the logic for timestamped logging (~6 lines) from a_nocheck__trace_foo(header) into a new qemu_log_timestamp() function in util/log.c. This avoids code duplication across binaries and enables reuse as a standalone utility. Encapsulation helps reduce build size significantly, particularly when many trace points are present. On Ubuntu 22 with
./configure --target-list=aarch64-softmmu --enable-kvm --enable-trace-backends=log,
this change reduced the build directory size from ~1435.27 MB to ~1412 MB (~23 MB saved).
Notable reductions include:
trace/: ~2.6 MB
libqemuutil.a.p: ~3 MB
A detailed report of size changes (in bytes) for relevant folders and subfolders will follow in a trailing mail.

---
 include/qemu/log-for-trace.h     |  3 +++
 scripts/tracetool/backend/log.py | 13 +------------
 util/log.c                       | 18 ++++++++++++++++++
 3 files changed, 22 insertions(+), 12 deletions(-)
include/qemu/log-for-trace.h +3 -0
index d47c9cd446..680f30a8a9 100644
@@ -32,4 +32,7 @@ static inline bool qemu_loglevel_mask(int mask)
 /* main logging function */
 void G_GNUC_PRINTF(1, 2) qemu_log(const char *fmt, ...);
 
+/* main logging function with timestamp */
+void G_GNUC_PRINTF(1, 2) qemu_log_timestamp(const char *fmt, ...);
+
 #endif
scripts/tracetool/backend/log.py +1 -12
index de27b7e62e..3358afb43a 100644
@@ -38,20 +38,9 @@ def generate_h(event, group):
         cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 
     out('    if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
-        '        if (message_with_timestamp) {',
-        '            struct timeval _now;',
-        '            gettimeofday(&_now, NULL);',
         '#line %(event_lineno)d "%(event_filename)s"',
-        '            qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s "\\n",',
-        '                     qemu_get_thread_id(),',
-        '                     (size_t)_now.tv_sec, (size_t)_now.tv_usec',
-        '                     %(argnames)s);',
+        '            qemu_log_timestamp("%(name)s " %(fmt)s "\\n"%(argnames)s);',
         '#line %(out_next_lineno)d "%(out_filename)s"',
-        '        } else {',
-        '#line %(event_lineno)d "%(event_filename)s"',
-        '            qemu_log("%(name)s " %(fmt)s "\\n"%(argnames)s);',
-        '#line %(out_next_lineno)d "%(out_filename)s"',
-        '        }',
         '    }',
         cond=cond,
         event_lineno=event.lineno,
util/log.c +18 -0
index b87d399e4c..996530fe7e 100644
@@ -143,6 +143,24 @@ void qemu_log_unlock(FILE *logfile)
     }
 }
 
+
+void qemu_log_timestamp(const char *fmt, ...)
+{
+    FILE *f = qemu_log_trylock();
+    if (f) {
+        va_list ap;
+        if(message_with_timestamp){
+            struct timeval _now;
+            gettimeofday(&_now, NULL);
+            fprintf(f,"%d@%zu.%06zu:",qemu_get_thread_id(),(size_t)_now.tv_sec, (size_t)_now.tv_usec);
+        }
+        va_start(ap, fmt);
+        vfprintf(f, fmt, ap);
+        va_end(ap);
+    }
+    qemu_log_unlock(f);
+}
+
 void qemu_log(const char *fmt, ...)
 {
     FILE *f = qemu_log_trylock();
Signature · 1 line
2.34.1
#1 lore raw

Two files are attached to show the folder-wise size (in bytes) before and after the change. Each file lists the folder names along with their corresponding sizes.

Quoted 95 lines · Tanish Desai

Moved the logic for timestamped logging (~6 lines) from a_nocheck__trace_foo(header) into a new qemu_log_timestamp() function in util/log.c. This avoids code duplication across binaries and enables reuse as a standalone utility.
Encapsulation helps reduce build size significantly, particularly when many trace points are present. On Ubuntu 22 with
./configure --target-list=aarch64-softmmu --enable-kvm --enable-trace-backends=log,
this change reduced the build directory size from ~1435.27 MB to ~1412 MB (~23 MB saved).
Notable reductions include:
trace/: ~2.6 MB
libqemuutil.a.p: ~3 MB
A detailed report of size changes (in bytes) for relevant folders and subfolders will follow in a trailing mail.

---
 include/qemu/log-for-trace.h     |  3 +++
 scripts/tracetool/backend/log.py | 13 +------------
 util/log.c                       | 18 ++++++++++++++++++
 3 files changed, 22 insertions(+), 12 deletions(-)
include/qemu/log-for-trace.h +3 -0
index d47c9cd446..680f30a8a9 100644
@@ -32,4 +32,7 @@ static inline bool qemu_loglevel_mask(int mask)
 /* main logging function */
 void G_GNUC_PRINTF(1, 2) qemu_log(const char *fmt, ...);
 
+/* main logging function with timestamp */
+void G_GNUC_PRINTF(1, 2) qemu_log_timestamp(const char *fmt, ...);
+
 #endif
scripts/tracetool/backend/log.py +1 -12
index de27b7e62e..3358afb43a 100644
@@ -38,20 +38,9 @@ def generate_h(event, group):
         cond = "trace_event_get_state(%s)" % ("TRACE_" +
 event.name.upper())
 
     out('    if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
-        '        if (message_with_timestamp) {',
-        '            struct timeval _now;',
-        '            gettimeofday(&_now, NULL);',
         '#line %(event_lineno)d "%(event_filename)s"',
-        '            qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s
 "\\n",',
-        '                     qemu_get_thread_id(),',
-        '                     (size_t)_now.tv_sec, (size_t)_now.tv_usec',
-        '                     %(argnames)s);',
+        '            qemu_log_timestamp("%(name)s " %(fmt)s
 "\\n"%(argnames)s);',
         '#line %(out_next_lineno)d "%(out_filename)s"',
-        '        } else {',
-        '#line %(event_lineno)d "%(event_filename)s"',
-        '            qemu_log("%(name)s " %(fmt)s "\\n"%(argnames)s);',
-        '#line %(out_next_lineno)d "%(out_filename)s"',
-        '        }',
         '    }',
         cond=cond,
         event_lineno=event.lineno,
util/log.c +18 -0
index b87d399e4c..996530fe7e 100644
@@ -143,6 +143,24 @@ void qemu_log_unlock(FILE *logfile)
     }
 }
 
+
+void qemu_log_timestamp(const char *fmt, ...)
+{
+    FILE *f = qemu_log_trylock();
+    if (f) {
+        va_list ap;
+        if(message_with_timestamp){
+            struct timeval _now;
+            gettimeofday(&_now, NULL);
+            fprintf(f,"%d@%zu.%06zu:",qemu_get_thread_id(),(size_t)_now.tv_sec,
 (size_t)_now.tv_usec);
+        }
+        va_start(ap, fmt);
+        vfprintf(f, fmt, ap);
+        va_end(ap);
+    }
+    qemu_log_unlock(f);
+}
+
 void qemu_log(const char *fmt, ...)
 {
     FILE *f = qemu_log_trylock();
Quoted 4 lines

--
2.34.1

. (1411968387)
- accel (28672)
- - hvf (4096)
- - kvm (4096)
- - qtest (4096)
- - stubs (4096)
- - tcg (4096)
- - xen (4096)
- audio (4096)
- authz (4096)
- backends (8192)
- - tpm (4096)
- block (71460)
- - export (4096)
- - monitor (4096)
- bsd-user (4096)
- chardev (4096)
- common-user (4096)
- contrib (10086104)
- - elf2dmp (4096)
- - ivshmem-client (164704)
- - - ivshmem-client.p (100656)
- - ivshmem-server (2847992)
- - - ivshmem-server.p (103104)
- - plugins (999680)
- - - libbbv.so.p (36264)
- - - libcache.so.p (92624)
- - - libcflow.so.p (47720)
- - - libdrcov.so.p (32328)
- - - libexeclog.so.p (62632)
- - - libhotblocks.so.p (34864)
- - - libhotpages.so.p (36344)
- - - libhowvec.so.p (50976)
- - - libhwprofile.so.p (54304)
- - - libips.so.p (35136)
- - - liblockstep.so.p (48304)
- - - libstoptrigger.so.p (34920)
- - vhost-user-blk (2966976)
- - - vhost-user-blk.p (96296)
- - vhost-user-gpu (4096)
- - vhost-user-input (3090368)
- - - vhost-user-input.p (77040)
- - vhost-user-scsi (4096)
- crypto (4096)
- disas (4096)
- docs (4125)
- - config (29)
- dump (4096)
- ebpf (4096)
- fpu (4096)
- fsdev (4096)
- gdbstub (4096)
- hw (299008)
- - 9pfs (4096)
- - acpi (4096)
- - adc (4096)
- - alpha (4096)
- - arm (4096)
- - audio (4096)
- - avr (4096)
- - block (8192)
- - - dataplane (4096)
- - char (4096)
- - core (4096)
- - cpu (4096)
- - cxl (4096)
- - display (4096)
- - dma (4096)
- - fsi (4096)
- - gpio (4096)
- - hppa (4096)
- - hyperv (4096)
- - i2c (4096)
- - i386 (12288)
- - - kvm (4096)
- - - xen (4096)
- - ide (4096)
- - input (4096)
- - intc (4096)
- - ipack (4096)
- - ipmi (4096)
- - isa (4096)
- - loongarch (4096)
- - m68k (4096)
- - mem (4096)
- - microblaze (4096)
- - mips (4096)
- - misc (8192)
- - - macio (4096)
- - net (8192)
- - - can (4096)
- - nubus (4096)
- - nvme (4096)
- - nvram (4096)
- - openrisc (4096)
- - pci (4096)
- - pci-bridge (4096)
- - pci-host (4096)
- - ppc (4096)
- - remote (4096)
- - riscv (4096)
- - rtc (4096)
- - rx (4096)
- - s390x (4096)
- - scsi (4096)
- - sd (4096)
- - sensor (4096)
- - sh4 (4096)
- - smbios (4096)
- - sparc (4096)
- - sparc64 (4096)
- - ssi (4096)
- - timer (4096)
- - tpm (4096)
- - tricore (4096)
- - uefi (4096)
- - ufs (4096)
- - usb (4096)
- - vfio (4096)
- - virtio (4096)
- - vmapple (4096)
- - watchdog (4096)
- - xen (4096)
- - xenpv (4096)
- - xtensa (4096)
- io (4096)
- libauthz.a.p (168080)
- libblock.a.p (14810216)
- libblockdev.a.p (1490976)
- libchardev.a.p (1244624)
- libcommon.a.p (96167871)
- libcrypto.a.p (896280)
- libdecnumber (4096)
- libevent-loop-base.a.p (37888)
- libhw_arm.a.p (12578968)
- libhwcore.a.p (597536)
- libio.a.p (999952)
- libmigration.a.p (419480)
- libqemu-aarch64-softmmu.a.p (61546762)
- libqemuutil.a.p (19050240)
- libqmp.a.p (364784)
- libqom.a.p (554808)
- libsystem.a.p (13481032)
- libtarget_arm.a.p (183144)
- libtarget_system_arm.a.p (4923616)
- libuser.a.p (4096)
- linux-headers (4137)
- - asm (41)
- linux-user (4096)
- meson-info (2771188)
- meson-logs (275229)
- meson-private (3269888)
- meson-uninstalled (4417)
- migration (4096)
- monitor (4096)
- nbd (4096)
- net (8192)
- - can (4096)
- pc-bios (317179265)
- - descriptors (9476)
- - dtb (4096)
- - keymaps (4096)
- - optionrom (4140)
- - s390-ccw (4139)
- - vof (4134)
- plugins (5906)
- python (24)
- - qemu (416336)
- - - machine (92087)
- - - - __pycache__ (42481)
- - - qmp (267664)
- - - - __pycache__ (107398)
- - - utils (52188)
- - - - __pycache__ (11857)
- - scripts (33681)
- - tests (24595)
- - wheels (969061)
- pyvenv (6723894)
- - bin (20267)
- - include (4096)
- - lib (6660142)
- - - python3.10 (6656046)
- - - - site-packages (6651950)
- - - - - meson-1.5.0.dist-info (53103)
- - - - - mesonbuild (6567971)
- - - - - - __pycache__ (600827)
- - - - - - ast (136973)
- - - - - - - __pycache__ (66203)
- - - - - - backend (825997)
- - - - - - - __pycache__ (300824)
- - - - - - cargo (110022)
- - - - - - - __pycache__ (50289)
- - - - - - cmake (290870)
- - - - - - - __pycache__ (125313)
- - - - - - - data (10443)
- - - - - - - - __pycache__ (4282)
- - - - - - compilers (984718)
- - - - - - - __pycache__ (292847)
- - - - - - - mixins (315273)
- - - - - - - - __pycache__ (146996)
- - - - - - dependencies (590473)
- - - - - - - __pycache__ (243011)
- - - - - - - data (18763)
- - - - - - - - __pycache__ (4289)
- - - - - - interpreter (698722)
- - - - - - - __pycache__ (272187)
- - - - - - - primitives (58769)
- - - - - - - - __pycache__ (31967)
- - - - - - interpreterbase (166091)
- - - - - - - __pycache__ (77730)
- - - - - - linkers (149349)
- - - - - - - __pycache__ (74861)
- - - - - - modules (657770)
- - - - - - - __pycache__ (275486)
- - - - - - scripts (222092)
- - - - - - - __pycache__ (97787)
- - - - - - templates (87466)
- - - - - - - __pycache__ (44745)
- - - - - - utils (198186)
- - - - - - - __pycache__ (93569)
- - - - - - wrap (95207)
- - - - - - - __pycache__ (40873)
- - - - - pycotap (18838)
- - - - - - __pycache__ (9650)
- - - - - pycotap-1.3.1.dist-info (7942)
- - lib64 (3)
- - - python3.10 (6656046)
- - - - site-packages (6651950)
- - - - - meson-1.5.0.dist-info (53103)
- - - - - mesonbuild (6567971)
- - - - - - __pycache__ (600827)
- - - - - - ast (136973)
- - - - - - - __pycache__ (66203)
- - - - - - backend (825997)
- - - - - - - __pycache__ (300824)
- - - - - - cargo (110022)
- - - - - - - __pycache__ (50289)
- - - - - - cmake (290870)
- - - - - - - __pycache__ (125313)
- - - - - - - data (10443)
- - - - - - - - __pycache__ (4282)
- - - - - - compilers (984718)
- - - - - - - __pycache__ (292847)
- - - - - - - mixins (315273)
- - - - - - - - __pycache__ (146996)
- - - - - - dependencies (590473)
- - - - - - - __pycache__ (243011)
- - - - - - - data (18763)
- - - - - - - - __pycache__ (4289)
- - - - - - interpreter (698722)
- - - - - - - __pycache__ (272187)
- - - - - - - primitives (58769)
- - - - - - - - __pycache__ (31967)
- - - - - - interpreterbase (166091)
- - - - - - - __pycache__ (77730)
- - - - - - linkers (149349)
- - - - - - - __pycache__ (74861)
- - - - - - modules (657770)
- - - - - - - __pycache__ (275486)
- - - - - - scripts (222092)
- - - - - - - __pycache__ (97787)
- - - - - - templates (87466)
- - - - - - - __pycache__ (44745)
- - - - - - utils (198186)
- - - - - - - __pycache__ (93569)
- - - - - - wrap (95207)
- - - - - - - __pycache__ (40873)
- - - - - pycotap (18838)
- - - - - - __pycache__ (9650)
- - - - - pycotap-1.3.1.dist-info (7942)
- - share (34140)
- - - man (20956)
- - - - man1 (16860)
- - - polkit-1 (9088)
- - - - actions (4992)
- qapi (3615578)
- qemu-bridge-helper.p (58608)
- qemu-bundle (149427)
- - usr (145331)
- - - local (141235)
- - - - bin (4398)
- - - - include (4288)
- - - - lib (12390)
- - - - - aarch64-linux-gnu (8294)
- - - - - - pkgconfig (4143)
- - - - libexec (4138)
- - - - share (111925)
- - - - - applications (4129)
- - - - - icons (82330)
- - - - - - hicolor (78234)
- - - - - - - 128x128 (8235)
- - - - - - - - apps (4139)
- - - - - - - 16x16 (8233)
- - - - - - - - apps (4137)
- - - - - - - 24x24 (8233)
- - - - - - - - apps (4137)
- - - - - - - 256x256 (8235)
- - - - - - - - apps (4139)
- - - - - - - 32x32 (8274)
- - - - - - - - apps (4178)
- - - - - - - 48x48 (8233)
- - - - - - - - apps (4137)
- - - - - - - 512x512 (8235)
- - - - - - - - apps (4139)
- - - - - - - 64x64 (8233)
- - - - - - - - apps (4137)
- - - - - - - scalable (8227)
- - - - - - - - apps (4131)
- - - - - qemu (21370)
- - - - - - dtb (4284)
- - - - - - firmware (4614)
- - - - - - keymaps (5343)
- qemu-edid.p (67560)
- qemu-img.p (560272)
- qemu-io.p (86632)
- qemu-nbd.p (228168)
- qemu-pr-helper.p (138208)
- qemu-system-aarch64.p (17888)
- qga (9024028)
- - qemu-ga.p (1454104)
- - qga-ssh-test.p (467536)
- qobject (4096)
- qom (4096)
- replay (4096)
- scripts (25)
- - ci (40231)
- - - gitlab-kubernetes-runners (4944)
- - - setup (22324)
- - - - ubuntu (13076)
- - coccinelle (37606)
- - codeconverter (121649)
- - - codeconverter (113175)
- - coverage (7637)
- - coverity-scan (34706)
- - kvm (17829)
- - modules (6847)
- - oss-fuzz (29700)
- - performance (22463)
- - qapi (371745)
- - - __pycache__ (171135)
- - qemu-guest-agent (11942)
- - - fsfreeze-hook.d (5870)
- - qemugdb (19008)
- - qmp (6225)
- - rust (11572)
- - simplebench (43431)
- - tracetool (119366)
- - - __pycache__ (16835)
- - - backend (39898)
- - - - __pycache__ (21083)
- - - format (45236)
- - - - __pycache__ (19016)
- scsi (4096)
- semihosting (4096)
- stats (4096)
- storage-daemon (15333811)
- - qapi (560459)
- - qemu-storage-daemon.p (932688)
- stubs (4096)
- subprojects (5665366)
- - berkeley-softfloat-3 (2250367)
- - - libsoftfloat.a.p (2207992)
- - berkeley-testfloat-3 (2164351)
- - - libslowfloat.a.p (292232)
- - - libtestfloat.a.p (1842096)
- - dtc (654502)
- - - libfdt (650372)
- - - - libfdt.a.p (323880)
- - keycodemapdb (4096)
- - libvduse (148166)
- - - libvduse.a.p (143432)
- - libvhost-user (439788)
- - - libvhost-user-glib.a.p (48568)
- - - libvhost-user.a.p (216912)
- - - link-test.p (25240)
- system (4096)
- target (172032)
- - alpha (4096)
- - arm (12288)
- - - hvf (4096)
- - - tcg (4096)
- - avr (4096)
- - hexagon (12288)
- - - gen_dectree_import.p (4096)
- - - gen_semantics.p (4096)
- - hppa (4096)
- - i386 (36864)
- - - emulate (4096)
- - - hvf (4096)
- - - kvm (4096)
- - - nvmm (4096)
- - - tcg (12288)
- - - - system (4096)
- - - - user (4096)
- - - whpx (4096)
- - loongarch (12288)
- - - kvm (4096)
- - - tcg (4096)
- - m68k (4096)
- - microblaze (4096)
- - mips (16384)
- - - system (4096)
- - - tcg (8192)
- - - - system (4096)
- - openrisc (4096)
- - ppc (4096)
- - riscv (12288)
- - - kvm (4096)
- - - tcg (4096)
- - rx (4096)
- - s390x (16384)
- - - gen-features.p (4096)
- - - kvm (4096)
- - - tcg (4096)
- - sh4 (4096)
- - sparc (4096)
- - tricore (4096)
- - xtensa (4096)
- tcg (4096)
- tests (608816285)
- - bench (22868048)
- - - atomic64-bench.p (4096)
- - - atomic_add-bench.p (4096)
- - - benchmark-crypto-akcipher.p (41984)
- - - benchmark-crypto-cipher.p (82576)
- - - benchmark-crypto-hash.p (69248)
- - - benchmark-crypto-hmac.p (27904)
- - - bufferiszero-bench.p (17120)
- - - qht-bench.p (89912)
- - - qtree-bench.p (43560)
- - data (28)
- - - acpi (616672)
- - - - aarch64 (43960)
- - - - - virt (39864)
- - - - riscv64 (12818)
- - - - - virt (8722)
- - - - x86 (552373)
- - - - - microvm (10109)
- - - - - pc (133543)
- - - - - q35 (404625)
- - - hex-loader (4828)
- - - qobject (94477)
- - - smbios (4117)
- - - uefi-boot-images (71680)
- - decode (4096)
- - fp (25217664)
- - - fp-bench.p (3654456)
- - - fp-test-log2.p (3391040)
- - - fp-test.p (3682048)
- - functional (4096)
- - include (10313)
- - libtestqapi.a.p (834440)
- - migration-stress (8192)
- - - stress.p (4096)
- - qapi-schema (4096)
- - qemu-iotests (4183)
- - qtest (112478424)
- - - arm-cpu-features.p (440384)
- - - ast2700-gpio-test.p (27032)
- - - ast2700-smc-test.p (173216)
- - - bcm2835-dma-test.p (36584)
- - - bcm2835-i2c-test.p (30840)
- - - bios-tables-test.p (530496)
- - - boot-serial-test.p (42296)
- - - cdrom-test.p (83328)
- - - device-introspect-test.p (89696)
- - - fuzz (4096)
- - - libqos (2723776)
- - - - libqos.a.p (2719680)
- - - machine-none-test.p (27560)
- - - migration-test.p (636616)
- - - netdev-socket.p (149400)
- - - numa-test.p (176752)
- - - qmp-cmd-test.p (78520)
- - - qmp-test.p (87800)
- - - qom-test.p (43616)
- - - qos-test.p (2528416)
- - - readconfig-test.p (53976)
- - - test-hmp.p (33008)
- - - tpm-tis-device-swtpm-test.p (247472)
- - - tpm-tis-device-test.p (262768)
- - - tpm-tis-i2c-test.p (275648)
- - - xlnx-canfd-test.p (49064)
- - - xlnx-versal-trng-test.p (103472)
- - tcg (504917)
- - - aarch64-softmmu (4411)
- - - plugins (496312)
- - - - libbb.so.p (30928)
- - - - libempty.so.p (10520)
- - - - libinline.so.p (60640)
- - - - libinsn.so.p (51448)
- - - - libmem.so.p (57640)
- - - - libreset.so.p (26200)
- - - - libsyscall.so.p (46904)
- - unit (443579368)
- - - check-block-qdict.p (232056)
- - - check-qdict.p (100616)
- - - check-qjson.p (233416)
- - - check-qlist.p (38440)
- - - check-qlit.p (47624)
- - - check-qnull.p (30080)
- - - check-qnum.p (69848)
- - - check-qobject.p (75576)
- - - check-qom-interface.p (26328)
- - - check-qom-proplist.p (124072)
- - - check-qstring.p (33040)
- - - ptimer-test.p (274736)
- - - rcutorture.p (63496)
- - - test-aio-multithread.p (93936)
- - - test-aio.p (298432)
- - - test-authz-list.p (48560)
- - - test-authz-listfile.p (47816)
- - - test-authz-simple.p (22960)
- - - test-base64.p (25952)
- - - test-bdrv-drain.p (444040)
- - - test-bdrv-graph-mod.p (173744)
- - - test-bitcnt.p (26368)
- - - test-bitmap.p (51056)
- - - test-bitops.p (39144)
- - - test-block-backend.p (59912)
- - - test-block-iothread.p (298712)
- - - test-blockjob-txn.p (95088)
- - - test-blockjob.p (125544)
- - - test-bufferiszero.p (21328)
- - - test-char.p (415344)
- - - test-clone-visitor.p (81408)
- - - test-coroutine.p (126000)
- - - test-crypto-afsplit.p (28224)
- - - test-crypto-akcipher.p (52568)
- - - test-crypto-block.p (63424)
- - - test-crypto-cipher.p (64888)
- - - test-crypto-der.p (37928)
- - - test-crypto-hash.p (52984)
- - - test-crypto-hmac.p (42464)
- - - test-crypto-ivgen.p (26184)
- - - test-crypto-pbkdf.p (35544)
- - - test-crypto-secret.p (74136)
- - - test-cutils.p (1023312)
- - - test-div128.p (31552)
- - - test-error-report.p (30152)
- - - test-fifo.p (65792)
- - - test-forward-visitor.p (60400)
- - - test-hbitmap.p (297632)
- - - test-image-locking.p (67600)
- - - test-int128.p (63320)
- - - test-interval-tree.p (62168)
- - - test-io-channel-buffer.p (58624)
- - - test-io-channel-command.p (76256)
- - - test-io-channel-file.p (76928)
- - - test-io-channel-null.p (38800)
- - - test-io-channel-socket.p (167072)
- - - test-io-task.p (75048)
- - - test-iov.p (120720)
- - - test-keyval.p (275392)
- - - test-logging.p (61984)
- - - test-mul64.p (23864)
- - - test-nested-aio-poll.p (32328)
- - - test-opts-visitor.p (94112)
- - - test-qapi-util.p (31792)
- - - test-qdev-global-props.p (75136)
- - - test-qdist.p (72352)
- - - test-qemu-opts.p (348096)
- - - test-qga.p (387264)
- - - test-qgraph.p (195112)
- - - test-qht.p (64320)
- - - test-qmp-cmds.p (114800)
- - - test-qmp-event.p (43464)
- - - test-qobject-input-visitor.p (317568)
- - - test-qobject-output-visitor.p (246616)
- - - test-qtree.p (66144)
- - - test-rcu-list.p (51272)
- - - test-rcu-simpleq.p (53048)
- - - test-rcu-slist.p (51992)
- - - test-rcu-tailq.p (52384)
- - - test-replication.p (196344)
- - - test-resv-mem.p (86264)
- - - test-shift128.p (24616)
- - - test-smp-parse.p (277784)
- - - test-string-input-visitor.p (89368)
- - - test-string-output-visitor.p (70424)
- - - test-thread-pool.p (91888)
- - - test-throttle.p (196920)
- - - test-timed-average.p (27536)
- - - test-util-filemonitor.p (66208)
- - - test-util-sockets.p (98456)
- - - test-uuid.p (39632)
- - - test-virtio-dmabuf.p (127904)
- - - test-visitor-serialization.p (127232)
- - - test-vmstate.p (245912)
- - - test-write-threshold.p (138624)
- - - test-x86-topo.p (48320)
- - - test-xbzrle.p (37552)
- - - test-xs-node.p (432864)
- - - test-yank.p (82744)
- - vhost-user-bridge.p (119176)
- tools (4096)
- trace (7345942)
- ui (1471055)
- - icons (4096)
- - shader (5052)
- util (4096)

. (1435279021)
- accel (28672)
- - hvf (4096)
- - kvm (4096)
- - qtest (4096)
- - stubs (4096)
- - tcg (4096)
- - xen (4096)
- audio (4096)
- authz (4096)
- backends (8192)
- - tpm (4096)
- block (71460)
- - export (4096)
- - monitor (4096)
- bsd-user (4096)
- chardev (4096)
- common-user (4096)
- contrib (10161656)
- - elf2dmp (4096)
- - ivshmem-client (164704)
- - - ivshmem-client.p (100656)
- - ivshmem-server (2876448)
- - - ivshmem-server.p (103104)
- - plugins (999680)
- - - libbbv.so.p (36264)
- - - libcache.so.p (92624)
- - - libcflow.so.p (47720)
- - - libdrcov.so.p (32328)
- - - libexeclog.so.p (62632)
- - - libhotblocks.so.p (34864)
- - - libhotpages.so.p (36344)
- - - libhowvec.so.p (50976)
- - - libhwprofile.so.p (54304)
- - - libips.so.p (35136)
- - - liblockstep.so.p (48304)
- - - libstoptrigger.so.p (34920)
- - vhost-user-blk (2991304)
- - - vhost-user-blk.p (96296)
- - vhost-user-gpu (4096)
- - vhost-user-input (3113136)
- - - vhost-user-input.p (77040)
- - vhost-user-scsi (4096)
- crypto (4096)
- disas (4096)
- docs (4125)
- - config (29)
- dump (4096)
- ebpf (4096)
- fpu (4096)
- fsdev (4096)
- gdbstub (4096)
- hw (299008)
- - 9pfs (4096)
- - acpi (4096)
- - adc (4096)
- - alpha (4096)
- - arm (4096)
- - audio (4096)
- - avr (4096)
- - block (8192)
- - - dataplane (4096)
- - char (4096)
- - core (4096)
- - cpu (4096)
- - cxl (4096)
- - display (4096)
- - dma (4096)
- - fsi (4096)
- - gpio (4096)
- - hppa (4096)
- - hyperv (4096)
- - i2c (4096)
- - i386 (12288)
- - - kvm (4096)
- - - xen (4096)
- - ide (4096)
- - input (4096)
- - intc (4096)
- - ipack (4096)
- - ipmi (4096)
- - isa (4096)
- - loongarch (4096)
- - m68k (4096)
- - mem (4096)
- - microblaze (4096)
- - mips (4096)
- - misc (8192)
- - - macio (4096)
- - net (8192)
- - - can (4096)
- - nubus (4096)
- - nvme (4096)
- - nvram (4096)
- - openrisc (4096)
- - pci (4096)
- - pci-bridge (4096)
- - pci-host (4096)
- - ppc (4096)
- - remote (4096)
- - riscv (4096)
- - rtc (4096)
- - rx (4096)
- - s390x (4096)
- - scsi (4096)
- - sd (4096)
- - sensor (4096)
- - sh4 (4096)
- - smbios (4096)
- - sparc (4096)
- - sparc64 (4096)
- - ssi (4096)
- - timer (4096)
- - tpm (4096)
- - tricore (4096)
- - uefi (4096)
- - ufs (4096)
- - usb (4096)
- - vfio (4096)
- - virtio (4096)
- - vmapple (4096)
- - watchdog (4096)
- - xen (4096)
- - xenpv (4096)
- - xtensa (4096)
- io (4096)
- libauthz.a.p (176496)
- libblock.a.p (14986024)
- libblockdev.a.p (1546968)
- libchardev.a.p (1256800)
- libcommon.a.p (4700927)
- libcommon_arm.a.p (183144)
- libcrypto.a.p (870208)
- libdecnumber (4096)
- libevent-loop-base.a.p (37888)
- libhwcore.a.p (616768)
- libio.a.p (1052800)
- libmigration.a.p (455872)
- libqemu-aarch64-softmmu.a.p (60077810)
- libqemuutil.a.p (21889568)
- libqmp.a.p (376032)
- libqom.a.p (563008)
- libsystem.a.p (107692392)
- libsystem_arm.a.p (17608912)
- libuser.a.p (4096)
- linux-headers (4137)
- - asm (41)
- linux-user (4096)
- meson-info (2779911)
- meson-logs (277751)
- meson-private (3068835)
- meson-uninstalled (4417)
- migration (4096)
- monitor (4096)
- nbd (4096)
- net (8192)
- - can (4096)
- pc-bios (317179265)
- - descriptors (9476)
- - dtb (4096)
- - keymaps (4096)
- - optionrom (4140)
- - s390-ccw (4139)
- - vof (4134)
- plugins (5906)
- python (24)
- - qemu (416336)
- - - machine (92087)
- - - - __pycache__ (42481)
- - - qmp (267664)
- - - - __pycache__ (107398)
- - - utils (52188)
- - - - __pycache__ (11857)
- - scripts (33681)
- - tests (26232)
- - wheels (1022216)
- pyvenv (7116423)
- - bin (20267)
- - include (4096)
- - lib (7052250)
- - - python3.10 (7048154)
- - - - site-packages (7044058)
- - - - - meson-1.8.1.dist-info (58034)
- - - - - - licenses (15454)
- - - - - mesonbuild (6955148)
- - - - - - __pycache__ (640541)
- - - - - - ast (137886)
- - - - - - - __pycache__ (66619)
- - - - - - backend (847015)
- - - - - - - __pycache__ (309186)
- - - - - - cargo (122007)
- - - - - - - __pycache__ (56894)
- - - - - - cmake (293154)
- - - - - - - __pycache__ (126014)
- - - - - - - data (10443)
- - - - - - - - __pycache__ (4282)
- - - - - - compilers (1060017)
- - - - - - - __pycache__ (314657)
- - - - - - - mixins (340122)
- - - - - - - - __pycache__ (158910)
- - - - - - dependencies (622775)
- - - - - - - __pycache__ (256010)
- - - - - - - data (18990)
- - - - - - - - __pycache__ (4289)
- - - - - - interpreter (707204)
- - - - - - - __pycache__ (275409)
- - - - - - - primitives (59220)
- - - - - - - - __pycache__ (32195)
- - - - - - interpreterbase (172978)
- - - - - - - __pycache__ (80068)
- - - - - - linkers (159714)
- - - - - - - __pycache__ (79721)
- - - - - - modules (724743)
- - - - - - - __pycache__ (300731)
- - - - - - scripts (266495)
- - - - - - - __pycache__ (119082)
- - - - - - templates (96253)
- - - - - - - __pycache__ (49463)
- - - - - - utils (195705)
- - - - - - - __pycache__ (91502)
- - - - - - wrap (96029)
- - - - - - - __pycache__ (41242)
- - - - - pycotap (18838)
- - - - - - __pycache__ (9650)
- - - - - pycotap-1.3.1.dist-info (7942)
- - lib64 (3)
- - - python3.10 (7048154)
- - - - site-packages (7044058)
- - - - - meson-1.8.1.dist-info (58034)
- - - - - - licenses (15454)
- - - - - mesonbuild (6955148)
- - - - - - __pycache__ (640541)
- - - - - - ast (137886)
- - - - - - - __pycache__ (66619)
- - - - - - backend (847015)
- - - - - - - __pycache__ (309186)
- - - - - - cargo (122007)
- - - - - - - __pycache__ (56894)
- - - - - - cmake (293154)
- - - - - - - __pycache__ (126014)
- - - - - - - data (10443)
- - - - - - - - __pycache__ (4282)
- - - - - - compilers (1060017)
- - - - - - - __pycache__ (314657)
- - - - - - - mixins (340122)
- - - - - - - - __pycache__ (158910)
- - - - - - dependencies (622775)
- - - - - - - __pycache__ (256010)
- - - - - - - data (18990)
- - - - - - - - __pycache__ (4289)
- - - - - - interpreter (707204)
- - - - - - - __pycache__ (275409)
- - - - - - - primitives (59220)
- - - - - - - - __pycache__ (32195)
- - - - - - interpreterbase (172978)
- - - - - - - __pycache__ (80068)
- - - - - - linkers (159714)
- - - - - - - __pycache__ (79721)
- - - - - - modules (724743)
- - - - - - - __pycache__ (300731)
- - - - - - scripts (266495)
- - - - - - - __pycache__ (119082)
- - - - - - templates (96253)
- - - - - - - __pycache__ (49463)
- - - - - - utils (195705)
- - - - - - - __pycache__ (91502)
- - - - - - wrap (96029)
- - - - - - - __pycache__ (41242)
- - - - - pycotap (18838)
- - - - - - __pycache__ (9650)
- - - - - pycotap-1.3.1.dist-info (7942)
- - share (34561)
- - - man (21377)
- - - - man1 (17281)
- - - polkit-1 (9088)
- - - - actions (4992)
- qapi (3604673)
- qemu-bridge-helper.p (58608)
- qemu-bundle (149427)
- - usr (145331)
- - - local (141235)
- - - - bin (4398)
- - - - include (4288)
- - - - lib (12390)
- - - - - aarch64-linux-gnu (8294)
- - - - - - pkgconfig (4143)
- - - - libexec (4138)
- - - - share (111925)
- - - - - applications (4129)
- - - - - icons (82330)
- - - - - - hicolor (78234)
- - - - - - - 128x128 (8235)
- - - - - - - - apps (4139)
- - - - - - - 16x16 (8233)
- - - - - - - - apps (4137)
- - - - - - - 24x24 (8233)
- - - - - - - - apps (4137)
- - - - - - - 256x256 (8235)
- - - - - - - - apps (4139)
- - - - - - - 32x32 (8274)
- - - - - - - - apps (4178)
- - - - - - - 48x48 (8233)
- - - - - - - - apps (4137)
- - - - - - - 512x512 (8235)
- - - - - - - - apps (4139)
- - - - - - - 64x64 (8233)
- - - - - - - - apps (4137)
- - - - - - - scalable (8227)
- - - - - - - - apps (4131)
- - - - - qemu (21370)
- - - - - - dtb (4284)
- - - - - - firmware (4614)
- - - - - - keymaps (5343)
- qemu-edid.p (67560)
- qemu-img.p (561136)
- qemu-io.p (86632)
- qemu-nbd.p (228504)
- qemu-pr-helper.p (138560)
- qemu-system-aarch64.p (17896)
- qga (9093716)
- - qemu-ga.p (1454776)
- - qga-ssh-test.p (467536)
- qobject (4096)
- qom (4096)
- replay (4096)
- scripts (25)
- - ci (40231)
- - - gitlab-kubernetes-runners (4944)
- - - setup (22324)
- - - - ubuntu (13076)
- - coccinelle (37606)
- - codeconverter (121649)
- - - codeconverter (113175)
- - coverage (7637)
- - coverity-scan (34706)
- - kvm (17829)
- - modules (6847)
- - oss-fuzz (29700)
- - performance (22463)
- - qapi (371567)
- - - __pycache__ (171135)
- - qemu-guest-agent (11942)
- - - fsfreeze-hook.d (5870)
- - qemugdb (19008)
- - qmp (6225)
- - rust (11364)
- - simplebench (43431)
- - tracetool (120294)
- - - __pycache__ (16835)
- - - backend (40826)
- - - - __pycache__ (21468)
- - - format (45236)
- - - - __pycache__ (19016)
- scsi (4096)
- semihosting (4096)
- stats (4096)
- storage-daemon (15544163)
- - qapi (563107)
- - qemu-storage-daemon.p (936504)
- stubs (4096)
- subprojects (5665366)
- - berkeley-softfloat-3 (2250367)
- - - libsoftfloat.a.p (2207992)
- - berkeley-testfloat-3 (2164351)
- - - libslowfloat.a.p (292232)
- - - libtestfloat.a.p (1842096)
- - dtc (654502)
- - - libfdt (650372)
- - - - libfdt.a.p (323880)
- - keycodemapdb (4096)
- - libvduse (148166)
- - - libvduse.a.p (143432)
- - libvhost-user (439788)
- - - libvhost-user-glib.a.p (48568)
- - - libvhost-user.a.p (216912)
- - - link-test.p (25240)
- system (4096)
- target (172032)
- - alpha (4096)
- - arm (12288)
- - - hvf (4096)
- - - tcg (4096)
- - avr (4096)
- - hexagon (12288)
- - - gen_dectree_import.p (4096)
- - - gen_semantics.p (4096)
- - hppa (4096)
- - i386 (36864)
- - - emulate (4096)
- - - hvf (4096)
- - - kvm (4096)
- - - nvmm (4096)
- - - tcg (12288)
- - - - system (4096)
- - - - user (4096)
- - - whpx (4096)
- - loongarch (12288)
- - - kvm (4096)
- - - tcg (4096)
- - m68k (4096)
- - microblaze (4096)
- - mips (16384)
- - - system (4096)
- - - tcg (8192)
- - - - system (4096)
- - openrisc (4096)
- - ppc (4096)
- - riscv (12288)
- - - kvm (4096)
- - - tcg (4096)
- - rx (4096)
- - s390x (16384)
- - - gen-features.p (4096)
- - - kvm (4096)
- - - tcg (4096)
- - sh4 (4096)
- - sparc (4096)
- - tricore (4096)
- - xtensa (4096)
- tcg (4096)
- tests (620978069)
- - bench (22834304)
- - - atomic64-bench.p (4096)
- - - atomic_add-bench.p (4096)
- - - benchmark-crypto-akcipher.p (41984)
- - - benchmark-crypto-cipher.p (82576)
- - - benchmark-crypto-hash.p (69248)
- - - benchmark-crypto-hmac.p (27904)
- - - bufferiszero-bench.p (17120)
- - - qht-bench.p (89912)
- - - qtree-bench.p (43560)
- - data (28)
- - - acpi (616672)
- - - - aarch64 (43960)
- - - - - virt (39864)
- - - - riscv64 (12818)
- - - - - virt (8722)
- - - - x86 (552373)
- - - - - microvm (10109)
- - - - - pc (133543)
- - - - - q35 (404625)
- - - hex-loader (4828)
- - - qobject (94477)
- - - smbios (4117)
- - - uefi-boot-images (84480)
- - decode (4096)
- - fp (25311232)
- - - fp-bench.p (3654456)
- - - fp-test-log2.p (3391040)
- - - fp-test.p (3682048)
- - functional (4096)
- - include (10313)
- - libtestqapi.a.p (834440)
- - migration-stress (8192)
- - - stress.p (4096)
- - qapi-schema (4096)
- - qemu-iotests (4183)
- - qtest (121190336)
- - - arm-cpu-features.p (440384)
- - - ast2700-gpio-test.p (27032)
- - - ast2700-hace-test.p (127368)
- - - ast2700-smc-test.p (173456)
- - - bcm2835-dma-test.p (36584)
- - - bcm2835-i2c-test.p (30840)
- - - bios-tables-test.p (531168)
- - - boot-serial-test.p (42296)
- - - cdrom-test.p (83328)
- - - device-introspect-test.p (89696)
- - - fuzz (4096)
- - - libqos (2723776)
- - - - libqos.a.p (2719680)
- - - machine-none-test.p (27560)
- - - migration-test.p (641048)
- - - netdev-socket.p (149736)
- - - npcm_gmac-test.p (189000)
- - - numa-test.p (176752)
- - - qmp-cmd-test.p (78592)
- - - qmp-test.p (87800)
- - - qom-test.p (43616)
- - - qos-test.p (2528416)
- - - readconfig-test.p (53976)
- - - test-hmp.p (33008)
- - - tpm-tis-device-swtpm-test.p (248816)
- - - tpm-tis-device-test.p (264456)
- - - tpm-tis-i2c-test.p (276992)
- - - xlnx-canfd-test.p (49064)
- - - xlnx-versal-trng-test.p (103472)
- - tcg (504917)
- - - aarch64-softmmu (4411)
- - - plugins (496312)
- - - - libbb.so.p (30928)
- - - - libempty.so.p (10520)
- - - - libinline.so.p (60640)
- - - - libinsn.so.p (51448)
- - - - libmem.so.p (57640)
- - - - libreset.so.p (26200)
- - - - libsyscall.so.p (46904)
- - unit (446949184)
- - - check-block-qdict.p (232056)
- - - check-qdict.p (100616)
- - - check-qjson.p (233416)
- - - check-qlist.p (38440)
- - - check-qlit.p (47624)
- - - check-qnull.p (30080)
- - - check-qnum.p (69848)
- - - check-qobject.p (75576)
- - - check-qom-interface.p (26328)
- - - check-qom-proplist.p (124072)
- - - check-qstring.p (33040)
- - - ptimer-test.p (274736)
- - - rcutorture.p (63496)
- - - test-aio-multithread.p (93920)
- - - test-aio.p (298432)
- - - test-authz-list.p (48560)
- - - test-authz-listfile.p (47816)
- - - test-authz-simple.p (22960)
- - - test-base64.p (25952)
- - - test-bdrv-drain.p (444472)
- - - test-bdrv-graph-mod.p (174928)
- - - test-bitcnt.p (26368)
- - - test-bitmap.p (51056)
- - - test-bitops.p (39144)
- - - test-block-backend.p (59912)
- - - test-block-iothread.p (299048)
- - - test-blockjob-txn.p (95088)
- - - test-blockjob.p (125544)
- - - test-bufferiszero.p (21328)
- - - test-char.p (415728)
- - - test-clone-visitor.p (81408)
- - - test-coroutine.p (126000)
- - - test-crypto-afsplit.p (28224)
- - - test-crypto-akcipher.p (52568)
- - - test-crypto-block.p (64912)
- - - test-crypto-cipher.p (65200)
- - - test-crypto-der.p (37928)
- - - test-crypto-hash.p (52984)
- - - test-crypto-hmac.p (42464)
- - - test-crypto-ivgen.p (26184)
- - - test-crypto-pbkdf.p (35544)
- - - test-crypto-secret.p (75808)
- - - test-cutils.p (1023312)
- - - test-div128.p (31552)
- - - test-error-report.p (30152)
- - - test-fifo.p (65792)
- - - test-forward-visitor.p (60400)
- - - test-hbitmap.p (297632)
- - - test-image-locking.p (67600)
- - - test-int128.p (63320)
- - - test-interval-tree.p (62168)
- - - test-io-channel-buffer.p (58624)
- - - test-io-channel-command.p (76256)
- - - test-io-channel-file.p (76928)
- - - test-io-channel-null.p (38800)
- - - test-io-channel-socket.p (167440)
- - - test-io-task.p (75048)
- - - test-iov.p (120720)
- - - test-keyval.p (275392)
- - - test-logging.p (61984)
- - - test-mul64.p (23864)
- - - test-nested-aio-poll.p (32328)
- - - test-opts-visitor.p (94112)
- - - test-qapi-util.p (31792)
- - - test-qdev-global-props.p (75136)
- - - test-qdist.p (72352)
- - - test-qemu-opts.p (348096)
- - - test-qga.p (387264)
- - - test-qgraph.p (195112)
- - - test-qht.p (64320)
- - - test-qmp-cmds.p (114800)
- - - test-qmp-event.p (43464)
- - - test-qobject-input-visitor.p (317568)
- - - test-qobject-output-visitor.p (246616)
- - - test-qtree.p (66144)
- - - test-rcu-list.p (51272)
- - - test-rcu-simpleq.p (53048)
- - - test-rcu-slist.p (51992)
- - - test-rcu-tailq.p (52384)
- - - test-replication.p (196680)
- - - test-resv-mem.p (86264)
- - - test-shift128.p (24616)
- - - test-smp-parse.p (277672)
- - - test-string-input-visitor.p (89368)
- - - test-string-output-visitor.p (70424)
- - - test-thread-pool.p (91888)
- - - test-throttle.p (196920)
- - - test-timed-average.p (27536)
- - - test-util-filemonitor.p (66208)
- - - test-util-sockets.p (138048)
- - - test-uuid.p (39632)
- - - test-virtio-dmabuf.p (127976)
- - - test-visitor-serialization.p (127232)
- - - test-vmstate.p (245912)
- - - test-write-threshold.p (138968)
- - - test-x86-topo.p (48320)
- - - test-xbzrle.p (37552)
- - - test-xs-node.p (432864)
- - - test-yank.p (83152)
- - vhost-user-bridge.p (119176)
- tools (4096)
- trace (9940283)
- ui (1471055)
- - icons (4096)
- - shader (5052)
- util (4096)

#2 lore raw
In reply to Tanish Desai
Quoted 8 lines · Tanish Desai

Moved the logic for timestamped logging (~6 lines) from a_nocheck__trace_foo(header) into a new qemu_log_timestamp() function in util/log.c. This avoids code duplication across binaries and enables reuse as a standalone utility. Encapsulation helps reduce build size significantly, particularly when many trace points are present. On Ubuntu 22 with
./configure --target-list=aarch64-softmmu --enable-kvm --enable-trace-backends=log,
this change reduced the build directory size from ~1435.27 MB to ~1412 MB (~23 MB saved).
Notable reductions include:
trace/: ~2.6 MB
libqemuutil.a.p: ~3 MB
A detailed report of size changes (in bytes) for relevant folders and subfolders will follow in a trailing mail.

I think this is inline to avoid overhead of function call at runtime when logging is not enabled which is more important than saving build time or disk space but I could be wrong.

Regards,
BALATON Zoltan

Quoted 75 lines

---

include/qemu/log-for-trace.h     |  3 +++
scripts/tracetool/backend/log.py | 13 +------------
util/log.c                       | 18 ++++++++++++++++++
3 files changed, 22 insertions(+), 12 deletions(-)
include/qemu/log-for-trace.h +3 -0
index d47c9cd446..680f30a8a9 100644
@@ -32,4 +32,7 @@ static inline bool qemu_loglevel_mask(int mask)
 /* main logging function */
 void G_GNUC_PRINTF(1, 2) qemu_log(const char *fmt, ...);
 
+/* main logging function with timestamp */
+void G_GNUC_PRINTF(1, 2) qemu_log_timestamp(const char *fmt, ...);
+
 #endif
scripts/tracetool/backend/log.py +1 -12
index de27b7e62e..3358afb43a 100644
@@ -38,20 +38,9 @@ def generate_h(event, group):
        cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
 
    out('    if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
-        '        if (message_with_timestamp) {',
-        '            struct timeval _now;',
-        '            gettimeofday(&_now, NULL);',
        '#line %(event_lineno)d "%(event_filename)s"',
-        '            qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s "\\n",',
-        '                     qemu_get_thread_id(),',
-        '                     (size_t)_now.tv_sec, (size_t)_now.tv_usec',
-        '                     %(argnames)s);',
+        '            qemu_log_timestamp("%(name)s " %(fmt)s "\\n"%(argnames)s);',
        '#line %(out_next_lineno)d "%(out_filename)s"',
-        '        } else {',
-        '#line %(event_lineno)d "%(event_filename)s"',
-        '            qemu_log("%(name)s " %(fmt)s "\\n"%(argnames)s);',
-        '#line %(out_next_lineno)d "%(out_filename)s"',
-        '        }',
        '    }',
        cond=cond,
        event_lineno=event.lineno,
util/log.c +18 -0
index b87d399e4c..996530fe7e 100644
@@ -143,6 +143,24 @@ void qemu_log_unlock(FILE *logfile)
    }
 }
 
+
+void qemu_log_timestamp(const char *fmt, ...)
+{
+    FILE *f = qemu_log_trylock();
+    if (f) {
+        va_list ap;
+        if(message_with_timestamp){
+            struct timeval _now;
+            gettimeofday(&_now, NULL);
+            fprintf(f,"%d@%zu.%06zu:",qemu_get_thread_id(),(size_t)_now.tv_sec, (size_t)_now.tv_usec);
+        }
+        va_start(ap, fmt);
+        vfprintf(f, fmt, ap);
+        va_end(ap);
+    }
+    qemu_log_unlock(f);
+}
+
 void qemu_log(const char *fmt, ...)
 {
    FILE *f = qemu_log_trylock();
#3 lore raw
Quoted 11 lines · BALATON Zoltan
Quoted 9 lines · Tanish Desai

Moved the logic for timestamped logging (~6 lines) from a_nocheck__trace_foo(header) into a new qemu_log_timestamp() function in util/log.c. This avoids code duplication across binaries and enables reuse as a standalone utility. Encapsulation helps reduce build size significantly, particularly when many trace points are present. On Ubuntu 22 with
./configure --target-list=aarch64-softmmu --enable-kvm
--enable-trace-backends=log,
this change reduced the build directory size from ~1435.27 MB to ~1412 MB (~23 MB saved).
Notable reductions include:
trace/: ~2.6 MB
libqemuutil.a.p: ~3 MB
A detailed report of size changes (in bytes) for relevant folders and subfolders will follow in a trailing mail.

Quoted 1 line

I think this is inline to avoid overhead of function call at runtime when logging is not enabled which is more important than saving build time or disk space but I could be wrong.

On second look this keeps the conditon inline only moves the timestamp so maybe OK but I'd let others more knowledgeable judge it.

Regards,
BALATON Zoltan

Quoted 80 lines
Quoted 78 lines

---

include/qemu/log-for-trace.h     |  3 +++
scripts/tracetool/backend/log.py | 13 +------------
util/log.c                       | 18 ++++++++++++++++++
3 files changed, 22 insertions(+), 12 deletions(-)
include/qemu/log-for-trace.h +3 -0
index d47c9cd446..680f30a8a9 100644
@@ -32,4 +32,7 @@ static inline bool qemu_loglevel_mask(int mask)
 /* main logging function */
 void G_GNUC_PRINTF(1, 2) qemu_log(const char *fmt, ...);
 
+/* main logging function with timestamp */
+void G_GNUC_PRINTF(1, 2) qemu_log_timestamp(const char *fmt, ...);
+
 #endif
scripts/tracetool/backend/log.py +1 -12
index de27b7e62e..3358afb43a 100644
@@ -38,20 +38,9 @@ def generate_h(event, group):
        cond = "trace_event_get_state(%s)" % ("TRACE_" + 
 event.name.upper())
 
    out('    if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
-        '        if (message_with_timestamp) {',
-        '            struct timeval _now;',
-        '            gettimeofday(&_now, NULL);',
        '#line %(event_lineno)d "%(event_filename)s"',
-        '            qemu_log("%%d@%%zu.%%06zu:%(name)s " %(fmt)s "\\n",',
-        '                     qemu_get_thread_id(),',
-        '                     (size_t)_now.tv_sec, (size_t)_now.tv_usec',
-        '                     %(argnames)s);',
+        '            qemu_log_timestamp("%(name)s " %(fmt)s 
 "\\n"%(argnames)s);',
        '#line %(out_next_lineno)d "%(out_filename)s"',
-        '        } else {',
-        '#line %(event_lineno)d "%(event_filename)s"',
-        '            qemu_log("%(name)s " %(fmt)s "\\n"%(argnames)s);',
-        '#line %(out_next_lineno)d "%(out_filename)s"',
-        '        }',
        '    }',

cond=cond,
event_lineno=event.lineno,

util/log.c +18 -0
index b87d399e4c..996530fe7e 100644
@@ -143,6 +143,24 @@ void qemu_log_unlock(FILE *logfile)
    }
 }
 
+
+void qemu_log_timestamp(const char *fmt, ...)
+{
+    FILE *f = qemu_log_trylock();
+    if (f) {
+        va_list ap;
+        if(message_with_timestamp){
+            struct timeval _now;
+            gettimeofday(&_now, NULL);
+ 
 fprintf(f,"%d@%zu.%06zu:",qemu_get_thread_id(),(size_t)_now.tv_sec, (size_t)_now.tv_usec);
+        }
+        va_start(ap, fmt);
+        vfprintf(f, fmt, ap);
+        va_end(ap);
+    }
+    qemu_log_unlock(f);
+}
+
 void qemu_log(const char *fmt, ...)
 {
    FILE *f = qemu_log_trylock();
#4 lore raw
In reply to Tanish Desai
Quoted 9 lines · Tanish Desai

Moved the logic for timestamped logging (~6 lines) from a_nocheck__trace_foo(header) into a new qemu_log_timestamp() function in util/log.c. This avoids code duplication across binaries and enables reuse as a standalone utility. Encapsulation helps reduce build size significantly, particularly when many trace points are present. On Ubuntu 22 with
./configure --target-list=aarch64-softmmu --enable-kvm --enable-trace-backends=log,
this change reduced the build directory size from ~1435.27 MB to ~1412 MB (~23 MB saved).
Notable reductions include:
trace/: ~2.6 MB
libqemuutil.a.p: ~3 MB
A detailed report of size changes (in bytes) for relevant folders and subfolders will follow in a trailing mail.

Nice, the output of size(1) on qemu-system-x86_64 is reduced by 3% (839 KB) when built with gcc 15.1.1 on x86_64:

text data bss dec hex filename

14712231        13652904         149496 28514631        1b31947 before
13852879        13652904         149496 27655279        1a5fc6f after

That is in the same ballpark as the change in build directory size you measured.

Quoted 14 lines
util/log.c +6 -0
index b87d399e4c..996530fe7e 100644
@@ -143,6 +143,24 @@ void qemu_log_unlock(FILE *logfile)
     }
 }
 
+
+void qemu_log_timestamp(const char *fmt, ...)
+{
+    FILE *f = qemu_log_trylock();
+    if (f) {
+        va_list ap;

util/log.c void qemu_log_unlock(FILE *logfile) · line 161

Quoted 10 lines
util/log.c +10 -0
+        if(message_with_timestamp){
+            struct timeval _now;
+            gettimeofday(&_now, NULL);
+            fprintf(f,"%d@%zu.%06zu:",qemu_get_thread_id(),(size_t)_now.tv_sec, (size_t)_now.tv_usec);
+        }
+        va_start(ap, fmt);
+        vfprintf(f, fmt, ap);
+        va_end(ap);
+    }
+    qemu_log_unlock(f);

Although calling qemu_log_unlock(NULL) is safe, existing callers invoke this function inside the if (f) { ... } body. Please follow that approach for consistency.

Looks good aside from that.

#5 lore raw

Thank you everyone for the review I have shared [PATCH v2] utils/log: add qemu_log_timestamp() in a separate mail thread with the suggested changes.

Quoted 61 lines · Stefan Hajnoczi
Quoted 2 lines · Tanish Desai

Moved the logic for timestamped logging (~6 lines) from

a_nocheck__trace_foo(header) into a new qemu_log_timestamp() function in util/log.c. This avoids code duplication across binaries and enables reuse as a standalone utility.

Quoted 1 line

Encapsulation helps reduce build size significantly, particularly when

many trace points are present. On Ubuntu 22 with

Quoted 1 line

./configure --target-list=aarch64-softmmu --enable-kvm

--enable-trace-backends=log,

Quoted 1 line

this change reduced the build directory size from ~1435.27 MB to ~1412

MB (~23 MB saved).

Quoted 4 lines

Notable reductions include:
trace/: ~2.6 MB
libqemuutil.a.p: ~3 MB
A detailed report of size changes (in bytes) for relevant folders and

subfolders will follow in a trailing mail.

Nice, the output of size(1) on qemu-system-x86_64 is reduced by 3% (839 KB) when built with gcc 15.1.1 on x86_64:

text data bss dec hex filename

14712231        13652904         149496 28514631        1b31947 before
13852879        13652904         149496 27655279        1a5fc6f after

That is in the same ballpark as the change in build directory size you measured.

Quoted 8 lines
util/log.c +0 -0
index b87d399e4c..996530fe7e 100644
@@ -143,6 +143,24 @@ void qemu_log_unlock(FILE *logfile)
     }
 }
 

util/log.c void qemu_log_unlock(FILE *logfile) · line 155

Quoted 10 lines
util/log.c +10 -0
+
+void qemu_log_timestamp(const char *fmt, ...)
+{
+    FILE *f = qemu_log_trylock();
+    if (f) {
+        va_list ap;
+        if(message_with_timestamp){
+            struct timeval _now;
+            gettimeofday(&_now, NULL);
+            fprintf(f,"%d@%zu.%06zu:",qemu_get_thread_id(),(size_t)_now.tv_sec,

(size_t)_now.tv_usec);

util/log.c void qemu_log_unlock(FILE *logfile) · line 161

Quoted 6 lines
util/log.c +6 -0
+        }
+        va_start(ap, fmt);
+        vfprintf(f, fmt, ap);
+        va_end(ap);
+    }
+    qemu_log_unlock(f);

Although calling qemu_log_unlock(NULL) is safe, existing callers invoke this function inside the if (f) { ... } body. Please follow that approach for consistency.

Looks good aside from that.