• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            gprof——GNU性能分析工具

            Posted on 2013-04-22 16:39 天邊藍 閱讀(1102) 評論(0)  編輯 收藏 引用 所屬分類: Linux
            轉載至http://www.cnblogs.com/feisky/archive/2010/03/09/1681997.html

            gprof介紹

            gprof是GNU profiler工具??梢燥@示程序運行的“flat profile”,包括每個函數的調用次數,每個函數消耗的處理器時間。也可以顯示“調用圖”,包括函數的調用關系,每個函數調用花費了多少時間。還可以顯示“注釋的源代碼”,是程序源代碼的一個復本,標記有程序中每行代碼的執行次數。

            為gprof編譯程序


            在編譯或鏈接源程序的時候在編譯器的命令行參數中加入“-pg”選項,編譯時編譯器會自動在目標代碼中插入用于性能測試的代碼片斷,這些代碼在程序在運行時采集并記錄函數的調用關系和調用次數,以及采集并記錄函數自身執行時間和子函數的調用時間,程序運行結束后,會在程序退出的路徑下生成一個gmon.out文件。這個文件就是記錄并保存下來的監控數據。可以通過命令行方式的gprof或圖形化的Kprof來解讀這些數據并對程序的性能進行分析。另外,如果想查看庫函數的profiling,需要在編譯是再加入“-lc_p”編譯參數代替“-lc”編譯參數,這樣程序會鏈接libc_p.a庫,才可以產生庫函數的profiling信息。如果想執行一行一行的profiling,還需要加入“-g”編譯參數。
            例如如下命令行:gcc -Wall -g -pg -lc_p example.c -o example

            Gprof基本用法:

            1. 使用 -pg 編譯和鏈接你的應用程序。

            2. 執行你的應用程序使之生成供gprof 分析的數據。

            3. 使用gprof 程序分析你的應用程序生成的數據。

            $gprof -b a.out gmon.out      
            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  function

                                    Call graph

            granularity: each sample hit covers 2 byte(s) no time propagated

            index % time    self  children    called     name
                            0.00    0.00       1/1           main [8]
            [1]      0.0    0.00    0.00       1         function [1]
            -----------------------------------------------

            Index by function name

               [1] function

            gprof產生的信息


            %                        the percentage of the total running time of the
            time                     program used by this function.
                                       函數使用時間占所有時間的百分比。
            cumulative          a running sum of the number of seconds accounted
            seconds             for by this function and those listed above it.
                                       函數和上列函數累計執行的時間。
            self                    the number of seconds accounted for by this
            seconds             function alone.  This is the major sort for this
                                      listing.
                                      函數本身所執行的時間。
            calls                   the number of times this function was invoked, if
                                      this function is profiled, else blank.
                                      函數被調用的次數
            self                   the average number of milliseconds spent in this
            ms/call               function per call, if this function is profiled,
                                     else blank.
                                      每一次調用花費在函數的時間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.
                                      每一次調用,花費在函數及其衍生函數的平均時間microseconds。
            name                 the name of the function.  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.
                                      函數名

            命令格式

            gprof [可執行文件] [gmon.out文件] [其它參數]

            方括號中的內容可以省略。如果省略了“可執行文件”,gprof會在當前目錄下搜索a.out文件作為可執行文件,而如果省略了gmon.out文件,gprof也會在當前目錄下尋找gmon.out。其它參數可以控制gprof輸出內容的格式等信息。最常用的參數如下:

            l -b 不再輸出統計圖表中每個字段的詳細描述。

            l -p 只輸出函數的調用圖(Call graph的那部分信息)。

            l -q 只輸出函數的時間消耗列表。

            l -e Name 不再輸出函數Name 及其子函數的調用圖(除非它們有未被限制的其它父函數)??梢越o定多個 -e 標志。一個 -e 標志只能指定一個函數。

            l -E Name 不再輸出函數Name 及其子函數的調用圖,此標志類似于 -e 標志,但它在總時間和百分比時間的計算中排除了由函數Name 及其子函數所用的時間。

            l -f Name 輸出函數Name 及其子函數的調用圖??梢灾付ǘ鄠€ -f 標志。一個 -f 標志只能指定一個函數。

            l -F Name 輸出函數Name 及其子函數的調用圖,它類似于 -f 標志,但它在總時間和百分比時間計算中僅使用所打印的例程的時間。可以指定多個 -F 標志。一個 -F 標志只能指定一個函數。-F 標志覆蓋 -E 標志。

            l -z 顯示使用次數為零的例程(按照調用計數和累積時間計算)。

            不過,gprof不能顯示對象之間的繼承關系,這也是它的弱點.

            Copyright © 天邊藍

            情人伊人久久综合亚洲| 日韩AV毛片精品久久久| 国产成人久久精品激情| 久久国产乱子精品免费女| 国产一区二区精品久久岳| 亚洲精品国产第一综合99久久 | 亚洲午夜久久久精品影院| 伊人久久大香线蕉影院95| 青春久久| 国产成人精品久久一区二区三区av | 精品久久久久久久| 亚洲中文字幕无码一久久区| 久久久久国产精品| 亚洲精品无码成人片久久| 国产精品成人久久久久三级午夜电影 | 国产精品久久久久jk制服| 久久免费观看视频| 久久99精品国产麻豆宅宅| 久久久久久精品成人免费图片| 66精品综合久久久久久久| 久久久久久久久久久久久久| 99久久精品国产一区二区蜜芽| 无码国内精品久久综合88| 久久se精品一区精品二区国产| 国产精品久久久久久影院| 狠狠色噜噜色狠狠狠综合久久| 伊人色综合久久天天| 国产午夜免费高清久久影院| 亚洲人成精品久久久久| 热99RE久久精品这里都是精品免费 | 久久香蕉国产线看观看精品yw| 亚洲精品无码久久不卡| 狠狠色丁香婷婷综合久久来来去 | 999久久久国产精品| 国产精品久久网| 青青草原综合久久大伊人精品| 精品久久久久久国产| 99热精品久久只有精品| 亚洲欧美日韩精品久久| 国产三级观看久久| 国产午夜精品理论片久久|