在运行时启用和禁用 gprof?
Enable and disable gprof at runtime?
我想知道 gprof
中是否有任何 API 来启用和禁用受监视应用程序在运行时的分析。我感兴趣的是禁用代码某些部分的分析,并使其专注于我感兴趣的部分。我的意思是,有没有办法避免这样做?
int main (void)
{
// disable gprof ?
uninteresting_routine();
// enable gprof ?
interesting_routine();
}
来自 GCC 网站的此 link 引用了检测选项,似乎没有包含对此功能的任何引用。
有一种未记录且隐藏的方法可以在某些系统上运行(至少是某些版本的 glibc 和某些 BSD,如果不是全部的话)。
$ cat foo.c
extern void moncontrol(int);
static void
foo(void)
{
}
static void
bar(void)
{
}
int
main(int argc, char **argv)
{
moncontrol(0);
foo();
moncontrol(1);
bar();
return 0;
}
$ cc -o foo -pg foo.c && ./foo
$ gprof foo | egrep 'foo|bar'
0.00 0.00 0.00 1 0.00 0.00 bar
[1] 0.0 0.00 0.00 1 bar [1]
[1] bar
Glibc 没有此函数的原型或手册页,但确实存在。
接受的答案是正确的。只是想提醒 C++ 程序员使用
extern "C" void moncontrol(int);
我想知道 gprof
中是否有任何 API 来启用和禁用受监视应用程序在运行时的分析。我感兴趣的是禁用代码某些部分的分析,并使其专注于我感兴趣的部分。我的意思是,有没有办法避免这样做?
int main (void)
{
// disable gprof ?
uninteresting_routine();
// enable gprof ?
interesting_routine();
}
来自 GCC 网站的此 link 引用了检测选项,似乎没有包含对此功能的任何引用。
有一种未记录且隐藏的方法可以在某些系统上运行(至少是某些版本的 glibc 和某些 BSD,如果不是全部的话)。
$ cat foo.c
extern void moncontrol(int);
static void
foo(void)
{
}
static void
bar(void)
{
}
int
main(int argc, char **argv)
{
moncontrol(0);
foo();
moncontrol(1);
bar();
return 0;
}
$ cc -o foo -pg foo.c && ./foo
$ gprof foo | egrep 'foo|bar'
0.00 0.00 0.00 1 0.00 0.00 bar
[1] 0.0 0.00 0.00 1 bar [1]
[1] bar
Glibc 没有此函数的原型或手册页,但确实存在。
接受的答案是正确的。只是想提醒 C++ 程序员使用
extern "C" void moncontrol(int);