如何在 g++ 中使用配置文件引导优化?

发布于 2024-10-06 09:36:28 字数 36 浏览 0 评论 0原文

另外,有人能给我指点关于这个主题的好教程吗?我找不到任何。

Also, can anyone point me to a good tutorial on the subject? I can't find any.

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

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

发布评论

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

评论(3

平安喜乐 2024-10-13 09:36:28

-fprofile-generate 将使用分析代码来检测应用程序。应用程序将在实际运行时记录某些事件,如果在编译时已知此使用模式,则可以提高性能。分支、内联的可能性等都可以被记录,但我不确定 GCC 是如何实现这一点的细节。

程序退出后,它会将所有这些数据转储到 *.gcda 文件中,这些文件本质上是测试运行的日志数据。使用 -fprofile-use 标志重建应用程序后,GCC 在进行优化时将考虑 *.gcda 日志数据,通常会显着提高性能。当然,这取决于很多因素。

-fprofile-generate will instrument the application with profiling code. The application will, while actually running, log certain events that could improve performance if this usage pattern was known at compile time. Branches, possibility for inlining, etc, can all be logged, but I'm not sure in detail how GCC implements this.

After the program exits, it will dump all this data into *.gcda files, which are essentially log data for a test run. After rebuilding the application with -fprofile-use flag, GCC will take the *.gcda log data into account when doing its optimizations, usually increasing the performance significantly. Of course, this depends on many factors.

感性不性感 2024-10-13 09:36:28

这个示例

g++ -O3 -fprofile-generate [more params here, like -march=native ...] -o executable_name
// run my program's benchmarks, or something to stress its most common path
g++ -O3 -fprofile-use [more params here, like -march=native...] -o executable_name

基本上,您最初编译并链接到此用于编译和链接的额外标志:-fprofile-generate(来自 此处)。

然后,当您运行它时,默认情况下它会在 .o 文件“旁边”创建 .gcda 文件(硬编码到它们构建的完整路径)。

您可以选择使用 -fprofile-dir=XXX 更改创建这些 .gcda 文件的位置设置

然后,您使用 -fprofile-use 参数重新编译和重新链接,它会使用配置文件引导的优点进行编译。

From this example:

g++ -O3 -fprofile-generate [more params here, like -march=native ...] -o executable_name
// run my program's benchmarks, or something to stress its most common path
g++ -O3 -fprofile-use [more params here, like -march=native...] -o executable_name

Basically, you initially compile and link with this extra flag for both compiling and linking: -fprofile-generate (from here).

Then, when you run it, by default it will create .gcda files "next" to your .o files, it seems (hard coded to the full path where they were built).

You can optionally change where it creates these .gcda files with the -fprofile-dir=XXX setting.

Then you re compile and relink using the -fprofile-use parameter, and it compiles it using profile guided goodness.

烟火散人牵绊 2024-10-13 09:36:28

棘手的一点是设置 makefile。

您肯定需要单独的目标文件输出目录。我建议将它们命名为“profile”和“release”。您可能必须复制配置文件运行生成的 *.gcda 文件,以便 GCC 在发布构建步骤中找到它们。

结果几乎肯定会更快。它可能也会更大。 -fprofile-use 选项启用许多其他优化步骤,否则只能通过 -O3 启用。

The tricky bit is setting up the makefiles.

You definitely need separate output directories for object files. I would recommend naming them "profile" and "release". You might have to copy the *.gcda files that result from the profile run so that GCC finds them in the release build step.

The result will almost certainly be faster. It will probably be larger as well. The -fprofile-use option enables many other optimization steps that are otherwise only enabled by -O3.

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