How to debug qemu using trace-event?

The following steps is an example to use trace-event (the tracing infrastrucure) to print useful qemu logs.

1. git clone git://git.qemu-project.org/qemu.git
2. cd qemu
3. Make sure you add trace_xxx(args) inside of the functions where you want to trace the arguments && define xxx(args) in the trace-events file in qemu code, so that the tracing infrastrucure can trace it
4. ./configure --target-list=x86_64-softmmu --enable-kvm --enable-trace-backends=simple && make -j4
5. If you want to see the logs without having to exit qemu process, please create a file with the events you want to trace. e.g.
   host# cat /tmp/events
   virtio_pci_load_config
   virtio_blk_req_complete
   virtio_blk_handle_write
   virtio_blk_handle_read
Or you can add these events via hmp later, but then can only see the logs after killing the qemu process, which is not a flexible one IMO.
6. run qemu cmd line to start the vm: `x86_64-softmmu/qemu-system-x86_64 --enable-kvm -m 2048 -drive file=/opt/leap423.qcow2,if=none,format=qcow2,id=drive0 -device virtio-blk-pci,drive=drive0,id=dev0 -netdev bridge,br=virbr0,id=virbr0-net -device virio-net,netdev=virbr0-net,id=virnet -monitor stdio -trace events=/tmp/events,file=trace.bin`
Note: the "events=/tmp/events" defines the file storing events that you want to trace; "file=trace.bin" is the bin file generated for current tracing. And if you do not define the "file=xxx", you can use the bin file generated automatically under the qemu project named "trace-QEMUpid"
7. An optional step in hmp:
   - `info trace-events` displays all events, 1 means being tracked like
     (qemu) info trace-events
     cpu_set_state : state 0
     virtio_blk_req_complete : state 1
   - `trace-event virtio_blk_handle_read on` to dynamically add events, but can only see its logs after killing the qemu process

8. run `./script/simpletrace.py trace-events trace.bin/trace-QEMUpid` to see the outputs, like:

virtio_blk_req_complete 0.000 pid=22880 req=0x55eb6f307670 status=0x0
virtio_blk_req_complete 32.869 pid=22880 req=0x55eb6f0515d0 status=0x0
virtio_blk_req_complete 35.624 pid=22880 req=0x55eb6f2576d0 status=0x0
virtio_blk_req_complete 7.098 pid=22880 req=0x55eb6f0d3660 status=0x0
virtio_blk_req_complete 230.246 pid=22880 req=0x55eb6eb6cf10 status=0x0
virtio_blk_req_complete 17.021 pid=22880 req=0x55eb6f293c00 status=0x0
virtio_blk_req_complete 3.417 pid=22880 req=0x55eb6db21900 status=0x0
virtio_blk_req_complete 2.977 pid=22880 req=0x55eb6db61930 status=0x0
...

猜你喜欢

转载自blog.csdn.net/Shirleylinyuer/article/details/80283008