GoogleCPUProfiler在CMake项目中的使用

本文介绍了如何在CMake项目中集成并使用GoogleCPUProfiler进行资源占用分析。首先,详细说明了gperftools的下载、编译及在CMake中的配置方法。然后,展示了如何通过ProfilerStart和ProfilerStop函数在代码中插入分析点,并生成资源占用的.prof文件。最后,提到了使用pprof工具以不同格式查看分析结果。
摘要由CSDN通过智能技术生成

GoogleCPUProfiler使用

  • gperftools-2.7下载与编译

将gperftools-2.7下载解压之后,进行编译make && make install

  • gperftools适用cmake项目

1)gperftools没有提供官方的查找profiler库的cmake脚本,所以在基于cmake管理的项目中如果要查找libprofiler库需要自己写FindPROFILER.cmake脚本:

# - Find libprofiler

# - This module determines the libprofiler library of the system

# the vairable can be set

#   LIBPROFILER_STATIC_LINK set true for static link library 为TRUE是要求静态连接

# The following variables are set if the library found:

# LIBPROFILER_FOUND - If false do nnt try to use libprofiler.

# LIBPROFILER_INCLUDE_DIRS - where to find the headfile of library.include文件夹位置

# LIBPROFILER_LIBRARY_DIRS - where to find the libprofiler library.profiler库所在位置

# LIBPROFILER_LIBRARIES, the library file name needed to use libprofiler.profiler库及所有依赖库列表

# LIBPROFILER_LIBRARY - the library needed to use libprofiler. profiler库全路径

# imported target

#   gperftools::profiler



if(LIBPROFILER_FOUND)

    return()

endif()

include (depcommon)

# linux系统下调用pkg-config查找profiler

if (NOT WIN32)

    include(FindPkgConfig)

    unset(_verexp)

    if(LIBPROFILER_FIND_VERSION)

        if(LIBPROFILER_FIND_VERSION_EXACT)        

              set(_verexp "=${LIBPROFILER_FIND_VERSION}")

        else()

              set(_v
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值