码迷,mamicode.com
首页 > 其他好文 > 详细

Profile your program using GNU gprof

时间:2021-04-20 14:35:11      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:for   comm   pre   forms   special   not   and   inpu   ted   

Profiling is an indispensable measure for analyzing and optimizing the performance of your program. A typical profiler like GNU gprof will complete this task by running your program after a special compilation.

There are 3 forms of the profiling analysis:

  • flat profile: how much time the program spent in each function and how many times the function was called.

  • call graph: for each function, which function called it and which other functions it called, and how many times.

  • annotated source: a listing of the program source code, which is labeled with the number of times each line of the program was executed.

Compiler options for generating the code which can be profiled by gprof:

  • -pg: enable profiling by gprof, which is always mandatory.

  • -g: enable annotated source profiling.

  • -a: enable basic-block counting, which is required by the annotated source profiling. However, this option does not appear in gcc or g++.

Options for gprof command

  • -p: generate flat profile.

  • -q: generate call graph.

  • -l: enable line-by-line profiling.

  • -s: summarize profile data from different files into gmon.sum.

Steps for using gprof:

  1. Compile the program for gprof:

    g++ -std=gnu++11 -g -O2 -o output input.cpp -gp
  2. Run the program: ./output1. After execution, the profiling data will be stored in the file gmon.out.

  3. Call gprof command with the generated gmon file as argument to generate profiling reports.

Profile your program using GNU gprof

标签:for   comm   pre   forms   special   not   and   inpu   ted   

原文地址:https://www.cnblogs.com/quantumman/p/14672800.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!