Linux C + + performance test tools gprof () Getting Started tutorial __ Storage

Source: Internet
Author: User

First, the preface

Reference gprof User manual: Http://sourceware.org/binutils/docs-2.17/gprof/index.html

Reference Blog: http://blog.csdn.net/stanjiang2010/article/details/5655143

Gprof is GCC's own performance testing tool, which can count the number of calls, time, and function call graphs for each function.

Second, the tutorial

Using GRPOF is divided into three steps

(1) Compile time to open the compile switch,-PG

(2) Run the program (the program must run normally before the performance report will be generated)

(3) Run the Performance test tool to generate the report.

1. Code

Write a sample code here and then perform a performance test on it

TEST_GPROF.C
#include <stdio.h>

void new_func1 (void);

void func1 (void)
{
    printf ("\ n Inside func1 \ n");
    int i = 0;

    for (; i<0xffffffff;i++);
    New_func1 ();

    return;
}

static void Func2 (void)
{
    printf ("\ Inside func2 \ n");
    int i = 0;

    for (; i<0xffffffaa;i++);
    return;
}

int main (void)
{
    printf (\ Inside main () \ n);
    int i = 0;

    for (; i<0xffffff;i++);
    Func1 ();
    Func2 ();

    return 0;
}
Test_gprof_new.c
#include <stdio.h>

void new_func1 (void)
{
    printf (\ Inside new_func1 () \ n ");
    int i = 0;

    for (; i<0xffffffee;i++);

    return;
}
2. Compile and Execute

g++  -pg test_gprof.cpp test_gprof_new.cpp-o test_gprof

You can see that the execution will be reborn into a gmon.out file



3. Run Performance test Tool

Gprof test_gprof Gmon.out
You can see a variety of parameters that are on the screen

(1) Flat profile, including the number of calls per function, and the processor time consumed by each function

(2) Call graph includes the invocation relationship of functions, and the time spent in each function call




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.