KVM Tracing, perf_events
Perf events - KVMhttps://www.linux-kvm.org/page/Perf_eventsQemu Tracing_RToax-CSDN博客Tracing — QEMU documentationhttps://qemu-project.gitlab.io/qemu/devel/tracing.html目录TracingIntroductionQuickstartTrace eventsSub-directory setupUsing trace eventsDeclaring trace eventsHints for adding new trace eventsGeneric interface ahttps://rtoax.blog.csdn.net/article/details/120658697
目录
Counting events
Tracing events
Recording events
Recording events for a guest
Reporting events
Links
This page describes how to count and trace performance events in the KVM kernel module.
There are two tools, kvm_stat and kvm_trace, which were previously used for these tasks. Now this can be done using standard Linux tracing tools.
Counting events
Often you want event counts after running a benchmark:
$ sudo mount -t debugfs none /sys/kernel/debug $ sudo ./perf stat -e 'kvm:*' -a sleep 1h ^CPerformance counter stats for 'sleep 1h':8330 kvm:kvm_entry # 0.000 M/sec0 kvm:kvm_hypercall # 0.000 M/sec4060 kvm:kvm_pio # 0.000 M/sec0 kvm:kvm_cpuid # 0.000 M/sec2681 kvm:kvm_apic # 0.000 M/sec8343 kvm:kvm_exit # 0.000 M/sec737 kvm:kvm_inj_virq # 0.000 M/sec0 kvm:kvm_page_fault # 0.000 M/sec0 kvm:kvm_msr # 0.000 M/sec664 kvm:kvm_cr # 0.000 M/sec872 kvm:kvm_pic_set_irq # 0.000 M/sec0 kvm:kvm_apic_ipi # 0.000 M/sec738 kvm:kvm_apic_accept_irq # 0.000 M/sec874 kvm:kvm_set_irq # 0.000 M/sec874 kvm:kvm_ioapic_set_irq # 0.000 M/sec0 kvm:kvm_msi_set_irq # 0.000 M/sec433 kvm:kvm_ack_irq # 0.000 M/sec2685 kvm:kvm_mmio # 0.000 M/sec3.493562100 seconds time elapsed
The perf tool is part of the Linux kernel tree in tools/perf.
Tracing events
Detailed traces can be generated using ftrace:
# mount -t debugfs none /sys/kernel/debug # echo 1 >/sys/kernel/debug/tracing/events/kvm/enable # cat /sys/kernel/debug/tracing/trace_pipe [...]kvm-5664 [000] 11906.220178: kvm_entry: vcpu 0kvm-5664 [000] 11906.220181: kvm_exit: reason apic_access rip 0xc011518ckvm-5664 [000] 11906.220183: kvm_mmio: mmio write len 4 gpa 0xfee000b0 val 0x0kvm-5664 [000] 11906.220183: kvm_apic: apic_write APIC_EOI = 0x0kvm-5664 [000] 11906.220184: kvm_ack_irq: irqchip IOAPIC pin 11kvm-5664 [000] 11906.220185: kvm_entry: vcpu 0kvm-5664 [000] 11906.220188: kvm_exit: reason io_instruction rip 0xc01e4473kvm-5664 [000] 11906.220188: kvm_pio: pio_read at 0xc13e size 2 count 1kvm-5664 [000] 11906.220193: kvm_entry: vcpu 0 ^D # echo 0 >/sys/kernel/debug/tracing/events/kvm/enable
Recording events
Events can be recorded to a file for later reporting and analysis. You can record events for the host using the --host option. You can record events for a guest using the --guest option. You can use both options at the same time to record events for both the host and a guest.
If you use just the --host option the default output file will be perf.data.host. If you use just the --guest option the default output file will be perf.data.guest. If you use both options the default output file will be perf.data.kvm. Use the -o option after the record key word to save the output to a different file name.
# perf kvm --host --guest [kvm options] record -a -o my.perf.data
Recording events for a guest
Using copies of guest files
In order to record events for a guest, the perf tool needs the /proc/kallsyms and /proc/modules for the guest. These are passed to perf with the --guestkallsyms and --guestmodules options. The files will have to be on the host, but you can get them easily using ssh.
# ssh guest "cat /proc/kallsyms" > /tmp/guest.kallsyms # ssh guest "cat /proc/modules" > /tmp/guest.modules
It is better to use ssh to cat the files and redirect the output than to use scp. Experience has shown that scp guest:/proc/kallsyms /tmp/guest.kallsyms will return an empty file.
Using these options you can record the events for a host and a guest with the following command
# perf kvm --host --guest --guestkallsyms=/tmp/guest.kallsyms --guestmodules=/tmp/guest.modules record -a
The order of the arguments is important. In general, the syntax for using perf to profile kvm is: perf kvm <perf kvm args> <perf command> <perf command args> In this case the perf kvm arguments are --host --guest --guestkallsyms=/tmp/guest.kallsyms --guestmodules=/tmp/guest.modules, the perf command is record, and the perf command argument is -a (profile all processes).
perf will record events until it is terminated with SIGINT. It must be SIGINT. If perf is terminated with any other signal, such as SIGTERM or SIGQUIT, the pref kvm report command (see below) won't correctly process the file generated. It will just list the headers with no data.
Using sshfs
perf kvm has a way of getting the guest's kallsyms and modules by itself instead of you hving to provide them. It makes use of sshfs to mount the root file system of the guest so that it can get the files directly from the guest.
sshfs depends on fuse, the Filesystem in Userspace. If your Linux distribution does not have fuse, see the fuse project page on SourceForge. If your Linux distribution does not have sshfs, see the sshfs project page on SourceForge.
Here's how it works. You create a directory, e.g., /tmp/guestmount. You then create a subdirectory that has for its name the PID of the qemu process for the guest. Then you use sshfs to mount the guest's root file system on that subdirectory. For example:
# mkdir -p /tmp/guestmount # ps -eo pid,cmd | grep qemu | grep -v grep 24764 /usr/libexec/qemu-kvm -M pc -m 4096 -smp 4 -name guest01 -boot c -drive file=/var/lib/libvirt/images/guest01.img ... # mkdir /tmp/guestmount/24764 # sshfs -o allow_other,direct_io guest:/ /tmp/guestmount/24764
Then, instead of using the --guestkallsyms and --guestmodules options, you use the --guestmount option.
# perf kvm --host --guest --guestmount=/tmp/guestmount
When you are finished recording, unmount the guest file system using fusermount.
# fusermount -u /tmp/guestmount/24764
Reporting events
Use the perf kvm report command to generate a report from a data file created by perf kvm record. To generate a report for the host, use the --host argument.
# perf kvm --host --guestmount=/tmp/guestmount report
To generate a report for the guest, use the --guest argument.
# perf kvm --guest --guestmount=/tmp/guestmount report
By default the perf report command will read perf.data.host for a host report and perf.data.guest for a guest report. Use the -i option if you want to use a different input file.
# perf kvm --host --guestmount=/tmp/guestmount report -i /tmp/perf.data.kvm
The perf report command sends its output to standard out. If you want the output to go to a file, redirect the output to a file. Don't use the -o option. Contrary to the help text, it does not work.
Links
- ftrace.txt
- events.txt
- tracepoint-analysis.txt
KVM Tracing, perf_events相关推荐
- Qemu Tracing
Tracing - QEMU documentationhttps://qemu-project.gitlab.io/qemu/devel/tracing.html KVM Tracing, perf ...
- kvm 监控内存,替换页表(linux版的win VT晶核)(这个整复杂了,不用小内核也可以实现,留着吧,主要记录了bootLoad的启动过程)
kvm 监控内存,替换页表等问题 一.如何利用kvm 监控整个linux系统 不过kvm似乎只能监控自己的虚拟机,自己的主机监控不了.那么,只能利用kvm重新启动linux内核.kvm启动可以简化为小 ...
- x86: perf_events内核初始化
perf属于硬件资源监控模块,通过PMU(Performance Monitor Unit)性能监控单元完成性能事件和硬件计数器的记录情况. Linux性能计数器的使用(perf_events)可 ...
- kvm虚拟机vnc配置
本文是通过vnc方式访问虚拟主机上的KVM虚拟机. 这里的通过vnc方式访问虚拟机不是在kvm虚拟机安装配置vnc服务器,通过虚拟主机的IP地址与端口进行访问,kvm虚拟化对vnc的支持相对来 ...
- [原创]KVM虚拟化管理平台的实现
KVM虚拟化管理平台的实现 源码链接:https://github.com/wsjhk/IaaS_admin.git 视频演示链接:https://v.youku.com/v_show/id_XMjg ...
- linux kvm虚拟化命令,Linux系统下kvm虚拟化(三)日常管理常用命令和配置说明
根据我们之前创建和一些操作可以知道,KVM虚拟机的管理主要是通过virsh命令对环境下kvm虚拟机进行管理,下边这里整理一些常用的配置说明以及如何进行日常管理维护. 1,查看KVM虚拟机配置文件 KV ...
- 虚拟机桌面linux系统,KVM - Linux下三大免费桌面虚拟机评测_Linux教程_Linux公社-Linux系统门户网站...
KVM KVM(基于内核的虚拟机)是一个x86 Linux全虚拟化解决方案,需要硬件支持虚拟化扩展(Intel VT 或AMD-V),它由一个载入时内核模块kvm.ko(提供核心虚拟化基础设施)和一个 ...
- kvm上添加万兆网卡_部署kvm(二)
6.管理KVM虚拟机 virsh list//查看 正在运行 virsh list --all//查看所有 id 名称 状态 centos7.3 running virsh start 名字 //启动 ...
- Path Tracing
Path Tracing 懒得翻译了,相信搞图形学的人都能看得懂,2333 Path Tracing is a rendering algorithm similar to ray tracing i ...
最新文章
- P1516 青蛙的约会 [exgcd]
- 【Win 10 应用开发】UI Composition 札记(二):基本构件
- java钩子函数(hook)以spring源码为例
- 24点游戏c语言源代码6,C语言解24点游戏程序
- 【贪心】失意(jzoj 2318)
- webpack那些事儿
- ueditor1_4_3-utf8-jsp 配置实现上传图片的功能
- 研究员使用新型CPU攻击技术 “SmashEx” 攻破 Intel SGX
- VMware虚拟机找不到USB设备该怎么办?
- 基础回顾:测井曲线划分油、气、水层
- OP-TEE 编译流程
- 书籍《Python股票量化交易从入门到实践》学习进阶路线
- 插上U盾计算机无法识别,U盾插入电脑后没反应,网上银行识别不了?
- (转)原子时代来临-Intel革命性Atom透析
- Python项目:学生管理系统(数据库)
- 央视《每周质量报告》:揭秘假宽带真相
- Excel统一添加前缀与后缀
- 雍正王朝里康熙临终予四爷言
- Linux自动备份压缩MySQL数据库的实用方法
- 数字华容道(C++)