Time profiling and memory leaks consumed by each function valgrind

Source: Internet
Author: User
Tags add time unpack valgrind

Source: Http://06110120wxc.blog.163.com/blog/static/37788161201333112445844/ARM (hisi) installation of profiling and Valgrind above

Use of profiling

The GNU gprof can print out the elapsed time of each function in the program, helping the programmer to find the most time-consuming functions in many functions. Generating a function call relationship at runtime, including the number of calls, can help the programmer to analyze the program's running flow. With the invocation of a function, this will greatly increase the productivity of the developer.

Basic usage of gprof:

1. Use the -pg option to compile and link your application, plus in makefile.

2. Execute your application to generate data for gprof analysis, run the executable program:./V2VAPP_M_V2V, which generates a gmon.out file that contains the profiling data.

Note: after the program runs and "normal" exits, a gmon.out file is generated. In other words, the program must be terminated from exit or return .

For example: In our project, can be in Session.cpp in the session_run inside to add restrictions, such as to see the 100S function usage: add gettimeofday (&pro_num_old,null); (1) Front;

Gettimeofday (&pro_num_new,null); in while (1). Then the following

if ((pro_num_new.tv_sec-pro_num_old.tv_sec) > 100)

{

printf ("new =%d, old =%d\n", pro_num_new.tv_sec, pro_num_old.tv_sec);

Break

}

3. Analyze Build Results

Gprof [Options] < executables > <profiler data file>.

such as: Gprof v2vapp_m_v2v gmon.out > Profile.txt

Report:

Information generated by gprof
% The percentage of the total running time of the

Time program used by the This function.

function usage time as a percentage of all time.

Cumulative a running sum of the number of seconds accounted

seconds for by this function and those listed above it.

The time that the function and the above functions accumulate execution.

Self the number of seconds accounted

seconds function alone. The major sort for this
Listing.
The time that the function itself executes.
Calls the number of times this function is invoked, if
This function is profiled, else blank.
Number of times the function was called
Self the average number of milliseconds spent in this
Ms/call function per call, if the function is profiled,
else blank.
Each call is spent at the time of the function microseconds.
Total the average number of milliseconds spent in this
Ms/call function and its descendents per call, if this
function is profiled, else blank.
Each call is spent on the average time of the function and its derived function microseconds.
Name the function of the name. This is the minor sort
For this listing. The index shows the location of
The function in the GPROF listing. If the index is
In parenthesis it shows where it would appear in
The GPROF listing if it were to be printed.
Name of function

Use of Valgrind

What can valgrind do?

? Memory usage detection, including:

– Memory leaks

– Illegal memory access

– Uninitialized use of variables

– Repeatedly freeing memory

? multi-Threaded competition

– Detect Deadlocks

-Detect Competition

What else can valgrind do?

? Performance analysis

–cachegrind+ cg_annotate

It simulates the first-level cache i1,d1 and L2 level two caches in the CPU, and is able to pinpoint the loss and hit of the cache in the program. If needed, it can also provide us with cache loss times, memory references, and each line of code, each function, each module, the total number of instructions generated by the program, which could be seen as the execution cost of the program. The above data in fact for app development is not very meaningful, only as a reference.

How to use:

–callgrind+ Callgrind_annotate/kcachegrind

Callgrind is more useful than cachegrind. Callgrind is implemented on a cachegrind basis to visualize function call relationships and the cost of each function as it runs through the process. For

? Helgrind/drd

–POSIXAPI Misuse

– Potential deadlock Reminders

– Data Competition

? Massif

– Memory analysis tool that counts the memory used by the process, including heap, stack

Valgrind--memcheck

Usage: Valgrind--tool=memcheck--leak-check=yes./grog

Output:

The Memcheck tool mainly checks for the following program errors:

Using uninitialized memory (use of uninitialised memories)

Use memory that has been freed (reading/writing memories after it have been free ' d)

Use over malloc allocated memory space (reading/writing off the end of malloc ' d blocks)

Illegal access to stacks (reading/writing inappropriate areas on the stack)

Whether the requested space has been released (Memory leaks–where pointers to malloc ' d blocks is lost forever)

Malloc/free/new/delete

Application and release memory matching (mismatched use of malloc/new/new [] vs Free/delete/delete [])

SRC and DST overlap (overlapping src and DST pointers in memcpy () and related functions)

Callgrind

Callgrind collects some data from the program runtime, functions call relationships and other information, and can optionally perform the cache simulation. At the end of the run, it writes the parsing data to a file. Callgrind_annotate can convert the contents of this file into a readable form.

Cachegrind

It simulates the first-level cache i1,d1 and L2 level two caches in the CPU, and is able to pinpoint the loss and hit of the cache in the program. It can also provide us with the number of cache misses, memory references, and each line of code, each function, each module, and the entire program, if needed. This is a great help in optimizing the program.

Helgrind

It is primarily used to check for competition issues that occur in multithreaded programs. Helgrind looks for areas in memory that are accessed by multiple threads without a consistent lock, which are often places where threads are out of sync and can cause hard-to-dig errors. Helgrind implements a competitive detection algorithm called "Eraser", and makes further improvements to reduce the number of reported errors.

Massif

The stack analyzer, which measures how much memory the program uses in the stack, tells us the size of heap blocks, heap management blocks, and stacks. Massif can help us reduce memory usage, and in modern systems with virtual memory, it can also speed up the operation of our programs and reduce the chances of the program staying in the swap area.

Valgrind installation 1, to www.valgrind.org download the latest version valgrind-3.2.3.tar.bz2
2, unpack the installation package: TAR–JXVF valgrind-3.2.3.tar.bz2
3. Create directory after decompression valgrind-3.2.3
4. CD valgrind-3.2.3
5,./configure
6, Make;make Installvalgrind use

Usage: valgrind [options] Prog-and-args [options]: Common options for all Valgrind tools

-tool=<name> the most common options. Run the tool named ToolName in Valgrind. Default Memcheck.

H–HELP Displays help information.

-version Displays the version of the Valgrind kernel, with each tool having its own version.

Q–quiet runs silently, printing only error messages.

V–verbose more detailed information, increase the number of error statistics.

-trace-children=no|yes Tracking Child threads? [No]

-track-fds=no|yes trace the Open file description? [No]

-time-stamp=no|yes add time stamp to log information? [No]

-log-fd=<number> output log to descriptor file [2=stderr]

The-log-file=<file> writes the output information to filename. PID file, the PID is the ID of the running program

-log-file-exactly=<file> output log information to file

-log-file-qualifier=<var> gets the value of the environment variable to be the file name of the output information. [None]

-log-socket=ipaddr:port output log to socket, Ipaddr:port

Log information output

-xml=yes output information in XML format, only Memcheck available

-num-callers=<number> show <number> callers in stack traces [12]

-error-limit=no|yes if too many errors, stop displaying the new error? [Yes]

-error-exitcode=<number> returns an error code if an error is found [0=disable]

-db-attach=no|yes When an error occurs, Valgrind automatically launches the debugger gdb. [No]

-db-command=<command> command-line options to start the debugger [GDB-NW%f%p]

Relevant options for the Memcheck tool:

-leak-check=no|summary|full require detailed information on leak? [Summary]

-leak-resolution=low|med|high how much bt merging in leak check [low]

-show-reachable=no|yes show reachable blocks in leak check? [No]

Note:5 and 6 are best performed in red section

1. Download the latest version of VALGRIND-3.8.1.TAR.BZ2

2, unpack the installation package: TAR–JXVF valgrind-3.8.1.tar.bz2

3. Create directory after decompression valgrind-3.8.1

4. CD valgrind-3.7.0

5, Vim Configure (change armv7* to arm*)./configure–host=arm-hisiv200-linux

As the following errors are mentioned, make changes:

Vim Configure add the following lines:

Export path= $PATH:/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/bin

cc=arm-hisiv200-linux-gcc

Cflags=-i/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/usr/include

Ldflags=-l/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/usr/lib

then make Distclean;./configure--prefix=/mnt/valgrind--host=arm-hisiv200-linux

6, make; (There will be no ARM-HISIV200-LINUX-GCC found in the Do install here, so did not execute)

Make install

7, CP coregrind/valgrind/tftpboot/(Tftpboot is mounted on the board)

CP memcheck/memcheck-arm-linux/tftpboot/(First four steps are operating on Ubuntu)

8, in the/usr/local of the board mkdir LIB;CD Lib;mkdir Valgrind

9, put the Memcheck-arm-linux under the/usr/local/lib/valgrind/

10, under the/etc/profile add Export path= $PATH:/mnt

11, Valgrind Ls–l will appear

==980== Memcheck, a memory error detector

==980== Copyright (C) 2002-2012, and GNU GPL ' d, by Julian Seward et al.

==980== Using Valgrind-3.8.1 and Libvex; Rerun with-h for copyright info

==980== command:ls-l

==980==

Valgrind:fatal error at startup:a function redirection

Valgrind:which is mandatory for this platform-tool combination

Valgrind:cannot is set up. Details of the redirection are:

Valgrind

Valgrind:a must-be-redirected function

Valgrind:whose name matches the pattern:memcpy

Valgrind:in an object with Soname matching:ld-linux.so.3

Valgrind:was not found whilst processing

Valgrind:symbols from the object with Soname:ld-linux.so.3

Valgrind

Valgrind:possible Fixes: (1, short term): Install glibc ' s Debuginfo

Valgrind:package on the machine. (2, longer term): Ask the Packagers

Valgrind:for your Linux distribution to non-

valgrind:stripped ld.so (or whatever the dynamic linker. So is called)

Valgrind:that exports the Above-named function using the standard

Valgrind:calling conventions for this platform. The package need

Valgrind:to Install for fix (1) is called

Valgrind

Valgrind:on Debian, ubuntu:libc6-dbg

Valgrind:on SuSE, OpenSuSE, Fedora, Rhel:glibc-debuginfo

Valgrind

Valgrind:cannot continue--exiting now. Sorry.

12. Modify the. So file under the/lib directory in the file system above the board, as the compiled library file is clipped:

The library file under the/opt/hisi-linux/x86-arm/arm-hisiv200-linux/target/lib/directory is a standard C library that has not been cropped, replacing the library file with the one in the/lib directory on the file system above the board.

Add Default.supp, vgpreload_core-arm-linux.so to/usr/local/lib/valgrind

However, errors such as the following are still present:

......

Conditional jump or move depends on uninitialised value (s)

==1006== at 0x4922160:strcmp (in/lib/libc-2.11.1.so)

==1006==

==1006== Conditional Jump or move depends on uninitialised value (s)

==1006== at 0x4922778:strlen (in/lib/libc-2.11.1.so

......

Time profiling and memory leaks consumed by each function valgrind

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.