Linux Performance Optimization Tool gprof précis-writers

Source: Internet
Author: User

    1. Gprof How to work

      When you specify the-PG option when using GCC compilation, the compiler inserts the performance test code into the user code.


    2. Gprof Simple Application Example

      Main.c

#include <stdio.h> #include "lib.h" int main (void) {func1 (FUNC2); return 0;}


Lib.h

#ifndef lib_h#define lib_hvoid func1 (int i), void func2 (int i); #endif/* Lib_h */


Lib.c

#include <stdio.h> #include "lib.h" void func1 (int i) {while (i--) printf ("Func1 ():%d\n", i);} void Func2 (int i) {while (i--) printf ("Func2 ():%d\n", i);}


Makefile

CFLAGS + =-PGOBJS = $ (patsubst%.c,%.o,$ (wildcard *.c)) Prog: $ (OBJS) gcc-pg-o [email protected] $^clean:-rm-f prog $ (obj S


Run make compile code at the command line to generate the prog file. Enter the./prog to run the file, producing an output file gmon.out. After

Use the tool gprof to analyze the operation of the output File Analyzer and to derive the data optimizer based on these analyses.

Run the Gprof prog gmon.out > Gprofrslt.txt analysis output file to get the following results (excerpt). can be passed to

Gprof different parameters to derive the output of different aspects of performance considerations.

flat profile:each sample counts as 0.01 seconds. no time  accumulated  %   cumulative   self               self     total             time   seconds   seconds     calls  Ts/call  Ts/call  name       0.00      0.00     0.00         1     0.00     0.00   func1  0.00      0.00     0.00         1     0.00      0.00  func2

The meaning of the specific output can be referenced in the GPROF help documentation.


3. Gprof Documentation

http://sourceware.org/binutils/docs/gprof/

This article is from the "Jimokuangxiangqu" blog, make sure to keep this source http://4594296.blog.51cto.com/4584296/1841733

Linux Performance Optimization Tool gprof précis-writers

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.