- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 gcc -pg
和 gprof
看到了奇怪的分析结果。
我找不到更好/更小的重现方法,因此我链接了我看到问题的实际代码。
我正在使用代码here ,使用 make prof
我注意到几个错误,主要是:
shape_stream_test
显示为被 ai_best_move_rec
大量调用,并且占用了自身时间总运行时间的 15%ai_best_move_rec
合法调用的其他函数,例如 grid_block_remove
、grid_cpy
、grid_new
甚至不会显示为 children 实际教授统计数据:
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
53.92 4.00 4.00 4231936 0.00 0.00 grid_eval
13.62 5.01 1.01 4467368 0.00 0.00 shape_stream_test
6.88 5.52 0.51 4690742 0.00 0.00 grid_block_center_top
6.07 5.97 0.45 4521016 0.00 0.00 grid_block_valid
5.80 6.40 0.43 4467368 0.00 0.00 grid_block_add
3.37 6.65 0.25 4467368 0.00 0.00 grid_block_drop
2.02 6.80 0.15 35 4.29 209.20 ai_best_move_rec
1.95 6.95 0.15 235469 0.00 0.00 grid_init
1.75 7.08 0.13 9212461 0.00 0.00 block_extreme
1.48 7.19 0.11 4467402 0.00 0.00 block_move
0.94 7.26 0.07 1654899 0.00 0.00 block_get
0.54 7.30 0.04 block_crust_get
0.40 7.33 0.03 grid_block_set_color
0.27 7.35 0.02 4467368 0.00 0.00 grid_block_remove
0.27 7.37 0.02 235501 0.00 0.00 block_new
0.27 7.39 0.02 grid_block_intersects
0.20 7.40 0.02 235469 0.00 0.00 grid_new
0.13 7.41 0.01 235467 0.00 0.00 shape_stream_peek
0.13 7.42 0.01 drop_amount
0.00 7.42 0.00 621 0.00 0.00 grid_clear_lines
0.00 7.42 0.00 587 0.00 0.00 grid_cpy
0.00 7.42 0.00 35 0.00 0.00 grid_print
0.00 7.42 0.00 34 0.00 0.00 block_init
0.00 7.42 0.00 34 0.00 0.00 block_print
0.00 7.42 0.00 34 0.00 0.00 game_move_print
0.00 7.42 0.00 34 0.00 0.00 grid_apply_moves
0.00 7.42 0.00 34 0.00 0.00 shape_stream_pop
0.00 7.42 0.00 7 0.00 0.00 shape_new
0.00 7.42 0.00 1 0.00 0.00 shape_stream_new
% 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-2014 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 2 byte(s) for 0.13% of 7.42 seconds
index % time self children called name
<spontaneous>
[1] 98.7 0.00 7.32 ai_test [1]
0.15 7.17 35/35 ai_best_move_rec [2]
0.00 0.00 34/34 grid_apply_moves [21]
0.00 0.00 2/235469 grid_new [9]
0.00 0.00 35/35 grid_print [24]
0.00 0.00 34/34 game_move_print [27]
0.00 0.00 34/34 shape_stream_pop [28]
0.00 0.00 1/1 shape_stream_new [30]
-----------------------------------------------
235432 ai_best_move_rec [2]
0.15 7.17 35/35 ai_test [1]
[2] 98.7 0.15 7.17 35+235432 ai_best_move_rec [2]
4.00 0.00 4231936/4231936 grid_eval [3]
1.01 0.00 4467368/4467368 shape_stream_test [4]
0.51 0.11 4690742/4690742 grid_block_center_top [5]
0.45 0.09 4521016/4521016 grid_block_valid [6]
0.43 0.00 4467368/4467368 grid_block_add [7]
0.25 0.00 4467368/4467368 grid_block_drop [8]
0.02 0.15 235467/235469 grid_new [9]
0.11 0.00 4467368/4467402 block_move [12]
0.02 0.00 4467368/4467368 grid_block_remove [16]
0.02 0.00 235467/235501 block_new [17]
0.01 0.00 235467/235467 shape_stream_peek [19]
0.00 0.00 587/587 grid_cpy [23]
0.00 0.00 587/621 grid_clear_lines [22]
235432 ai_best_move_rec [2]
-----------------------------------------------
4.00 0.00 4231936/4231936 ai_best_move_rec [2]
[3] 53.9 4.00 0.00 4231936 grid_eval [3]
-----------------------------------------------
1.01 0.00 4467368/4467368 ai_best_move_rec [2]
[4] 13.6 1.01 0.00 4467368 shape_stream_test [4]
-----------------------------------------------
0.51 0.11 4690742/4690742 ai_best_move_rec [2]
[5] 8.4 0.51 0.11 4690742 grid_block_center_top [5]
0.07 0.00 4690742/9212461 block_extreme [11]
0.04 0.00 1056160/1654899 block_get [13]
-----------------------------------------------
0.45 0.09 4521016/4521016 ai_best_move_rec [2]
[6] 7.3 0.45 0.09 4521016 grid_block_valid [6]
0.06 0.00 4521016/9212461 block_extreme [11]
0.03 0.00 598739/1654899 block_get [13]
-----------------------------------------------
0.43 0.00 4467368/4467368 ai_best_move_rec [2]
[7] 5.8 0.43 0.00 4467368 grid_block_add [7]
-----------------------------------------------
0.25 0.00 4467368/4467368 ai_best_move_rec [2]
[8] 3.4 0.25 0.00 4467368 grid_block_drop [8]
0.00 0.00 635/9212461 block_extreme [11]
-----------------------------------------------
0.00 0.00 2/235469 ai_test [1]
0.02 0.15 235467/235469 ai_best_move_rec [2]
[9] 2.2 0.02 0.15 235469 grid_new [9]
0.15 0.00 235469/235469 grid_init [10]
-----------------------------------------------
0.15 0.00 235469/235469 grid_new [9]
[10] 2.0 0.15 0.00 235469 grid_init [10]
-----------------------------------------------
0.00 0.00 68/9212461 grid_apply_moves [21]
0.00 0.00 635/9212461 grid_block_drop [8]
0.06 0.00 4521016/9212461 grid_block_valid [6]
0.07 0.00 4690742/9212461 grid_block_center_top [5]
[11] 1.8 0.13 0.00 9212461 block_extreme [11]
-----------------------------------------------
0.00 0.00 34/4467402 grid_apply_moves [21]
0.11 0.00 4467368/4467402 ai_best_move_rec [2]
[12] 1.5 0.11 0.00 4467402 block_move [12]
-----------------------------------------------
0.03 0.00 598739/1654899 grid_block_valid [6]
0.04 0.00 1056160/1654899 grid_block_center_top [5]
[13] 0.9 0.07 0.00 1654899 block_get [13]
-----------------------------------------------
<spontaneous>
[14] 0.5 0.04 0.00 block_crust_get [14]
-----------------------------------------------
<spontaneous>
[15] 0.4 0.03 0.00 grid_block_set_color [15]
-----------------------------------------------
0.02 0.00 4467368/4467368 ai_best_move_rec [2]
[16] 0.3 0.02 0.00 4467368 grid_block_remove [16]
-----------------------------------------------
0.00 0.00 34/235501 grid_apply_moves [21]
0.02 0.00 235467/235501 ai_best_move_rec [2]
[17] 0.3 0.02 0.00 235501 block_new [17]
-----------------------------------------------
<spontaneous>
[18] 0.3 0.02 0.00 grid_block_intersects [18]
-----------------------------------------------
0.01 0.00 235467/235467 ai_best_move_rec [2]
[19] 0.1 0.01 0.00 235467 shape_stream_peek [19]
-----------------------------------------------
<spontaneous>
[20] 0.1 0.01 0.00 drop_amount [20]
-----------------------------------------------
0.00 0.00 34/34 ai_test [1]
[21] 0.0 0.00 0.00 34 grid_apply_moves [21]
0.00 0.00 34/235501 block_new [17]
0.00 0.00 68/9212461 block_extreme [11]
0.00 0.00 34/4467402 block_move [12]
0.00 0.00 34/34 block_init [25]
0.00 0.00 34/621 grid_clear_lines [22]
-----------------------------------------------
0.00 0.00 34/621 grid_apply_moves [21]
0.00 0.00 587/621 ai_best_move_rec [2]
[22] 0.0 0.00 0.00 621 grid_clear_lines [22]
-----------------------------------------------
0.00 0.00 587/587 ai_best_move_rec [2]
[23] 0.0 0.00 0.00 587 grid_cpy [23]
-----------------------------------------------
0.00 0.00 35/35 ai_test [1]
[24] 0.0 0.00 0.00 35 grid_print [24]
-----------------------------------------------
0.00 0.00 34/34 grid_apply_moves [21]
[25] 0.0 0.00 0.00 34 block_init [25]
-----------------------------------------------
0.00 0.00 34/34 game_move_print [27]
[26] 0.0 0.00 0.00 34 block_print [26]
-----------------------------------------------
0.00 0.00 34/34 ai_test [1]
[27] 0.0 0.00 0.00 34 game_move_print [27]
0.00 0.00 34/34 block_print [26]
-----------------------------------------------
0.00 0.00 34/34 ai_test [1]
[28] 0.0 0.00 0.00 34 shape_stream_pop [28]
-----------------------------------------------
0.00 0.00 7/7 shapes_read [68]
[29] 0.0 0.00 0.00 7 shape_new [29]
-----------------------------------------------
0.00 0.00 1/1 ai_test [1]
[30] 0.0 0.00 0.00 1 shape_stream_new [30]
-----------------------------------------------
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-2014 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] ai_best_move_rec [21] grid_apply_moves [3] grid_eval
[14] block_crust_get [7] grid_block_add [10] grid_init
[11] block_extreme [5] grid_block_center_top [9] grid_new
[13] block_get [8] grid_block_drop [24] grid_print
[25] block_init [18] grid_block_intersects [29] shape_new
[12] block_move [16] grid_block_remove [30] shape_stream_new
[17] block_new [15] grid_block_set_color [19] shape_stream_peek
[26] block_print [6] grid_block_valid [28] shape_stream_pop
[20] drop_amount [22] grid_clear_lines [4] shape_stream_test
[27] game_move_print [23] grid_cpy
后来我发现我结合了 -Ofast 和 -pg 标志,并删除 -Ofast 修复了上面的这些问题。
我的问题是:
这两个标志不兼容吗?我在文档中找不到任何此类警告
如果它们不兼容,这是否是 gcc 错误?
如何解决这个问题,以查看与最积极的优化相匹配的分析结果,这样我就不会浪费时间优化错误的代码?
最佳答案
你想要速度,对吗? -Ofast
仅在调用堆栈的底部起作用。它无法解决只有您才能解决的问题。这只会让他们更难找到。首先关闭优化器并修复您可以修复的问题。 Here's an example of how some people do it.当您尽可能做到这一点后,打开优化器并让它发挥其魔力。
小火焰:) 很多人说分析未优化的代码是浪费时间,但他们从不说出原因。他们在演讲厅听到、在博客上或从 stackoverflow 上读到,来自某个在该主题上具有明确权威的人,无需给出理由。
我认为这是一厢情愿的情况:我的代码基本上是完美的,所以唯一可以加快速度的方法就是运行编译器的优化器。然后,当分析器显示无法加快速度时 - 这显然是正确的,对我来说万岁!
针对评论添加:让我稍微离题一下(抱歉)。我知道人们可以仔细检查代码,在数据表示上投入精力,内联一些函数,进行其他高级优化,并测量这样做的速度。伟大的。但是,如果您每次更改代码的原因只是查看并思考代码,那么无论您的想法如何,它仍然是一种猜测。猜测可能是正确的,但你应该问的问题是“我错过了什么?”和“我如何找到它?”
我和很多人用的方法是 random pausing 。它所需的唯一工具是调试器,如 GDB 或任何 IDE。它与分析的不同之处在于,它直接定位不必要的计算,而不是进行测量并指望您破译它们、过滤掉噪音、查看特定例程并在其中进行搜索。它告诉您特定的代码行和特定的数据,程序正在做什么以及为什么这样做。然后你可以询问是否有一种更少浪费的方法可以做到这一点,很可能是有的。它不做的是告诉您精确的时间分数 - 您只能得到非常粗略的测量结果。它所做的就是识别问题。您可能认为您当然不能依赖这种不准确的方法,如果您只在一个样本上发现问题,那就是事实。但是,如果您在多个样本上看到它,您就知道它很大,并且多次查看它的总体样本越少,它就越大。 Here are the statistics behind it.更重要的是:这将发现任何分析器都会发现的任何问题,甚至更多。
然后,当您发现并解决一个问题时,您可以重新进行所有操作,因为解决一个问题会放大剩余的问题。通过这种方式,你可以“阶梯”加速,直到你不能再加速为止。这就是你获得最大速度的方式as in this example 。然后,无论如何,使用 -Ofast
。
关于c - gcc -Ofast -pg 的 gprof 结果错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38966415/
我正在尝试在 Conda 环境中编译一些代码,在那里我 之前安装的编译包gcc_linux-64 . 然而,即使在停用和重新激活环境之后,gcc还在/usr/bin/gcc . 我该怎么做才能让 Co
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 7 年前。 Improve
这其实是两个问题: 1 - 在我的 debian amd64 系统上,我似乎无法构建与 gmp/mpfr/mpc 动态链接的交叉 GCC。即使我删除 --disable-shared,它也总是静态链接
研究ELF格式的结果,可以看到目标文件中有一个符号对应每个函数,对应的符号表项的值为st_size,表示大小的功能。 问题是,即使我更改了目标文件中特定函数的 st_size 并链接了它,但可执行文件
海湾合作委员会的 documentation for #line directives说他们是这样的: #line "myfile.cpp" 123 但是当我用 g++ 5.1 检查输出时,它们实际上
我正在使用 as 和 gcc 来汇编和创建 ARM 汇编程序的可执行文件,正如 this 所推荐的那样教程,如下: 给定一个汇编源文件,program.s,我运行: as -o program.o p
long long x; double n; x=long long(n); 这不起作用。什么是正确的方法? 最佳答案 显而易见的: x = (long long) n; 关于gcc - 转换为长长
我想知道用于 gcc 的原子内置函数的头文件是什么? 我想使用这 2 个函数为我当前创建的线程库实现互斥锁。 bool __sync_bool_compare_and_swap (type *ptr,
它出现在 another question :gcc调用的程序和部件是什么? (特别是在编译 C 或 C++ 时)以便有人可以设计一些拦截和更改流程的方案以用于各种自定义编码目的? 最佳答案 编译器二
可能吗?我想使用 gcc喜欢 assembler并在将其编译为 ubuntu 上的可执行文件后。 我尝试过这个: gcc a.asm -o out.o 来自 out.o文件编译成.out可执行文件。
我写了一个简单的 C 程序 test.c : #include #include int add(int a, int b); int main() { int i=5,j=10;
即。所以如果你使用任何八进制文字,它会给你一个警告。 微软编译器的同样问题。 如果没有,是否有任何其他工具可以检测八进制文字。 (vim 似乎有一个很酷的技巧,它突出了第一个领先的将不同的颜色归零,但
我在旧线程中搜索。但没有找到任何线程回答我的问题。 gcc 是否像 vc++ 一样支持函数级链接? 如果是,我应该提供什么选项来链接目标文件和库? 最佳答案 看起来 gcc 不直接支持函数级链接。您可
也许标题并没有把问题说得那么准确:我知道当我运行 gcc foo.c 时,GCC 会调用其他为它完成所有工作的子程序,从而生成主 gcc 程序只是一个界面。但这究竟是如何完成的呢? 它是否使用syst
我听说最近版本的 gcc 非常擅长将通过函数指针的调用转换为直接调用。但是,我在网上或快速浏览 gcc 的源代码上找不到任何关于它的信息。有谁知道这是否真的是真的,如果是这样,它使用什么算法来做到这一
gcc/g++ 链接器选项“-Map”生成的“.map”文件用于什么? 以及如何阅读它们? 最佳答案 我建议为您投入生产的任何软件生成一个映射文件并保留一份副本。 它可用于破译崩溃报告。根据系统的不同
gcc信息文件在有关x86-64特定标志的部分中说 其他事情: There is no `-march=generic' option because `-march' ind
我想知道 gcc 链接器选项(例如:-Wl,options)是否可以更改编译后的可执行文件中的汇编指令,因为如果您使用某些 gcc 优化选项会发生这种情况? 当您比较编译后的二进制文件(例如比较签名)
是否有GCC编译指示会停止,暂停或中止编译过程? 我正在使用gcc 4.1,但也希望在gcc 3.x版本上也可以使用该编译指示。 最佳答案 您可能需要#error: edd@ron:/tmp$ g++
当我使用gcc编译C程序时我通常使用 -g 将一些调试信息放入 elf 文件中这样 gdb 就可以在需要时帮助我。 但是,我注意到有些程序使用 -ggdb,因为它应该使调试信息对 gdb 更加友好。
我是一名优秀的程序员,十分优秀!