From 69288ec46b132881f77f6d893d3d947d6bebf94e Mon Sep 17 00:00:00 2001 From: wuying39 <921169248@qq.com> Date: Tue, 21 Oct 2025 09:58:15 +0800 Subject: [PATCH] add cache collect tool --- tools/cache_collect/CMakeLists.txt | 11 + tools/cache_collect/README.md | 144 ++++++++ tools/cache_collect/collect.cpp | 509 +++++++++++++++++++++++++++ tools/cache_collect/collect.h | 75 ++++ tools/cache_collect/collect_args.cpp | 153 ++++++++ tools/cache_collect/collect_args.h | 49 +++ tools/cache_collect/main.cpp | 28 ++ tools/cache_collect/utils.cpp | 52 +++ tools/cache_collect/utils.h | 29 ++ 9 files changed, 1050 insertions(+) create mode 100644 tools/cache_collect/CMakeLists.txt create mode 100644 tools/cache_collect/README.md create mode 100644 tools/cache_collect/collect.cpp create mode 100644 tools/cache_collect/collect.h create mode 100644 tools/cache_collect/collect_args.cpp create mode 100644 tools/cache_collect/collect_args.h create mode 100644 tools/cache_collect/main.cpp create mode 100644 tools/cache_collect/utils.cpp create mode 100644 tools/cache_collect/utils.h diff --git a/tools/cache_collect/CMakeLists.txt b/tools/cache_collect/CMakeLists.txt new file mode 100644 index 0000000..54a2a39 --- /dev/null +++ b/tools/cache_collect/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required (VERSION 3.12.0) +project(cache_collect) + +include_directories(${CMAKE_CURRENT_LIST_DIR}/../../output/include) +include_directories(${CMAKE_CURRENT_LIST_DIR}/../../util) +file(GLOB SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/*.cpp) + +add_executable(cache_collect ${SRC_FILES}) + +target_link_directories(cache_collect PRIVATE ${CMAKE_CURRENT_LIST_DIR}/../../output/lib) +target_link_libraries(cache_collect PRIVATE sym kperf) \ No newline at end of file diff --git a/tools/cache_collect/README.md b/tools/cache_collect/README.md new file mode 100644 index 0000000..7df18e8 --- /dev/null +++ b/tools/cache_collect/README.md @@ -0,0 +1,144 @@ +# Cache Collect Tool +### Description +This tool is designed to collect L2I cache, l2D cache infomation of go program. + +1. It generates statistics of hotspots from the function and instruction perspectives. + +2. It reports the L2I cache miss ratio, L2D cache miss ratio, and IPC (Instructions Per Cycle) for each process. + +In L2I cache collect mode, the corresponding data can be output as a txt file for BOLT in the work directory. +Format: 1 [funcName] [offset] [number] + +[number] is the sample count for [funcName] at [offset] + +### Build +Build the libkperf tool first: +``` +bash build.sh +``` + +then: +``` +cd tools/cache_collect +mkdir build && cd build +cmake .. +make +``` + +### Run +Use 'cache_collect --help/-h' to view the help information. + +``` + Usage: cache_collect --pid/-p [options] + + Required: + --pid/-p : Target process ID(s). Multiple IDs can be separated by ',' + Optional: + --duration/-d : Set collection time of hotspots. Unit: s, default: 10 + --level/-l : Set to 'inst' for instruction-level summary. Default: function-level summary + --mode/-m : Set to 'dcache' to collect L2D cache data. Default: L2I cache data + --interval/-i : Interval for reading the ring buffer. Unit: ms, default: 1000 + --frequency/-f : Sampling frequency, default: 1000 + --bolt/-b