运行可执行文件的默认配置文件,并调用该文件gmon.out.有没有办法指定新的位置?
我在i386/linux2.6上使用gcc 3.4.6
在尝试优化代码时,我对由kcachegrdind和生成的配置文件的差异感到有些困惑gprof.具体来说,如果我使用gprof(使用-pg交换机编译等),我有这个:
Flat profile:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
89.62 3.71 3.71 204626 0.02 0.02 objR<true>::R_impl(std::vector<coords_t, std::allocator<coords_t> > const&, std::vector<unsigned long, std::allocator<unsigned long> > const&) const
5.56 3.94 0.23 18018180 0.00 0.00 W2(coords_t const&, coords_t const&)
3.87 4.10 0.16 200202 0.00 0.00 build_matrix(std::vector<coords_t, std::allocator<coords_t> > const&)
0.24 4.11 0.01 400406 0.00 0.00 std::vector<double, std::allocator<double> >::vector(std::vector<double, std::allocator<double> > const&)
0.24 4.12 0.01 100000 …Run Code Online (Sandbox Code Playgroud) 任何人都可以向我解释profile-generate和pg选项之间的区别吗?
我gprof在OS X上运行时遇到问题.该文件test.c是:
#include <stdio.h>
int main() {
printf("Hello, World!\n");
return 0;
}
Run Code Online (Sandbox Code Playgroud)
我的终端看起来像:
$ gcc -pg test.c
$ gcc -pg -o test test.c
$ ./test
Hello, World!
$ gprof test
gprof: file: test is not of the host architecture
Run Code Online (Sandbox Code Playgroud)
编辑:此外,它不会生成文件gmon.out.
这里发生了什么?
我已经查看了几十个用gprof进行性能分析的教程.我正在尝试使用SMT求解器dReal的代码.为了构建程序,我首先安装了g ++ - 4.8,Bison,Flex和Cmake.然后构建dReal,说明执行以下操作:
git clone git@github.com:soonhokong/dReal.git dreal
cd dreal
mkdir -p build/release
cd build/release
cmake -DCMAKE_BUILD_TYPE=RELEASE -DCMAKE_CXX_COMPILER=g++-4.8 -DCMAKE_C_COMPILER=gcc-4.8 ../../src
make
Run Code Online (Sandbox Code Playgroud)
在这里,我应该添加-pg?我是编程的新手,因此非常感谢推理而不是答案.我知道你应该把它添加-pg到编译阶段但是所有的教程都说要把它放在g ++或gcc之后.我找不到如何修改cmake的代码.我确实尝试将构建类型更改为PROFILE,但这没有帮助.
我使用profiling标志(-pg)编译了一个带gcc的代码,但是当我运行程序时,没有生成gmon.out.
我编译了一个测试代码 - 实际上是来自这个问题的代码 - 看看编译标志和gprof是否正常工作,是的,它是否有效.
为了编译代码(命名xrttimetag),使用了以下行(下面我使用了-I(...)以及-L(...)隐藏其他科学库的大量路径列表):
gcc -c -o ./xrttimetag.o -Wall --pedantic -Wno-comment -Wno-long-long -pg -fPIC -I(...) -DPACKAGE_NAME="" -DPACKAGE_TARNAME="" -DPACKAGE_VERSION="" -DPACKAGE_STRING="" -DPACKAGE_BUGREPORT="" -DPACKAGE_URL="" -Dg77Fortran=1 -DgFortran=1 -DHAVE_CONNECT=1 -DHAVE_ACCEPT=1 -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_LIBM=1 -DHAVE_LIBDL=1 -DHAVE_LIBNCURSES=1 -DSIZEOF_LONG=8 xrttimetag.c
gcc -o xrttimetag xrttimetag.o -L(...) -lswxrt -latFunctions3.3 -lcoordfits -lcoord -lephemeris -lhdinit_2.7 -lhdutils_2.7 -lape_2.8 -lcfitsio_3.37 -lreadline -lhdio_2.7 -lncurses -ldl -lm -L/usr/lib64/gcc/x86_64-suse-linux/4.6 -L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.6/../../.. …Run Code Online (Sandbox Code Playgroud) 我们使用g ++ 4.2.4,我试图在我的代码中追踪一些性能问题.
我正在运行gprof来生成配置文件,我得到以下"奇怪",因为最昂贵的功能是__tcf_0:
Each sample counts as 0.01 seconds.
% cumulative self self total
time seconds seconds calls ms/call ms/call name
40.00 0.04 0.04 1 40.00 95.00 __tcf_0
Run Code Online (Sandbox Code Playgroud)
然后,此函数似乎调用了我的大多数用户函数(即,它是从main调用的函数).我在这里找到的最接近的解释是在这里,但该链接指的是静态对象和atexit,我不认为这适用于我的情况.
如果它有用,我正在使用Boost(program_options和fusion)和HDF5库.
更新:
我在构建时使用的命令是:
g++ -Wreturn-type -Wunused -Winline -pg -DLINUX -DHAS_SETENV \
-DFUSION_MAX_MAP_SIZE=15 -DFUSION_MAX_VECTOR_SIZE=15 -g -O0 \
--param large-function-growth=300 --param inline-unit-growth=200
Run Code Online (Sandbox Code Playgroud) 我知道我可以分析我的代码gprof和kprofLinux上.在Windows上是否有与这些应用程序相当的替代方案?
我不懂gprof的文档,关于如何使用gprof编译程序以进行性能分析.在g ++中,是否需要使用-g选项(调试信息)进行编译,-pg或者不添加选项.在每种情况下,我得到不同的结果,我想看看我的应用程序中的瓶颈在哪里处于发布模式,而不是在调试模式中,编译器遗漏了许多优化(例如内联)
编译一个C++程序使用gcc -pg -g(至少,这些是我在Makefile中给出的参数;没有任何确凿的证据证明执行了什么命令).程序运行到正常完成,CWD设置为我的主目录.没有写gmon.out文件.
gcc是4.4.7.OS是centos 6.
我的程序是由一个手动滚动的Perl守护进程使用fork/exec启动的.我已经验证了CWD是我的主目录,并且它是可写的,通过在执行touch foo我的目标程序之前执行守护进程.至于我已经能够研究,这不应该影响程序的分析或写gmon.out终止(通常).