环境搭建
项目根目录下
git clone https://github.com/wolfpld/tracy
cmake 配置
add_definitions("-DTRACY_ENABLE")
add_subdirectory(tracy)
include_directories(${TRACY_PUBLIC_DIR})
target_link_libraries(project TracyClient)
test.cpp
//#define TRACY_CALLSTACK // 收集调用栈
// #define TRACY_LIBUNWIND_BACKTRACE // use libunwind to perform callstack#define TRACY_FIBERS //线程监控#include "tracy/Tracy.hpp"
#include "tracy/TracyC.h"// Memory profiling
void * operator new ( std :: size_t count )
{auto ptr = malloc ( count );TracyAlloc ( ptr , count );return ptr ;
}
void operator delete ( void * ptr ) noexcept
{TracyFree ( ptr );free ( ptr );
}void test() {TracySetProgramName("test");ZoneScoped;TracyMessageL("Hello");// TracyAppInfo(text, size);TracyCZoneN(test, "test", true);FrameMarkStart (" Audio processing ");
// FrameMarkNamed(" Audio processing ");
// FrameImage(image, width, height, offset, flip);// TracyGpuZone("test");FrameMarkEnd (" Audio processing ");const char * fiber = " job1 ";TracyCZoneCtx zone ;std::thread t1([fiber]{TracyFiberEnter(fiber);TracyCZone(ctx, 1) ;TracyFiberLeave;});t1.join () ;}
抓包配置
工具下载
版本配对
运行
启动 tracy-profiler.exe
启动test.exe
点击connect采集
效果
参考
GitHub - wolfpld/tracy: Frame profiler
C++ tracy性能分析_tracy c++-CSDN博客
C++ prometheus性能分析-CSDN博客
gprof性能分析-CSDN博客