This do not describe how to install oprofile. There are a few cotchas on installation: You must have APIC enabled to use performance counters. This is usually the default, but you may want to check this in your kernel configuration. You also need the oprofile module, this is part of the kernel config in Linux 2.6+, but must be compiled seperately for earlier kernels. Finally, some RedHat kernels does not work with the standard oprofile, so you must use the RedHat version of oprofile, or compile your own kernel.
So we configure thusly:
make distclean ./configure --compile-type=profile --enable-proc-opt [+your normal opts]
The "make distclean" clears out all your old binaries and the the configure sets the compile type approriately. You may not want the "--enable-proc-opt" if you plan on making a package for other CPUs. This only makes about a 10% difference in playback speed because MMX and CMOV are enabled for CPUs that support them regardless of this option.
Next, you compile and install MythTV as you normally would.
qmake; make -j2 -k su make install
opcontrol --deinit opcontrol --init
You also will want to tell the profiler whether to profile the kernel as well, if you want the kernel profiled, and assuming your compiled kernel is in /usr/src/linux, issue this command:
opcontrol --vmlinux=/usr/src/linux/vmlinux
opcontrol --no-vmlinux
Now all CPU's are not profiled the same way. In the days of olde, a sampling profiler would hook into the clock interupt and record the instuction pointer's location at the instant the interrupt was triggered. But the wall clock timer still ticks as often as it did when CPU's ran at 5 Mhz, and now they run almost a thousand times faster. Such a profile would now take a thousand times longer than it did in 1985.
So modern processors include explicit support for profiling. For, example the Pentium Pro has the INST_RETIRED counter, the Pentium 4 has the INSTR_RETIRED counter, the AMD64 has the RETIRED_INSNS counter, etc. For a full list see the OProfile documentation. You need to find a performance counter you can use for your CPU, after you've run "opcontrol --init" you can run the following command:
opcontrol --list-events
For an Intel Pentium 4, the following will work
opcontrol -e INSTR_RETIRED:6000:0x0f:0:1
This tells OProfile to schedule an interrupt on every 6000th instruction that finishes and matches the flag 0x0f. You could also count cycles when not in idle for the same type of measurements. The last two numbers tell OProfile it should not profile the kernel and should profile userspace, if you want to profile the kernel as well you need to replace the zero with a one.
It is possible to profile in oprofile the old fashioned way, by using the real-time-clock. But you must compile your Linux kernel WITHOUT RTC support, and run MythTV significantly longer to get enough samples for a good report.
opcontrol --image=/usr/local/bin/mythfrontend
Now you want to start MythTV as usual:
Then begin doing whatever you want to profile, then issue these commands:
opcontrol --reset ; opcontrol --start
After a few seconds/minutes your should have collected enough data. Then you want to issue the following commands:
opcontrol --shutdown opreport --merge tgid -l --image-path=/usr/local/bin > report.txt
Now you can peruse the report at your pleasure.
This should be enough to get you started with finding and fixing performance problems in MythTV, but there is more information available from the OProfile manual. This includes information on constructing callgraphs, producing an annotated versions of the code, and saving results.
1.5.5