Ubuntu PGO方式编译Firefox笔记
在上一篇blog里用最简单的方式编译了firefox,今天用PGO方式重新优化编译了一下。
官方的PGO编译文档参考https://developer.mozilla.org/en/Building_with_Profile-Guided_Optimization
首先将.mozconfig修改如下:
mk_add_options MOZ_CO_PROJECT=browser mk_add_options MOZ_OBJDIR=@TOPSRCDIR@/ff-opt mk_add_options PROFILE_GEN_SCRIPT="sh /home/xmx/run-firefox.sh" ac_add_options --enable-application=browser ac_add_options --disable-tests ac_add_options --disable-debug ac_add_options --enable-default-toolkit=cairo-gtk2 --enable-system-cairo ac_add_options --enable-official-branding ac_add_options --enable-optimize="-O2 -march=native -mtune=native -pipe -fomit-frame-pointer" ac_add_options --enable-jemalloc ac_add_options --enable-strip ac_add_options --enable-install-strip ac_add_options --enable-profile-guided-optimization
其中
ac_add_options –enable-optimize=”-O2 -march=native -mtune=native -pipe -fomit-frame-pointer”, ac_add_options –enable-jemalloc, ac_add_options –enable-strip, ac_add_options –enable-install-strip
这四个选项是优化编译选项。
ac_add_options –enable-profile-guided-optimization 这个选项表示用PGO方式编译,而 mk_add_options PROFILE_GEN_SCRIPT=”sh /home/xmx/run-firefox.sh” 这个选项指定了PGO编译第一遍结束后执行的脚本。
而run-firefox.sh的内容如下:
#!/bin/sh make -f client.mk profiledbuild export NO_EM_RESTART=1 mkdir $OBJDIR/_profileprofile $OBJDIR/dist/bin/firefox -no-remote -profile $OBJDIR/_profileprofile
配置结束后在源码顶层目录执行:
make -f client.mk profiledbuild
注意执行的是profiledbuild而不是之前简单的build
然后就开第一次编译,等待。。。
第一次编译结束后会自动调用run-firefox.sh脚本,运行刚刚编译完的firefox(第一次编译的时候千万不要运行原来的firefox,以免这里出错)。按照平时的上网习惯看一些网页,然后关掉,第二次编译便自动开始了。第二次编译会以第一次编译后运行产生的profile调优,通常能获得相当不错的性能提升。
第二次编译结束后便和普通编译一样了:
cd ff-opt make package
在ff-opt/dist下就已经生成了一个打包好的firefox包,解压到任何地方运行就可以了。

这么多东西,看的眼晕,博主太邪恶了。。。