I built oprofile 0.9.9 and it is working fine with my kernel (Linux sw0 2.6.34.6) when I loaded into my box directly.
But I did the same steps in virtual machine mode where oprofile starts, but no report is generated in sample directory. Do I need to do anything specific for kvm mode? Is it an issue with kernel module or oprofile user daemon?
opcontrol --deinit
opcontrol --init
opcontrol --vmlinux /root/vmlinux
opcontrol --separate=kernel
opcontrol --cpu-buffer-size=9000000
opcontrol --event=CPU_CLK:100000:0:1:1
opcontrol --callgraph=0
opcontrol --status
opcontrol --start
opcontrol --stop
opcontrol --dump
opreport -l -p /mymod/modules
Error
sw0:FID128:root> opreport -l -p /fabos/modules
Using /var/lib/oprofile/samples/ for samples directory.
error: no sample files found: profile specification too strict ?
sw0:FID128:root>
Sample directory structure (no {kern} and {root} directory)
sw0:FID128:root> pwd
/var/lib/oprofile/samples/current
sw0:FID128:root> ls
stats/
sw0:FID128:root>
Sample directory structure (working case)
sw0:FID128:root> pwd
/var/lib/oprofile/samples/current
sw0:FID128:root> ls
stats/ {kern}/ {root}/
sw0:FID128:root>
Whether oprofile works on a guest vm depends on the hosts support of performance monitoring hardware. With older kernels running on the host such as RHEL6 2.6.32 kernel the guest vms do not have access to the machine. Also the guest vm needs to be configured to have the same processor configuration as host machine. The performance monitoring hardware is very processor implementation specific and the default cpu types used for guest vm are going to present the wrong hardware.
Since you are running a 2.6.34 kernel you should be able to check to see if the performance hardware is working properly. For example on a Intel Ivy Bridge host machine running fedora 24 and rhel6 guest the "perf stat true" can be run to see if the performance monitoring hardware is working properly:
$ perf stat true
Performance counter stats for 'true':
If that doesn't work, then oprofile isn't going to work either.
Assuming that perf shows access is working then see whether oprofile is having the issue. On the same configuration as above:
[root@rhel664 tmp]# rpm -q oprofile
oprofile-0.9.9-13.el6.x86_64
[root@rhel664 tmp]# opcontrol --deinit
Unloading oprofile module
[root@rhel664 tmp]# opcontrol --init
[root@rhel664 tmp]# opcontrol --setup --vmlinux /usr/lib/debug/lib/modules/
uname -r
/vmlinux \You should look to see if there is something /var/log/messages about oprofile setup. If using performance monitoring hardware should see:
Aug 24 11:54:30 rhel664 kernel: oprofile: using NMI interrupt.
I do not have perf in my system. Same setup is working fine with normal setup whereas it does not work in VM mode. Is there anything I can do with VM to eliminate this difference? Do I need to confiure anything to make it working?
You haven't stated what distribution the host system is running. That would decide whether the performance monitoring hardware is usable within a guest machine.
If the host is rhel6, the performance monitoring won't work in the guest because of the older kernels.
If the host is rhel7 or newer versions of Fedora you can use the performance monitoring hardware inside the guest. However, you will need to make the guest machine use the same cpuid information as the hostl. This can be set up using the information in section 3.3.2 of https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/6/html-single/Virtualization_Tuning_and_Optimization_Guide/index.html
Installing perf is pretty trivial with root permission with:
yum install perf
HOSTOS where VM runs in ubuntu
HOST OS
PRETTY_NAME="Ubuntu 14.04 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"
root@HOST:~# uname -a
Linux HOST 3.14.17 #0 SMP Tue Sep 20 19:56:09 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
root@HOST:~#
VM
It is customized distribution (kind of redhat model).
sw0:FID128:root> uname -a
Linux sw0 2.6.34.6 #1 SMP Tue Sep 20 16:50:05 UTC 2016 i686 GNU/Linux
sw0:FID128:root>