虚拟化|qemu trace event

实例

diff --git a/hw/virtio/trace-events b/hw/virtio/trace-events index 650e521e3..7c254468d 100644 --- a/hw/virtio/trace-events +++ b/hw/virtio/trace-events @@ -63,6 +63,10 @@ virtio_queue_notify(void *vdev, int n, void *vq) "vdev %p n %d vq %p" virtio_notify_irqfd(void *vdev, void *vq) "vdev %p vq %p" virtio_notify(void *vdev, void *vq) "vdev %p vq %p" virtio_set_status(void *vdev, uint8_t val) "vdev %p val %u" +virtio_device_realize(void *dev) "dev %p" + +# virtio-pci.c +virtio_pci_realize(void *pci_dev) "pci_dev %p"diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c index 750aa47ec..982c90b1b 100644 --- a/hw/virtio/virtio-pci.c +++ b/hw/virtio/virtio-pci.c @@ -27,6 +27,7 @@ #include "hw/qdev-properties.h" #include "qapi/error.h" #include "qemu/error-report.h" +#include "trace.h" #include "qemu/log.h" #include "qemu/module.h" #include "hw/pci/msi.h" @@ -1785,9 +1786,10 @@ static void virtio_pci_device_unplugged(DeviceState *d) } } } - +/* virtio_pci net或blk的实现部分 */ static void virtio_pci_realize(PCIDevice *pci_dev, Error **errp) { +trace_virtio_pci_realize(pci_dev); VirtIOPCIProxy *proxy = VIRTIO_PCI(pci_dev); VirtioPCIClass *k = VIRTIO_PCI_GET_CLASS(pci_dev); bool pcie_port = pci_bus_is_express(pci_get_bus(pci_dev)) && diff --git a/hw/virtio/virtio.c b/hw/virtio/virtio.c index ea7c079fb..897c9a333 100644 --- a/hw/virtio/virtio.c +++ b/hw/virtio/virtio.c @@ -3636,6 +3636,7 @@ static void virtio_memory_listener_commit(MemoryListener *listener) static void virtio_device_realize(DeviceState *dev, Error **errp) { +trace_virtio_device_realize(dev); VirtIODevice *vdev = VIRTIO_DEVICE(dev); VirtioDeviceClass *vdc = VIRTIO_DEVICE_GET_CLASS(dev); Error *err = NULL;

例子加了一个trace_virtio_pci_realize 和 trace_virtio_device_realize 两个trace event。
编译 编译时需要加上--enable-trace-backends=log,qemu启动的时候可以通过-d指定trace事件
# qemu -d trace:qio* ...some args...
#-trace enable=*,file=/root/trace trace所有的,如果使用-D指定log文件会覆盖/root/trace
./configure --enable-trace-backends=log│PCI_SLOT_NAME=0000:00:03.0
--enable-kvm --enable-debug --enable-debug-info --enable-vnc --target-lis│MODALIAS=pci:v00001AF4d00001000sv00001AF4sd00000001bc02sc00i00
t=x86_64-softmmu
# make -j20; make install
编译安装好后,所有的trace event会记录在 /usr/share/qemu-kvm/trace-events-all 文件中
运行
# qemu-system-x86_64 -name centos8 -machine pc-i440fx-2.1,accel=kvm \ -cpu host -m 4096 -smp 2,sockets=1,cores=2,threads=1 -boot menu=on \ -drive file=/home/wlm/centos8.4-8g-ext4-host.img,media=disk,format=raw,if=none,id=systemdisk \ -device virtio-blk-pci,scsi=off,addr=0x04,drive=systemdisk,id=systemdiskvirtio,bootindex=0 \ -netdev tap,id=ens47f0v0,ifname=vnet0,script=no,downscript=no,vhost=on \ -device virtio-net-pci,netdev=ens47f0v0,mac=00:16:35:AF:94:4B \ -vnc :21 -D /var/log/qemu-1.log -chardev file,path=/var/log/mg.log,id=char0 \ -serial chardev:char0 -trace events=/home/wlm/events \ -serial telnet:localhost:4321,server,nowait \ -device edu\ -monitor stdio

可以看到如下打印,另个virtio设备实现。
【虚拟化|qemu trace event】虚拟化|qemu trace event
文章图片


参考 QEMU跟踪 / QEMU文档翻译: Tracing - JciX ~

    推荐阅读