1. By default, xen kernel may not be enabled for profiling. So before installation, compile the kernel with profiling option enabled.

2. Once you are booted with the new kernel, install oprofile using the command (if you are using ubuntu version of linux)

     $ apt-get install oprofile
  

3. If you want to install oprofile from the sources, perform these folloeing steps:

   $ tar –zxvf oprofile-0.9.3.tar.gz
   $ cd oprofile-0.9.3
   $ patch –p1 < ../oprofile-0.9.3-xen-rc2.patch
   $ ./configure –with-kernel-support
   $ make
   $ make install

4. Type the command opcontrol –help. If successful the command should list –xen as a valid option.

5. Installing Oprofile tool in virtual machines:

 
 * Dump the disk image of the VM under /mnt/
 * execute chroot /mnt/ /bin/bash
 * then type apt-get install oprofile.
 * Remember to copy the linux image and kernel image from Dom0 to /boot/ directory of Dom1. Also the events should be the same for virtual machine and dom0. 

6. Active profiling in Virtual Machines. Imagine that you have dom1 and dom2 running along with dom0. Reset the machines.

  dom0> opcontrol --reset
  dom1> opcontrol --reset
  dom2> opcontrol --reset

7. Pass Parameters in Dom0

dom0> opcontrol --start-daemon --event=GLOBAL_POWER_EVENTS:1000000 --xen=/boot/xen-syms-3.0-unstable –vmlinux=/boot/vmlinux-syms-2.6.16.13-xen0 --active-domains=1,2
  --event specifies the activity you want to measure with oprofile.
  --xen specifies the xen image
  --vmlinux specifies the runnig kernel image in Dom0.
  --active-domains options asks for the list of dom ids for the target VMs

8. Start profiling in DomUs. You need to specify the same events across all the domains.

  dom1> opcontrol --start --event=GLOBAL_POWER_EVENT:1000000 --xen=/boot/xen-syms-3.0-unstable --vmlinux=/boot/vmlinux-syms-2.6.16.13-xenU
  dom2> opcontrol --start --event=GLOBAL_POWER_EVENT:1000000 --xen=/boot/xen-syms-3.0-unstable --vmlinux=/boot/vmlinux-syms-2.6.16.13-xenU

9. Start Profiling in Dom0

  dom0> opcontrol --start

10. Run the Benchmark 11. Shutdown oprofile

  dom0> opcontrol --shutdown
  dom1> opcontrol --shutdown
  dom2> opcontrol --shutdown

12. To get the statistics you need to perform opreport -l in each domain.

13. To get the symbols for kernel modules that are inserted dynamically, you need to specify the directory path under which the module files are located. Remember to export your functions with the EXPORT_SYMBOL(function_name) command in the code source file.

   opreport -l -p /home/xprime (If your modules are located under /home/xprime/)

14. The details about oprofile can be found in the following link: http://oprofile.sourceforge.net/doc/index.html