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
...

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值