Performance Tuning for Linux Servers
|
| OProfile is a system-wide tracing tool that is available for the Intel, Power PC, AMD, sparc64, and PA-RISC platforms. The OProfile tool works off of the system timer support or the performance counter support, if available. OProfile is a useful tool for obtaining a profile of a running system. This profile shows the amount of time being spent in an application and the number of times an application was running when OProfile made its measurement. It also gives information by application and library symbols. The most unique function of OProfile is that it provides a report that shows the source code for an application with the number of measurements made for each line of code in the application. This function applies to C code and is very useful to determine where in an application to concentrate the tuning efforts. OProfile is now shipped as part of some Red Hat distributions and is available from other Linux operating system providers. Note that the OProfile web site contains a disclaimer that they are not responsible for the version that ships with Red Hat. Some versions of Red Hat require that SMP support be enabled in the kernel configuration and that the OProfile driver must be built as a loadable module and not built into the kernel. If it's built into the kernel, duplicate function name errors occur. One other item to note is that on the version that is downloaded from the OProfile development web site, you must run the autosetup.sh command as the first step. This is not always clear in the documentation. It is best to use the OProfile patch on kernel source that is obtained from the www.kernel.org web site. This patch ensures that all the required support is included in the kernel source. If you use a specific vendor version of the kernel source, you might not have the latest patches. As vendors upgrade their kernel source to newer versions of the Linux kernel, the patches will be included. Refer to the OProfile web site at http://oprofile.sourceforge.net/ for detailed information on the tool and to download a copy. The next sections examine the various parts of OProfile, including opcontrol, oprof_start, oprofpp, op_time, op_to_source, and op_merge. opcontrol
opcontrol initializes the OProfile tool and starts and stops the data collection. The specific command options available with opcontrol are as follows:
Refer to the OProfile documentation for further information. The following examples show the initialization and starting of the OProfile functions for counter support, creating separate profiles for libraries and the kernel, and saving session data. Using the Counter Support
The following command initializes OProfile to start counter 0 to use the CPU clock not-halted event and to make the measurement after every 400,000 counter events. Performance counter 1 is set to data memory references, and the measurement is made after every 10,000 events. The Linux kernel executable file is located at /usr/src/Linux and is called vmlinux. After the initialization, the measurement is started. opcontrol --ctr0-event=CPU_CLK_UNHALTED --ctr0-count=400000 opcontrol --ctr1-event=DATA_MEM_REFS --ctr1-count=10000 opcontrol --vmlinux=/usr/src/Linux/vmlinux opcontrol --start
When using performance counters, ensure that the count values are large enough to prevent all the time from being spent in processing the performance counter handler. If the counter count value is too low, it is possible that the system will stop functioning and require a reboot. The performance counters are set up to interrupt when a counter overflow occurs. Therefore, if the count is too low, the time will be spent processing the counter overflow interrupt and nothing else. Separate Profiles for Libraries and the Kernel
opcontrol --separate=kernel --vmlinux=/usr/src/Linux/vmlinux opcontrol --start my_test --run pprofpp -kl -p /lib/modules/Linux/kernel /usr/local/bin/oprofiled
These commands profile the OProfile daemon itself, including when the daemon was running inside the kernel driver and the libraries it is using. Saving Session Data
The following command saves the profiling data that has been collected in a file called /var/lib/oprofile/samples/run1. This name can then be passed on to the reporting functions to be processed. opcontrol --save=run1 oprof_start
oprof_start is a GUI interface for opcontrol. oprof_start contains window sections where you can select counter events and a sampling rate, configuration options, and the status of the profiling. Data Profiling Tools
The following sections describe the tools that profile the sample data OProfile collects. These tools are oprofpp, op_time, op_to_source, and op_merge. oprofpp
oprofpp produces the following types of reports:
Some of the more interesting options that can be used to control the report output are as follows:
The following sample listing shows the counts and time by kernel symbols. [View full width] # oprofpp l Cpu type: PIII Cpu speed was (MHz estimation) : 863.886 Counter 0 counted CPU_CLK_UNHALTED events (clocks processor is not halted) with a unit
op_time
op_time produces summary reports relative to the binaries that are running on the system. Use this report to find out where time is being spent when your test case is running. You can then use other reports to narrow your focus to specific functions and code segments within the application to see where the problem may exist. Many of the same options that are available for oprofpp are also available for op_time. The following sample report uses the -D option. # op_time -D 1 0.0043 0.0000 /lib/libhistory.so.4.3 1 0.0043 0.0000 /opt/kde3/lib/kwin.so 1 0.0043 0.0000 /opt/kde3/lib/libartsflow.so.1.0.0 1 0.0043 0.0000 /usr/X11R6/lib/X11/locale/lib/common/ximcp.so.2 1 0.0043 0.0000 /usr/lib/vslick/bin/vs 2 0.0087 0.0000 /bin/gawk 2 0.0087 0.0000 /lib/modules/2.4.19-4GB/kernel/drivers/usb/usb-uhci.o 2 0.0087 0.0000 /opt/kde3/lib/libartsmidi.so.0.0.0 3 0.0130 0.0000 /bin/ps 3 0.0130 0.0000 /lib/modules/2.4.19-4GB/oprofile/oprofile.o 4 0.0173 0.0000 /lib/libreadline.so.4.3 4 0.0173 0.0000 /opt/kde3/lib/libkdecore.so.4.0.0 5 0.0216 0.0000 /opt/kde3/lib/libmcop.so.1.0.0 5 0.0216 0.0000 /usr/local/bin/op_help 16 0.0692 0.0000 /usr/X11R6/lib/libX11.so.6.2 16 0.0692 0.0000 /usr/lib/gconv/ISO8859-1.so 19 0.0822 0.0000 /lib/libpthread.so.0 20 0.0865 0.0000 /opt/kde3/lib/libkio.so.4.0.0 25 0.1082 0.0000 /usr/lib/libstdc++.so.5.0.0 26 0.1125 0.0000 /usr/X11R6/bin/XFree86 33 0.1428 0.0000 /opt/kde3/lib/libkonsolepart.so 45 0.1947 0.0000 /bin/bash 59 0.2553 0.0000 /sbin/insmod 68 0.2942 0.0000 /lib/ld-2.2.5.so 163 0.7052 0.0000 /lib/modules/2.4.19-4GB/kernel/fs/reiserfs/reiserfs.o 297 1.2849 0.0000 /lib/libc.so.6 308 1.3325 0.0000 /usr/lib/qt-3.0.5/lib/libqt-mt.so.3.0.5 661 2.8597 0.0000 /usr/src/Linux/vmlinux 3950 17.0892 0.0000 /usr/local/bin/oprofiled 17373 75.1622 0.0000 /piperf/bin/pi_watch op_to_source
The op_to_source tool generates annotated source for assembly listings. If the profiled application is built with debug information, a report contains the actual source code with the profiled counts interleaved. If the application is built without the debug information, op_to_source can produce the assembler report. Use the --assembly (-a) option to produce this type of report. The op_to_source level of reporting is one step above an application debugger that allows you to step through your application to check the execution logic. op_to_source provides you with the information necessary to determine where in the application you need to focus the debugging effort. The following is sample output from op_to_source for a sample program. [View full width] # op_to_source :/* * IBM Performance Inspector * Copyright (c) International Business Machines Corp., 2003 * * This library is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published * by the Free Software Foundation; either version 2.1 of the License, or * (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ : #include <stdio.h> #include <stdlib.h> #include <unistd.h> int One(unsigned long long cps); int Two(unsigned long long cps); int Four(unsigned long long cps); int Eight(unsigned long long cps); int Sixteen(unsigned long long cps); int ThirtyTwo(unsigned long long cps); int SixtyFour(unsigned long long cps); int val = 0; /************************************/ 10 0.003% 580 0.000% :void pc50() { /* pc50 total: 153902 52.31% 40667094 52.46% */ : int i; : 119226 40.52% 29583773 38.16% : for(i = 0; i < 5000; i++) { 34613 11.76% 11071427 14.28% : val = val + i; : } 53 0.018% 11314 0.014% :} : :/************************************/ 8 0.002% 290 0.000% :void pc25() { /* pc25 total: 70463 23.95% 18765427 24.20% */ : int i; : 60711 20.63% 16897936 21.79% : for(i = 0; i < 2500; i++) { 9693 3.295% 1851007 2.387% : val = val + i; : } 51 0.017% 16194 0.020% :} : :/************************************/ 13 0.004% 5455 0.007% :void pc15() { /* pc15 total: 43572 14.81% 11245713 14.50% */ : int i; : 39415 13.39% 11069245 14.27% : for(i = 0; i < 1500; i++) { 4046 1.375% 136253 0.175% : val = val + i; : } 98 0.033% 34760 0.044% :} : :/************************************/ 9 0.003% 116 0.000% :void pc10() { /* pc10 total: 26148 8.888% 6818423 8.795% */ : int i; : 20936 7.116% 5433262 7.008% : for(i = 0; i < 1000; i++) { 5154 1.752% 1365913 1.762% : val = val + i; : } 49 0.016% 19132 0.024% :} : :/************************************/ :int main(int argc, char *argv[]) { /* main total: 84op_merge
op_merge merges profiling samples created with the --separate option when applied to the same binary. op_merge can produce reports for separate shared libraries and then merge the reports for a complete system view. You can also produce reports on a combination of a subset of profiled applications. |
|