在不修改源代码的情况下查找多进程程序中调用了哪些函数?

发布于 2024-07-18 06:58:51 字数 333 浏览 5 评论 0原文

我正在开发一个项目,在该项目中,我需要找到在给定特定输入的情况下在各种 Linux 程序(用 C 编写)中调用哪些函数。 我当前的方法是使用 -pg (分析选项)编译程序,运行它,并通过处理 gprof 的输出来查找调用哪些函数。 只有至少被调用一次的函数才会出现在输出文件中。

明显的问题是只有一个进程可以写入 gprof 输出文件。 如果程序分叉多个进程,我不会从其他进程获得任何分析输出。

有没有办法让 gprof 为每个进程生成一个输出文件(可能由 pid 标记)? 该手册建议将每个进程更改为不同的目录,但我不想修改源代码来执行此操作。 Linux 上还有其他可以提供帮助的工具吗?

I'm working on a project where I need to find which functions get called in various Linux programs (written in C) given particular inputs. My current approach has been to compile a program with -pg (profiling option), run it, and find which functions get called by processing gprof's output. Only functions that are called at least once appear in the output file.

The apparent problem is that only one process can write to the gprof output file. If the program forks multiple processes, I don't get any profiling output from the other processes.

Is there any way to make gprof produce an output file for each process (maybe labelled by pid)? The manual suggests having each process change into a different directory, but I don't want to modify the source code to do this. Is there another tool for Linux that can help?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

神也荒唐 2024-07-25 06:58:51

这里< /a> 他们建议使用 tprof

您尝试过 valgrind 吗?

http://www.network-theory.co.uk/docs/ valgrind/valgrind_17.html

--child-silent-after-fork=<yes|no> [default: no] 

启用后,Valgrind 将不会显示 fork 调用产生的子进程的任何调试或日志输出。 在处理创建子进程时,这可以使输出不那么混乱(尽管更具误导性)。 与 --trace-children= 结合使用特别有用。 如果您请求 XML 输出 (--xml=yes),也强烈建议使用此标志,否则来自子级和父级的 XML 可能会混淆,这通常会使其毫无用处。

Here they suggest using tprof:

Have you tried valgrind?

http://www.network-theory.co.uk/docs/valgrind/valgrind_17.html

--child-silent-after-fork=<yes|no> [default: no] 

When enabled, Valgrind will not show any debugging or logging output for the child process resulting from a fork call. This can make the output less confusing (although more misleading) when dealing with processes that create children. It is particularly useful in conjunction with --trace-children=. Use of this flag is also strongly recommended if you are requesting XML output (--xml=yes), since otherwise the XML from child and parent may become mixed up, which usually makes it useless.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文