From ca416b97db95f859441b8867d3dc5ece2811dde0 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 | 48 +++ tools/cache_collect/collect.cpp | 551 +++++++++++++++++++++++++++ tools/cache_collect/collect.h | 79 ++++ tools/cache_collect/collect_args.cpp | 152 ++++++++ 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, 999 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..1aed722 --- /dev/null +++ b/tools/cache_collect/README.md @@ -0,0 +1,48 @@ +# Cache Collect Tool +### Description +This tool is designed to collect L2I cache, l2D cache, and l3D cache infomation. + +1. It generates statistics of hotspots from the function and instruction perspectives. + +2. It reports the L2I cache miss ratio, L2D cache miss ratio, L3D cache miss ratio and IPC (Instructions Per Cycle) for each process. + +Before running the tool, please check the perf event list to comfirm whether l3D cache events are supported on your device. +If l3D cache is not supported, the related data will be excluded from collection and statistics. + +In L2I cache collect mode, the corresponding data will be output as a txt file for BOLT in the work directory. +Format: 1 [funcName] [offset] [data] + +### 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 and L3D 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