我有一个包含许多函数调用的简单 C 代码,我使用 gprof 对其进行了分析。
% cumulative self self total
time seconds seconds calls s/call s/call name
71.93 907.85 907.85 201280 0.00 0.00 ForceCalcs
2.61 1237.18 33.00 1258 0.03 1.00 Heap
1.53 1256.45 19.28 1258 0.02 0.02 AdjustSP
0.01 1261.61 0.07 1258 0.00 0.00 Boundary
0.00 1261.61 0.00 100 0.00 0.00 Profile
0.00 1261.61 0.00 2 0.00 0.00 MakeMap
0.00 1261.61 0.00 1 0.00 0.18 Initialize
为了清楚起见,我从列表中省略了一些其他函数调用。这就是百分比加起来不等于 100 的原因。为了比较结果,我使用 -O3 命令对其进行编译并使用 gprof 再次对其进行分析。获得的平面轮廓如下:
% Each sample counts as 0.01 seconds.
% (--- means nothing mentioned)
% cumulative self self total
time seconds seconds calls ms/call ms/call name
73.66 460.88 460.88 201280 2.29 2.29 ForceCalc
1.65 620.85 10.30 --- --- --- Heap
0.47 623.80 2.95 --- --- --- AdjustSP
0.00 626.10 0.01 1258 0.01 0.01 Boundary
0.00 626.10 0.00 1 0.00 0.00 MakeMap
但是现在我无法理解我的代码中发生了哪些优化。例如
- 对 Initialize() 和 profile() 的调用在后面的配置文件中没有对应的条目
- 在后面的配置文件中没有提到 Heap() 和 AdjustSP() 的调用或毫秒/调用。(这就是我想通过 --- 展示的内容)
有人可以解释上述2个观察的含义。我认为它与内联有关,但不确定。