Gprof and oprofiling performance testing tools in Linux, gprofoprofiling

Source: Internet
Author: User

Gprof and oprofiling performance testing tools in Linux, gprofoprofiling

I. Introduction

Sometimes, we pay special attention to program performance, especially the underlying software, such as drivers and OS. In order to better optimize the program performance, we must find the performance bottleneck. "Good steel is used on the blade" to achieve good results. Otherwise, we may do the work in vain. To find the key path, we can use profilng technology. On the linux platform, we can use gprof and oprofile tools.

 

Gprof is one of the GNU tools. during compilation, it adds profiling code to the entrances and exits of each function. during runtime, the statistics program executes information in the user State, you can obtain the number of calls, execution time, call relationship, and other information of each function, which is easy to understand. It is suitable for finding the performance bottleneck of user-level programs. gprof is not suitable for the procedures that are executed in kernel state for many times.

OProfile is a powerful performance analysis tool on the Linux platform. It supports two sampling methods: Event-based sampling and time-based sampling ), it can work on different architectures, including MIPS, ARM, IA32, IA64, and AMD.

Refer:

http://blog.chinaunix.net/uid-21768364-id-186057.html http://blog.csdn.net/cybertan/article/details/8015611 http://www.cnblogs.com/bangerlee/archive/2012/08/30/2659435.html

Ii. gprof usage

Gprof is one of the gnu binutils tools. It is included in linux by default.

Use the-pg option to compile hello. c. If you want to get the source code list with annotations, you need to add the-g option. Run: gcc-pg-g-o hello. c
Run the application:./hello will generate the gmon. out file in the current directory. When you use gprof to analyze the gmon. out file, you need to associate it with the application that generates it:

Gprof hello gmon. out-p gets the execution time occupied by each function gprof hello gmon. get the call graph from out-q, including the call relationship, number of calls, and execution time of each function. Gprof hello gmon. out-A gets A "Source code list" with comments, which comments the source code and indicates the number of times each function is executed. This requires the-g option to be added during compilation.

3. oprofile Installation Steps

1. Enable the kernel OPROFILE option. Otherwise, the following message is displayed when you run the oProfile:

[root@localhost oprofile-0.9.6]# opcontrol --init FATAL: Module oprofile not found. FATAL: Module oprofile not found. Kernel doesn't support oprofile
2. Edit the Kernel configuration file:. config and change # CONFIG_OPROFILE is not set to CONFIG_OPROFILE = m (or y)
[root@localhost ~]# cd /usr/src/linux-2.6.37.2 [root@localhost linux-2.6.37.2]# vi .config

As follows:

CONFIG_PROFILING=y CONFIG_X86_LOCAL_APIC=y CONFIG_X86_IO_APIC=y CONFIG_PCI_IOAPIC=y

3. Compile the kernel and restart the machine.

4. Download the source code, compile and install it

wget http://cznic.dl.sourceforge.net/project/oprofile/oprofile/oprofile-1.0.0/oprofile-1.0.0.tar.gztar -zxvf oprofile-1.0.0.tar.gzcd oprofile-1.0.0./configuremakemake install

 

Iv. oprofile tool set

Op_help: lists all supported events. Opcontrol: Set the events to be collected. Opreport: outputs statistical results. Opannaotate: generates source/assembly files with annotations. Source Language-level annotations must be supported when source files are compiled. Opstack: generate the call graph profile, but the x86/2.6 platform is required, and the call-graph patchopgprof is installed in linux2.6: generate results similar to gprof. Oparchive: Collects and packages all raw data files and analyzes them on another machine. Op_import: converts the sampled database files from another abi to the local cost format.

 

V. oprofile usage

Test File: multiply. c

#include <stdio.h> int fast_multiply(x,  y) {     return x * y; }   int slow_multiply(x, y) {     int i, j, z;     for (i = 0, z = 0; i < x; i++)         z = z + y;     return z; }   int main(int argc, char *argv[]) {     int i,j;     int x,y;     for (i = 0; i < 200; i ++) {         for (j = 0; j <  30 ; j++) {             x = fast_multiply(i, j);             y = slow_multiply(i, j);         }     }     printf("x=%d, y=%d\n", x, y);     return 0; }

Compile

gcc multiply.c -g -o multiply

Test

modprobe oprofile timer=1 
opcontrol --no-vmlinux
opcontrol --separate=kernel
opcontrol --init opcontrol --reset opcontrol --start./multiplyopcontrol --dumpopcontrol --stopopcontrol --shutdownopcontrol --deinitopannotate --source ./multiply
opreport -l ./multiply
opreport

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.