(工具) 交叉编译 gperftools及使用
交叉编译gperftools及使用
sudo apt-get install kcachegrind # 导出为 callgrind 格式时需要
sudo apt install doxygen-latex
sudo apt install graphviz
# 编译 pprof
go install github.com/google/pprof@latest
1. 交叉编译gperftools
# https://github.com/gperftools/gperftools/releases/tag/gperftools-2.9.1
CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ cmake .. -Dgperftools_enable_libunwind=OFF -Dgperftools_enable_frame_pointers=ON -DCMAKE_INSTALL_PREFIX=/home/hxf0223/tmp/gperftools/bbb
make -j && make install
2. ARM 测量待测试项目
2.1. 添加链接:libprofiler.so
file(GLOB SRCS *.cc)
ADD_EXECUTABLE(eigen_arm_test ${SRCS})
# SET(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)
# target_link_libraries(eigen_arm_test gtest glog pthread)
target_link_libraries(eigen_arm_test dcl_utils pthread "-Wl,--no-as-needed" profiler "-Wl,--as-needed")
2.2. 在ARM板卡上运行CPUPROFILE
# 生成 eigen_test.prof
CPUPROFILE=eigen_test.prof CPUPROFILE_FREQUENCY=500 ./eigen_arm_test
2.3. 转换.prof文件为pdf文件
sudo apt install graphviz ghostscript
sudo apt-get install kcachegrind # 转换为callgrind之后使用kcachegrind查看
拷贝ARM板卡上生成eigen_test.prof文件到PC主机上交叉编译生成的eigen_arm_test目录。
直接运行转换命令会导致找不到ARM测试程序依赖库文件:
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libc-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libc-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libc-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libgcc_s.so.1': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libgcc_s.so.1': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libgcc_s.so.1': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libm-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libm-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libm-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.25': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.25': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.25': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: /usr/local/lib/libprofiler.so.0.5.4: file format not recognized
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: /usr/local/lib/libprofiler.so.0.5.4: file format not recognized
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: /usr/local/lib/libprofiler.so.0.5.4: file format not recognized
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libpthread-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libpthread-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/libpthread-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/ld-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/ld-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-objdump: '/lib/arm-linux-gnueabihf/ld-2.28.so': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-addr2line: '/usr/lib/arm-linux-gnueabihf/libstdc++.so.6.0.25': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-addr2line: '/lib/arm-linux-gnueabihf/libgcc_s.so.1': No such file
/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf-addr2line: '/lib/arm-linux-gnueabihf/libc-2.28.so': No such file
解决办法是,在主机上创建一个目录,在此目录下创建名称跟缺失的路径一样的软链接(该缺失的路径为ARM板卡上的路径):
mkdir ~/tmp/fake_root && cd ~/tmp/fake_root
mkdir -p lib usr lib_gcc/lib
ln -s /usr/local/arm-linux-gnueabihf-8.3/arm-linux-gnueabihf/libc/lib/ lib/arm-linux-gnueabihf
ln -s /usr/local/arm-linux-gnueabihf-8.3/arm-linux-gnueabihf/libc/usr/lib usr/lib
ln -s /usr/local/arm-linux-gnueabihf-8.3/arm-linux-gnueabihf/lib lib_gcc/lib/arm-linux-gnueabihf
从.prof文件生成pdf文件:
pprof --tools=/usr/local/arm-linux-gnueabihf-8.3/bin/arm-linux-gnueabihf- --lib_prefix=/home/hxf0223/tmp/fake_bbb_root,/home/hxf0223/tmp/fake_bbb_root/lib_gcc,/home/hxf0223/tmp/gperftools/bbb/lib ./eigen_arm_test eigen_test.prof --pdf > eigen_test.pdf
lib_prefix添加了三个目录:ARM运行时目录,arm-gcc相关lib目录,及交叉编译libprofiler.so目录。
注意:lib_prefix只能添加绝对路径。
2.4. PC下转换命令格式
# 生成pdf格式的性能报告(层次调用节点有向图)
pprof --pdf ./eigen_arm_test eigen_test.prof > profile_eigen_x86.pdf
# pprof ----callgrind ./eigen_arm_test eigen_test.prof > profile_eigen_x86.callgrind
3. 在项目中使用ProfilerStart
链接使用libprofiler.so, 在代码中添加ProfilerStart, ProfilerStop。
#include <gperftools/profiler.h>
ProfilerStart("test_capture.prof");
// 待分析代码
ProfilerStop();
运行编译的可执行程序,得到test_capture.prof文件。随后从.prof文件生成报告。
4. Ubuntu x86_64编译 gperf-tools
使用如下链接,utoconf编译安装即可:
https://github.com/libunwind/libunwind.git
https://github.com/gperftools/gperftools.git
- libunwind 按照官方说明编译即可;
- gperftools 使用默认configure即可。如果libunwind安装到其他目录,gperftools使用 ./configure CFLAGS=inc_dir LDFLAGS=lib_dir;
5. 内存 Profile
export LD_PRELOAD=/usr/local/lib/libtcmalloc.so
export HEAPPROFILE=/home/q/perf-result/
export HEAP_PROFILE_ALLOCATION_INTERVAL=2000000000
6. 参考
7. 其他
(工具) 交叉编译 gperftools及使用的更多相关文章
- Linux主机上实现树莓派的交叉编译及文件传输,远程登陆
0.环境 Linux主机OS:Ubuntu14.04 64位,运行在wmware workstation 10虚拟机 树莓派版本:raspberry pi 2 B型. 树莓派OS:官网下的的raspb ...
- 在Blade中结合gperftools检查内存泄露
Blade是我们开发的大规模C++项目构建工具. gperftools是google开发的性能工具,由高效内存分配器,CPU性能分析器,堆分析器,堆检查器等工具组成. 和其他构建工具不同,结合gtes ...
- hisi3559的usb无线网卡驱动(rtl8192cu)(一条龙服务:内核编译、驱动编译、iw等工具编译)
usb无线网卡驱动(rtl8192cu) 内核编译.驱动编译.iw等工具编译 (哈哈,如果有其他问题,麻烦留言:) 环境 板卡:hi3559av100(arm64) 交叉编译链:aarch64-hi ...
- Qt Creator的安装与Qt交叉编译的配置
Qt Creator 的安装 到Qt官网下载Qt Creator https://www.qt.io/download-open-source/ 其它旧版本点击Achieve连接下载 或登录http ...
- am335x watchdog 设备出错
问题描述: am335x watchdog 设备节点打开失败. 如果是直接将omap_wdt 直接编译成uImage,这样会出现打开文件节点失败的情况. 如果单独编译成模块在后面文件系统内插入则不会. ...
- linux内核调试指南
linux内核调试指南 一些前言 作者前言 知识从哪里来 为什么撰写本文档 为什么需要汇编级调试 ***第一部分:基础知识*** 总纲:内核世界的陷阱 源码阅读的陷阱 代码调试的陷阱 原理理解的陷阱 ...
- Cocos移植到Android的一些问题-SQLite3数据库移植问题
首选我们讨论一下SQLite3数据库移植问题.我们在第14章节介绍了在Win32平台使用SQLite3数据库,我们介绍了两种配置环境的方法:一种是使用Cocos2d-x提供的SQLite3库配置,另一 ...
- Exynos4412从SD卡启动的简单网络文件系统制作
Exynos4412从SD卡启动的简单网络文件系统制作 1. 简介 嵌入式系统能够在开发板上正常运行,需要先进行系统配置,一个完整的嵌入式系统应该包含的几个部分::uboot,kernel,rootf ...
- Jz2440 环境安装
目录 Jz2440 环境安装 Ubuntu 设置 烧写工具 交叉编译环境 使用说明 烧写特性 title: Jz2440 环境安装 tags: linux date: 2018-09-20 22:56 ...
- linux下应用程序性能剖分神器gprofiler-tools-安装和使用
最近在摆弄算法的的优化,需要剖分一下算法的瓶颈,就找了一些代码剖分工具,其中 gprofileer-tools是很不错的工具,gperftools时google开源的一款C++性能分析分析工具,git ...
随机推荐
- Yarn上运行spark-shell和spark-sql命令行
spark-shell On Yarn spark-shell \ --master yarn-client \ --executor-memory 1G \ --num-executors 10 s ...
- Spark 写 Hbase
package com.grady import org.apache.hadoop.hbase.HBaseConfiguration import org.apache.hadoop.hbase.c ...
- Kubernetes(K8S)特性有哪些?
Kubernetes简介 Kubernetes是一个开源的,用于管理云平台中做个主机上的容器化的应用,Kubernetes的目标是让部署容器化的应用简单且高效,Kubernetes提供了应用部署,规划 ...
- 【项目实战】Kaggle泰坦尼克号的幸存者预测
前言 这是学习视频中留下来的一个作业,我决定根据大佬的步骤来一步一步完成整个项目,项目的下载地址如下:https://www.kaggle.com/c/titanic/data 大佬的传送门:http ...
- nginx中 location正则的理解
文章转载自:https://blog.csdn.net/wzj_110/article/details/110142902 正则表达式在线测试工具:https://tool.lu/regex loca ...
- Docker 与 Containerd 并用配置
描述: 事实上,Docker 和 Containerd 是可以同时使用的,只不过 Docker 默认使用的 Containerd 的命名空间不是 default,而是 moby,此处为了更方便我们学习 ...
- 基于ELK Nginx日志分析
配置Nginx 日志 Nginx 默认的access 日志为log格式,需要logstash 进行正则匹配和清洗处理,从而极大的增加了logstash的压力 所以我们Nginx 的日志修改为json ...
- Alertmanager篇
报一直是整个监控系统中的重要组成部分,Prometheus监控系统中,采集与警报是分离的.警报规则在 Prometheus 定义,警报规则触发以后,才会将信息转发到给独立的组件 Alertmanage ...
- IDEA中直接将 SpringBoot项目打包成 Docker镜像时 pom.xml的配置
<plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactI ...
- httpd常用配置之虚拟主机
httpd常用配置 目录 httpd常用配置 虚拟主机: 相同IP不同端口 不同IP相同端口 相同IP相同端口不同域名 切换使用MPM(编辑/etc/httpd/conf.modules.d/00-m ...