• <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 天邊藍(lán) 閱讀(1102) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): Linux
            轉(zhuǎn)載至http://www.cnblogs.com/feisky/archive/2010/03/09/1681997.html

            gprof介紹

            gprof是GNU profiler工具。可以顯示程序運(yùn)行的“flat profile”,包括每個(gè)函數(shù)的調(diào)用次數(shù),每個(gè)函數(shù)消耗的處理器時(shí)間。也可以顯示“調(diào)用圖”,包括函數(shù)的調(diào)用關(guān)系,每個(gè)函數(shù)調(diào)用花費(fèi)了多少時(shí)間。還可以顯示“注釋的源代碼”,是程序源代碼的一個(gè)復(fù)本,標(biāo)記有程序中每行代碼的執(zhí)行次數(shù)。

            為gprof編譯程序


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

            Gprof基本用法:

            1. 使用 -pg 編譯和鏈接你的應(yīng)用程序。

            2. 執(zhí)行你的應(yīng)用程序使之生成供gprof 分析的數(shù)據(jù)。

            3. 使用gprof 程序分析你的應(yīng)用程序生成的數(shù)據(jù)。

            $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產(chǎn)生的信息


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

            命令格式

            gprof [可執(zhí)行文件] [gmon.out文件] [其它參數(shù)]

            方括號(hào)中的內(nèi)容可以省略。如果省略了“可執(zhí)行文件”,gprof會(huì)在當(dāng)前目錄下搜索a.out文件作為可執(zhí)行文件,而如果省略了gmon.out文件,gprof也會(huì)在當(dāng)前目錄下尋找gmon.out。其它參數(shù)可以控制gprof輸出內(nèi)容的格式等信息。最常用的參數(shù)如下:

            l -b 不再輸出統(tǒng)計(jì)圖表中每個(gè)字段的詳細(xì)描述。

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

            l -q 只輸出函數(shù)的時(shí)間消耗列表。

            l -e Name 不再輸出函數(shù)Name 及其子函數(shù)的調(diào)用圖(除非它們有未被限制的其它父函數(shù))。可以給定多個(gè) -e 標(biāo)志。一個(gè) -e 標(biāo)志只能指定一個(gè)函數(shù)。

            l -E Name 不再輸出函數(shù)Name 及其子函數(shù)的調(diào)用圖,此標(biāo)志類(lèi)似于 -e 標(biāo)志,但它在總時(shí)間和百分比時(shí)間的計(jì)算中排除了由函數(shù)Name 及其子函數(shù)所用的時(shí)間。

            l -f Name 輸出函數(shù)Name 及其子函數(shù)的調(diào)用圖。可以指定多個(gè) -f 標(biāo)志。一個(gè) -f 標(biāo)志只能指定一個(gè)函數(shù)。

            l -F Name 輸出函數(shù)Name 及其子函數(shù)的調(diào)用圖,它類(lèi)似于 -f 標(biāo)志,但它在總時(shí)間和百分比時(shí)間計(jì)算中僅使用所打印的例程的時(shí)間。可以指定多個(gè) -F 標(biāo)志。一個(gè) -F 標(biāo)志只能指定一個(gè)函數(shù)。-F 標(biāo)志覆蓋 -E 標(biāo)志。

            l -z 顯示使用次數(shù)為零的例程(按照調(diào)用計(jì)數(shù)和累積時(shí)間計(jì)算)。

            不過(guò),gprof不能顯示對(duì)象之間的繼承關(guān)系,這也是它的弱點(diǎn).

            Copyright © 天邊藍(lán)

            久久久久久久久久久久久久| 久久人人爽人人爽人人av东京热 | 国产精品一区二区久久| 国产精品禁18久久久夂久| 国产亚洲色婷婷久久99精品91| 少妇无套内谢久久久久| 色综合久久中文色婷婷| 2021国产精品午夜久久| 一本色道久久88—综合亚洲精品| 国产成人久久精品二区三区| 亚洲精品高清国产一线久久| 老司机午夜网站国内精品久久久久久久久 | 青青草原综合久久| 色综合久久天天综线观看| 国产精品视频久久| 欧美大香线蕉线伊人久久| 亚洲精品97久久中文字幕无码| 91久久精品视频| 狠狠人妻久久久久久综合蜜桃| 久久人人添人人爽添人人片牛牛| 久久777国产线看观看精品| 久久国语露脸国产精品电影| 国产精品伊人久久伊人电影| 性欧美大战久久久久久久久| 久久久久久国产精品免费免费| 91精品久久久久久无码| 无码超乳爆乳中文字幕久久| 久久久这里只有精品加勒比| 久久无码高潮喷水| 日韩欧美亚洲国产精品字幕久久久| 丰满少妇高潮惨叫久久久| 久久亚洲春色中文字幕久久久| 久久久www免费人成精品| 亚洲欧美日韩精品久久亚洲区 | 久久亚洲国产精品一区二区| 久久亚洲AV成人无码电影| 一本一本久久aa综合精品| 久久精品日日躁夜夜躁欧美| 久久99国产精品久久99小说 | 一本久道久久综合狠狠爱| 国产成人精品综合久久久久|