首页 > 系统相关 >gprof:Linux 自带性能分析工具(含中文翻译)

gprof:Linux 自带性能分析工具(含中文翻译)

时间:2024-09-11 16:49:46浏览次数:1  
标签:std function 中文翻译 int 0.00 gprof number vector Linux

gprof 的使用

gprof 已经安装在 NOI Linux 2.0 中,是 Linux 中一个使用的程序性能分析工具。欲将对程序 main.cpp 进行性能分析,需要在编译选项中加入 -pg

g++ main.cpp -o main -pg

然后正常运行程序:

./main

此时会生成一个 gmon.out 文件,存储了性能分析信息,需要使用 gprof 进行翻译,输出人类可读的信息(以下五选一):

gprof main gmon.out
gprof main # 这样也可以
gprof -b main # -b 不会输出每一项的英文解释(相当于简洁输出)
gprof main > report.txt # 建议输出到文件再查看
gprof main | view - # 或者你比较极端也可以

建议使用 vim 查看 gprof 的信息,因为 vim 有对它的高亮。程序调用树中,紫色行即为当前描述的函数,紫色行上方是它的父级函数,下方是它所调用的函数。或者也可以看 index 列,左边写了 index 的是当前描述的函数。

gprof 信息的中文翻译

  • %time: 此函数使用的程序总运行时间的百分比。
  • cumulative seconds: 此函数所占秒数与上面列出的秒数的总和。
  • self seconds: 仅此函数所占的秒数。这是列表排序的第一关键字。
  • calls: 调用此函数的次数。
  • self ms/call: 每次调用此函数所花费的平均毫秒数。
  • total ms/call: 每次调用此函数及其后代所花费的平均毫秒数。
  • 以上,如果该函数没有被分析,那么对应项为空。

此表描述了程序的调用树,并按每个函数及其子函数所花费的总时间进行排序。此表中的每个条目由几行组成。左侧空白处的索引编号行列出了当前函数。上面的几行列出了调用此函数的函数,下面的几行则列出了此函数调用的函数。

此行列出了:

  • index: 表中每个元素的唯一编号。索引号按数字排序。索引号印在每个函数名称旁边,这样更容易在表中查找函数的位置。
  • %time: 这是用于此功能及其子功能的“总”时间的百分比。请注意,由于不同的观点、选项排除的功能等,这些数字加起来不会达到 100%。
  • self: 这是在此函数中花费的总时间。
  • children: 这是子函数传播到此函数中的总时间。
  • called: 这是函数被调用的次数。如果函数递归调用自身,则该数字仅包括非递归调用,后面是“+”和递归调用的数量。
  • name: 当前函数的名称。索引号打印在其后。如果函数是循环(cycle,下文有解释)的成员,则循环号打印在函数名称和索引号之间。

对于函数的父亲(即调用它的函数),字段具有以下含义:

  • self: 这是从函数直接传播到此父级的时间量。(was propagated,可以理解为在……中所占的时间)
  • children: 这是从函数的子级传播到此父级的时间量。
  • called: 这是父级调用函数的次数 "/" 函数被调用的总次数。对函数的递归调用不包含在“/”后面的数字中。
  • name: 这是父级的名字。父级的索引号将打印在其后。如果父级是循环的成员,则循环号将打印在名称和索引号之间。如果无法确定函数的父级,则会在“name”字段中打印“<spontaneous>”一词,而所有其他字段都是空的。

对于函数的孩子(即它调用的函数),字段具有以下含义:

  • self: 这是从孩子直接传播到函数中的时间量。
  • children: 这是从孩子的孩子传播到函数的时间量。
  • called: 这是函数调用此子项的次数 “/” 子项被调用的总次数。孩子的递归调用不会包含在“/”后面的数字中。
  • name: 这是孩子的名字。子项的索引号将打印在其后。如果子项是循环的成员,则循环号将打印在名称和索引号之间。

如果调用图中有任何循环(圆圈,cycles & circles),则整个循环都有一个条目。此条目显示谁调用了循环(作为父项)和循环的成员(作为子项)。“+”递归调用条目显示了循环内部的函数调用次数,每个成员的调用条目显示该成员从循环的其他成员调用的次数。

示例

Flat profile:

Each sample counts as 0.01 seconds.
  %   cumulative   self              self     total           
 time   seconds   seconds    calls  ms/call  ms/call  name    
 53.66      0.22     0.22  1599992     0.00     0.00  chkmax(std::vector<long long, std::allocator<long long> >&, minkowski_t<long long>, int)
 26.83      0.33     0.11 29033026     0.00     0.00  minkowski_t<long long>::next()
  7.32      0.36     0.03  1199994     0.00     0.00  bitmax(std::vector<long long, std::allocator<long long> > const&, std::vector<long long, std::allocator<long long> > const&, int)
  7.32      0.39     0.03        1    30.00   410.00  solve(int, int)
  2.44      0.40     0.01  2399988     0.00     0.00  chkmaxp(std::vector<long long, std::allocator<long long> >&, std::vector<long long, std::allocator<long long> > const&, long long)
  2.44      0.41     0.01   799996     0.00     0.00  chkmax(std::vector<long long, std::allocator<long long> >&, std::vector<long long, std::allocator<long long> > const&, int)
  0.00      0.41     0.00   799996     0.00     0.00  std::vector<long long, std::allocator<long long> >::_M_default_append(unsigned long)
  0.00      0.41     0.00   600000     0.00     0.00  std::vector<long long, std::allocator<long long> >::operator=(std::vector<long long, std::allocator<long long> > const&)

 %         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.

 total     the average number of milliseconds spent in this
ms/call    function and its descendents per call, if this
	   function is profiled, else blank.

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.

Copyright (C) 2012-2022 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

		     Call graph (explanation follows)


granularity: each sample hit covers 4 byte(s) for 2.44% of 0.41 seconds

index % time    self  children    called     name
                                                 <spontaneous>
[1]    100.0    0.00    0.41                 main [1]
                0.03    0.38       1/1           solve(int, int) [2]
-----------------------------------------------
                              399998             solve(int, int) [2]
                0.03    0.38       1/1           main [1]
[2]    100.0    0.03    0.38       1+399998  solve(int, int) [2]
                0.22    0.00 1599992/1599992     chkmax(std::vector<long long, std::allocator<long long> >&, minkowski_t<long long>, int) [3]
                0.11    0.00 29033026/29033026     minkowski_t<long long>::next() [4]
                0.03    0.00 1199994/1199994     bitmax(std::vector<long long, std::allocator<long long> > const&, std::vector<long long, std::allocator<long long> > const&, int) [5]
                0.01    0.00 2399988/2399988     chkmaxp(std::vector<long long, std::allocator<long long> >&, std::vector<long long, std::allocator<long long> > const&, long long) [6]
                0.01    0.00  799996/799996      chkmax(std::vector<long long, std::allocator<long long> >&, std::vector<long long, std::allocator<long long> > const&, int) [7]
                0.00    0.00  799996/799996      std::vector<long long, std::allocator<long long> >::_M_default_append(unsigned long) [14]
                0.00    0.00  600000/600000      std::vector<long long, std::allocator<long long> >::operator=(std::vector<long long, std::allocator<long long> > const&) [15]
                              399998             solve(int, int) [2]
-----------------------------------------------
                0.22    0.00 1599992/1599992     solve(int, int) [2]
[3]     53.7    0.22    0.00 1599992         chkmax(std::vector<long long, std::allocator<long long> >&, minkowski_t<long long>, int) [3]
-----------------------------------------------
                0.11    0.00 29033026/29033026     solve(int, int) [2]
[4]     26.8    0.11    0.00 29033026         minkowski_t<long long>::next() [4]
-----------------------------------------------
                0.03    0.00 1199994/1199994     solve(int, int) [2]
[5]      7.3    0.03    0.00 1199994         bitmax(std::vector<long long, std::allocator<long long> > const&, std::vector<long long, std::allocator<long long> > const&, int) [5]
-----------------------------------------------
                0.01    0.00 2399988/2399988     solve(int, int) [2]
[6]      2.4    0.01    0.00 2399988         chkmaxp(std::vector<long long, std::allocator<long long> >&, std::vector<long long, std::allocator<long long> > const&, long long) [6]
-----------------------------------------------
                0.01    0.00  799996/799996      solve(int, int) [2]
[7]      2.4    0.01    0.00  799996         chkmax(std::vector<long long, std::allocator<long long> >&, std::vector<long long, std::allocator<long long> > const&, int) [7]
-----------------------------------------------
                0.00    0.00  799996/799996      solve(int, int) [2]
[14]     0.0    0.00    0.00  799996         std::vector<long long, std::allocator<long long> >::_M_default_append(unsigned long) [14]
-----------------------------------------------
                0.00    0.00  600000/600000      solve(int, int) [2]
[15]     0.0    0.00    0.00  600000         std::vector<long long, std::allocator<long long> >::operator=(std::vector<long long, std::allocator<long long> > const&) [15]
-----------------------------------------------

 This table describes the call tree of the program, and was sorted by
 the total amount of time spent in each function and its children.

 Each entry in this table consists of several lines.  The line with the
 index number at the left hand margin lists the current function.
 The lines above it list the functions that called this function,
 and the lines below it list the functions this one called.
 This line lists:
     index	A unique number given to each element of the table.
		Index numbers are sorted numerically.
		The index number is printed next to every function name so
		it is easier to look up where the function is in the table.

     % time	This is the percentage of the `total' time that was spent
		in this function and its children.  Note that due to
		different viewpoints, functions excluded by options, etc,
		these numbers will NOT add up to 100%.

     self	This is the total amount of time spent in this function.

     children	This is the total amount of time propagated into this
		function by its children.

     called	This is the number of times the function was called.
		If the function called itself recursively, the number
		only includes non-recursive calls, and is followed by
		a `+' and the number of recursive calls.

     name	The name of the current function.  The index number is
		printed after it.  If the function is a member of a
		cycle, the cycle number is printed between the
		function's name and the index number.


 For the function's parents, the fields have the following meanings:

     self	This is the amount of time that was propagated directly
		from the function into this parent.

     children	This is the amount of time that was propagated from
		the function's children into this parent.

     called	This is the number of times this parent called the
		function `/' the total number of times the function
		was called.  Recursive calls to the function are not
		included in the number after the `/'.

     name	This is the name of the parent.  The parent's index
		number is printed after it.  If the parent is a
		member of a cycle, the cycle number is printed between
		the name and the index number.

 If the parents of the function cannot be determined, the word
 `<spontaneous>' is printed in the `name' field, and all the other
 fields are blank.

 For the function's children, the fields have the following meanings:

     self	This is the amount of time that was propagated directly
		from the child into the function.

     children	This is the amount of time that was propagated from the
		child's children to the function.

     called	This is the number of times the function called
		this child `/' the total number of times the child
		was called.  Recursive calls by the child are not
		listed in the number after the `/'.

     name	This is the name of the child.  The child's index
		number is printed after it.  If the child is a
		member of a cycle, the cycle number is printed
		between the name and the index number.

 If there are any cycles (circles) in the call graph, there is an
 entry for the cycle-as-a-whole.  This entry shows who called the
 cycle (as parents) and the members of the cycle (as children.)
 The `+' recursive calls entry shows the number of function calls that
 were internal to the cycle, and the calls entry for each member shows,
 for that member, how many times it was called from other members of
 the cycle.

Copyright (C) 2012-2022 Free Software Foundation, Inc.

Copying and distribution of this file, with or without modification,
are permitted in any medium without royalty provided the copyright
notice and this notice are preserved.

Index by function name

   [2] solve(int, int)         [7] chkmax(std::vector<long long, std::allocator<long long> >&, std::vector<long long, std::allocator<long long> > const&, int) [14] std::vector<long long, std::allocator<long long> >::_M_default_append(unsigned long)
   [5] bitmax(std::vector<long long, std::allocator<long long> > const&, std::vector<long long, std::allocator<long long> > const&, int) [6] chkmaxp(std::vector<long long, std::allocator<long long> >&, std::vector<long long, std::allocator<long long> > const&, long long) [15] std::vector<long long, std::allocator<long long> >::operator=(std::vector<long long, std::allocator<long long> > const&)
   [3] chkmax(std::vector<long long, std::allocator<long long> >&, minkowski_t<long long>, int) [4] minkowski_t<long long>::next()

你可以看一下能不能用上面的中文翻译大致看懂。

标签:std,function,中文翻译,int,0.00,gprof,number,vector,Linux
From: https://www.cnblogs.com/caijianhong/p/18408481

相关文章

  • 使用nvim查看的linux kernel 源码(可以快速跳转等
    neovim使用的是lazyvim,开箱即用十分方便。linuxkernel源码,如果用clangd构建指定好LLVM还是可以使用下面的指令得到compile_commands.json这个文件的。compile_commands.json就是用来做clangd跳转支持的文件。./scripts/gen_compile_commands.py但是对于aarch64-linux-gnu......
  • Linux:seq指令
    学习自:Linux命令(113)——seq命令-腾讯云开发者社区-腾讯云1、前言seq(Sequence)指令类似Python中的range函数,用于按照指定步长产生从start到end之间的所有整数。2、用法seq[选项]startstependstart、step:默认1,可不写end:必须要有3、选项选项说明-fformat......
  • Linux安装MySQL数据库
    Linux安装MySQL数据库1.检查是否已经安装MySQLrpm-qa|grepmysql如果已经安装必须进行卸载之后在进行安装,可以使用下面命令将其删除(xxx为文件全名)rpm-exxx2.安装MySQL2.1下载安装包下载mysqlMySQL::DownloadMySQLCommunityServer(ArchivedVersions......
  • socket套接字通信---win和linux互通(1)
    一、Windows下的网络调试工具-NetAssist下载页面下载后无需安装,解压缩就是个exe的执行文件。双击打开就可使用软件界面二、linux下的网络调试工具nc(netcat)1、当前系统$cat/proc/versionLinuxversion6.6.47-current-x86(build@armbian)(gcc(Ubuntu11.4.0-1ubun......
  • Arch Linux 安装记录
    ArchLinux个人直接在arch中使用arch-install-scripts安装新系统,一些前面的步骤没有记录。其中的步骤可以用GUI软件逃课。分区和格式化可以使用partitionmanager(Linux)、diskgenius(Windows)等GUI软件一键分区。partitionmanager在安装btrfs-progs后可以格式化分区为......
  • Linux——进程
    ......
  • [Linux] Microsoft Teams 无法进行屏幕分享
    在Ubuntu22.04中,MicrosoftTeams无法进行屏幕分享的问题可能与桌面环境中的屏幕共享集成缺失有关。运行以下命令可以解决这个问题:sudoaptinstallxdg-desktop-portal-gnomexdg-desktop-portalxdg-desktop-portal是一个通用的桌面门户服务,它提供了一组标准接口,允许沙盒......
  • 【北京迅为】i.mx8mm嵌入式linux开发指南第四篇 嵌入式Linux系统移植篇第六十八章u-bo
      迅为i.mx8mm开发板特点: 性能强:i.MX8MM处理器采用了先进的14LPCFinFET工艺,提供更快的速度和更高的电源效率;四核Cortex-A53,单核Cortex-M4,多达五个内核,主频高达1.8GHz,2GDDR4内存、8GEMMC存储。 PMIC:采用PCA9450A电源管理,是NXP全新研制配套iMX.8M的电源管理芯片,有六个......
  • 如何在 Linux 系统中查看 CPU 核数和内存大小
     在日常运维和开发中,了解服务器或虚拟机的硬件配置是非常重要的一环。无论是进行性能调优,还是资源分配,了解CPU的核数和内存大小可以帮助我们更好地规划应用的运行环境。本篇博客将介绍如何在Linux系统中查看CPU核数和内存大小。一、查看CPU核数在Linux中,查看CPU......
  • arm64 Linux操作系统知识点
    一、C语言常见陷阱1.数据模型ARM64下可以采用LP64和ILP64数据模型,在Linux系统下默认采用LP64数据模型。LP64中,L表示Long,P表示Pointer(指针长度),ILP32、ILP64、LP64数据模型中不同数据类型的长度数据类型/字节ILP32数据模型中的长度ILP64数据模型中的长度LP64......