For performance issue, like a rpc all takes long time, you want to know which function takes much time without modifying source code and restart libvirt, also you want to collect stats of libvirt, here I will share the way to meet this reqirement, the core tool is systemtap, you can also refer to linux systemtap guide which shows how to enable systemtap and write probes. with systemtap, you can insert any code outside application without restarting it or rebuilding it
systemtap
Systemtap is a scripting language and tool for dynamically probing or tracing in Linux kernel space or user space. libvirt already has built in markers(static probes) and tapset to simple your use, this feature can be enabled when compile libvirt
1 2
$ ../configure --with-dtrace $ make
The tapset is installed at /usr/share/systemtap/tapset/libvirt_* if enabled.
when dtrace enabled, you can use the markers registered in source code and probe on marker like this, debuginfo is not a must in this way, this is can used for production env!!!
# check the args for each marker in order to use that marker # vi /usr/share/systemtap/tapset/libvirt_qemu_probes.stp # vi /usr/share/systemtap/tapset/libvirt_probes.stp
Write probe on marker
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# stp is a script but similar like C $ cat qmp.stp probe begin { printf("Start tracing\n"); } # check marker parameters from above probe libvirt.qemu.monitor_send_msg { printf("%s QMPs: %s", tz_ctime(gettimeofday_s()), msg); }
# OR enable probe when starting libvirtd $ stap qmp.stp -c "/usr/sbin/libvirtd"
without dtrace enable
When dtrace is disabled, there is no markder available, you have to write probe by yourself and build with deubg mode or install debuginfo of libvirt and shared library used by libvirt, without dtrace from libvirt itself, you have more freedom and more control, as you can trace on any function, but more complex as well.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# must build libvirt and shared library with debuginfo first
$ cat qmp.stp probe begin { printf("Start tracing\n") } # check the function parameters probe process("/usr/lib64/libvirt/connection-driver/libvirt_driver_qemu.so").function("qemuMonitorSend") { // can access fields like we did in C printf("%s, mon fd: %d, vm: %s, QMPs: %s", tz_ctime(gettimeofday_s()), $mon->fd, user_string($mon->vm->def->name), user_string($msg->txBuffer)) }