# hfsort **Repository Path**: endre/hfsort ## Basic Information - **Project Name**: hfsort - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2025-04-03 - **Last Updated**: 2025-04-03 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # hfsort ## 介绍 从[Facebook仓](https://github.com/facebook/hhvm/tree/master/hphp/tools/hfsort)中提取的大型程序如数据中心mysql等程序函数重排优化工具,生成hotfuncs.txt,在编译链接期传入gold链接器,从而完成二进制文件中函数排序,优化结构,实现程序优化。 ## 安装方式 ### 编译hfsort ```shell cd hfsort/build cmake .. make ``` ## 使用方式 1、编译程序,生成可执行二进制程序YOUR_BINARY(名称中尽量不要包含特殊符号) 2、通过如下命令采集程序的perf数据 For Applications: ```shell perf record -BN -F 3999 --no-buffering -g -e instructions:u -o perf.data -- YOUR_BINARY ``` For Services:(这需要记录运行Services时的pid,-p指定pid,获取-a全部采集,perf script时使用YOUR_BINARY名称过滤得到指定服务的调用栈) ```shell perf record -BN -F 3999 --no-buffering -g -p YOUR_PID -e instructions:u -o perf.data -- sleep SLEEP_TIME ``` or ```shell perf record -BN -F 3999 --no-buffering -g -a -e instructions:u -o perf.data -- sleep SLEEP_TIME ``` 3、运行hfsort,生成hotfuncs.txt,其中包含函数重排信息(默认hfsort算法,-a为hfsort+算法,-p为ph算法) ```shell ${hfsort_dir}/bin/hfsort YOUR_BINARY perf.data ``` 4、再次编译YOUR_BINARY,在编译选项中加入以下选项,生成新的YOUR_BINARY_sorted ```shell -ffunction-sections -fuse-ld=gold -Wl,--icf=all,--gc-sections,--section-ordering-file hotfuncs.txt ``` 5、测试对比YOUR_BINARY_sorted与YOUR_BINARY的性能差距(正负收益均有可能, good luck)