Oprofile performance analysis tools on Linux platforms __linux

Source: Internet
Author: User
Tags image filter

http://blog.csdn.net/wlsfling/article/details/5876134

Content Overview

1.oprofile Introduction

2.oprofile Installation and Linux kernel compilation

3.oprofile use

First, Oprofile Introduction

Oprofile is a powerful performance analysis tool on the Linux platform similar to the INTEL VTune. It supports two types of sampling (sampling) modes: event-based sampling (event based) and time based sampling.

Event-based sampling is the number of occurrences of a specific event (such as L2 cache miss) that is recorded by Oprofile, and the Oprofile is recorded when the user's set value is reached. This approach requires a performance counter (performace counter) inside the CPU. Modern CPU generally has performance counters;

Time based sampling is the mechanism by which oprofile interrupts with OS clocks, and each clock interrupt oprofile is recorded once (sampling). The purpose of the introduction is to provide support for CPUs that do not have performance counters. The precision is lower than the event-based sampling. Because of the support for OS clock interrupts, code oprofile that disables interrupts cannot be parsed.

Oprofile is divided into two parts on Linux, one is the kernel module (Oprofile.ko), the other is a daemon for user space (oprofiled). The former is responsible for accessing performance counters or registering functions based on time sampling (using Register_timer_hook registration so that the clock interrupt handler can be accessed at the end of the Profile_tick), and sampling is placed in the buffer area of the kernel. The latter runs in the background and is responsible for collecting data from kernel space and writing to files.

Second, oprofile installation and Linux kernel compilation

I. Oprofile Installation

Oprofile is included in the Linux 2.6 version of the kernel and is one of several metrics and performance monitoring tools for Linux.

can also download the source from the official website to compile and install the installation steps:

1./configure--with-kernel-support

Note: During the compilation process, the problems that arise during this step are: (1) lack of libiberty.h header files; (2) lack of popt;

Libiberty.h header file in Binutils-devel package, you need to download the package to install it; also through the new Ned

For installation. You can use the sudo apt-get install Binutil-dev for package installation.

Popt exist in Libpopt-devel package, the same need to download and install;

sudo apt-get install libpopt-dev;

2. Make

3. Make install

The following toolset is generated when the Oprofile installation is complete:

/usr/bin/oprofiled Daemon Process
/usr/bin/opcontrol Control front-end, responsible for control and user interaction, use the most
/usr/bin/opannotate, based on the data collected, is annotated and presented to the user at the source or assembly level.
Overview of/usr/bin/opreport generating binary mirrors or symbols
/USR/BIN/OPHELP list events supported by Oprofile
/USR/BIN/OPGPROF profiling data generated in GPROF format

Opstack: Generates call Graph profile, but requires x86/2.6 platform, and linux2.6 installed Call-graph patch

Oparchive: Pack All the raw data files, and then analyze them on another machine.
Op_import: Converts the sampled database file from another ABI to a local format.

Running oprofile requires root permission because it loads the profile module, starts the oprofiled daemon, and so on. So before you run, you need to switch to root.

II. Linux Kernel Compilation

Because Oprofile is a tool for evaluating and monitoring the kernel, kernel support is required. But in Ubuntu

The following does not have the kernel source code, so need to download the corresponding version of the kernel source code, to compile and install;

The steps for compiling the new kernel are as follows:

(1) The downloaded kernel is placed in the/USR/SRC directory; decompression: TAR-JXVF linux-source-2.6.27.tar.bz2;

(2) next to the kernel configuration: Make Menuconfig (or made xconfig), I choose to use this command;

In the configuration process, the local version-append to kernel release in general setup can be

Customize your favorite kernel name; Load an alternate Configuration File this option can refer to the

The configuration file, save an alternate Configuration file is to save the reconfigured. config files.

Before you configure it, you can use the following command to clear it.

Make clean: the previously compiled files can be purged;

Make Mrproper: You can clear the previous configuration file, the novice is not recommended, preferably the previous. config file configuration.

The. config file is taken from the kernel source./usr/src/linux-source-2.6.27/arch/x86/configs

The config file of the face and then according to the options in Menuconfig to get the final config file.

(3) make for kernel compilation

After compiling, several important files are generated in the/boot directory; vmlinuz-2.6.27, System.map, etc.;

Where the config file is generated in the/linux-source-2.6.27 directory, it needs to be copied below the/boot directory.

(4) The module selected in the Make Modules_install installation configuration.

(5) Make install

(6) Check whether to generate INITRD image files, under the Ubuntu did not generate, you need to use the command under/boot:

Mkinitramfs-o initrd.img.2.6.27.18 generates a mirrored file.

(7) Edit the Menu.lst file under/boot/grub and add the new kernel information according to the format; only the new kernel

Added, the system is booted before it is booted into the new kernel.

If the configuration meets system requirements, you can compile a new kernel in this order.

Iii. Use of Oprofile

Oprofile to be used under root permissions:

A. Initialization

Opcontrol--init

The command loads the Oprofile.ko module, and the Mount Oprofilefs succeeds with the/dev/oprofile/directory exporting a

Some files and directories such as: CPU_type, dump, enable, pointer_size, stats.

B. Configuration

1. First, configure whether OProfile should monitor the kernel. This is the configuration option required before starting OProfile.

and the setting of counting event and sample count, the CPU mode of counting (user state, kernel mentality) is the system default;

If Oprofile monitors the kernel itself:

Opcontrol–vmlinux=/src/urc/linux-source-2.6.27/vmlinux

If Oprofile does not monitor the evaluation kernel:

Opcontrol--no-vmlinux.

The default configuration in this architecture family10h is:

opcontrol–event=cpu_clk_unhalted:100000

If you configure how the daemon writes to the file, use the command:

Opcontrol--separate=<choice>

<choice> can be one of the following:

none-do not separate files (default)

library-generates files for each application for the library

kernel-generates files for each application for kernel and kernel modules

all-generates files for each application for the library, and generates files for each application for kernel and kernel modules

Note the problem:

(1) Oprofile can be set up in this event;

You can view the events supported in this structure through the Opcontrol--list-events command;

Through Opcontrol--event=l2_cache_miss:500--event=l1_dtlb_miss_and_l2_dtlb_hit:500

--event= ..... command to set the event;

This command--event parameter must be given in turn, no matter how many, not branch, remember.

You can view the events that you have configured by using the Opcontrol–status command;

(2) For each test process, if you need to reset the event, you must restart the daemon, it is

A daemon process. That is, when the data is collected, the--shutdown command is used to stop the daemon, not

--stop (This command simply stops profiling) so that the-start command can be used again to use the new event settings;

(3) Once the evaluation is over, the old profiling data still exists, with-reset or-save commands to clean up or

Save data;

C. Launch

Opcontrol--start

D. Running the procedure to be analysed

Gcc-o WLS wls.c; wls.o file generation;/wls

E. Fetching data

Opcontrol–dump

Data is written into the/var/lib/oprofile/samples/oprofiled.log

F. Stop profiling

Opcontrol--stop

G. Use of opreport analysis results

Opreport-l./wls

Based on the set of events for evaluation, the results of the evaluation of one by one display.

H. Using opannotate Analysis results

If the source analysis, you can use the Opannotate tool to achieve

Compiling: gcc-g wls.c-o WLS

Analysis: Opannotate--source./wls

To sum up:

1. Opcontrol–init loading module, mout/dev/oprofile create necessary files and directories

2. Opcontrol--no-vmlinux or Opcontrol--vmlinux=/boot/vmlinux-' uname-r ' determines whether kernel is profiling

3. Opcontrol--reset Clear the data in the current session

4. Opcontrol--start began profiling

5./wls runs the application, oprofile it profiling

6. Opcontrol--dump writes the collected data to the file

7. Opcontrol--stop Stop Profiling

8. opcotrol-h Shutdown Daemon oprofiled

9. Opcontrol--shutdown Stop oprofiled

Opcontrol--deinit Uninstall Module

Commonly used is the 3→7 these several processes, obtains the performance data, may use Opreport, Opstack, Opgprof, opannotate

Several tools for analysis, I commonly used is opreport, opannotate analysis.

Iv. Example Demo

The following is an example of the decoding source of AMR to analyze the performance of the code.

First, compile the code that is about to be parsed:

(1) Compile the source code library file:

Executes the make command under the directory/home/wls/application software/amrenginec_oki_source/amrdecengine;

Build file: Libamrdecengine.a This file as an archive library file.

(2) Compile the source code main file:

Executes the make command under the directory/home/wls/application software/amrenginec_oki_source/testamrdec/win32;

Build file: Testamr This file is an executable file.

Copy Testamr to the upper directory: CP Testamr.

Execute command:./TESTAMR amrdec.par Generation Testamrdec.wav

Second, execute the oprofile command and set it accordingly:

root@wls-desktop:~/testamrdec# Opcontrol--init

root@wls-desktop:~/testamrdec# Opcontrol--no-vmlinux

root@wls-desktop:~/testamrdec# Opcontrol--event= cpu_clk_unhalted:5000

--event=data_cache_misses:1000--event=instruction_cache_misses:1000

--event=memory_requests:1000

root@wls-desktop:~/testamrdec# Opcontrol--status

Daemon Running:pid 14979

Event 0:cpu_clk_unhalted:5000:0:1:1

Event 1:data_cache_misses:1000:0:1:1

Event 2:instruction_cache_misses:1000:0:1:1

Event 3:memory_requests:1000:131:1:1

Separate Options:none

Vmlinux File:none

Image Filter:none

Call-graph depth:0

Root@wls-desktop:~/testamrdec# Opcontrol–start

Using 2.6+ OProfile Kernel interface.

Reading Module INFO.

Using Log File/var/lib/oprofile/samples/oprofiled.log

Daemon started.

Profiler running.

root@wls-desktop:~/testamrdec#./testamr Amrdec.par

===================================================

Audio Length [msec]: 10020

Audio Frames [frame]: 501

Audio Packets [Packet]: 501

Decoded Bytes [byte]: 7014

Average bitrate [Kbps]: 5.600

decoding time [msec]: + (250.500 times)

===================================================

root@wls-desktop:~/testamrdec# Opcontrol--dump

root@wls-desktop:~/testamrdec# Opcontrol--stop

stopping profiling.

root@wls-desktop:~/testamrdec# opreport-l./testamr

Data analysis results are as follows:

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.