zoukankan      html  css  js  c++  java
  • Profile your program using GNU gprof

    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.

      子曰:“君子食无求饱,居无求安,敏于事而慎于言,就有道而正焉,可谓好学也已。”
  • 相关阅读:
    完全背包笔记
    渗透测试之信息收集常用网站
    结对项目-四则运算"软件"之升级版
    第三次作业:个人项目-小学四则运算“软件”之初版
    分布式版本控制系统Git的安装与使用
    第一次作业:准备
    爬虫综合大作业
    爬取全部校园新闻
    理解爬虫原理
    中文词频统计与词云生成
  • 原文地址:https://www.cnblogs.com/quantumman/p/14672800.html
Copyright © 2011-2022 走看看