Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/cache_profiler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Profile the use of CPU caches

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:
runs-on: ubuntu-24.04

steps:
- uses: actions/checkout@v3

- name: Install Valgrind
run: |
sudo apt-get install -y valgrind
sudo apt-get install -y linux-tools-common linux-tools-generic

- name: Relax perf_event_paranoid
run: sudo sysctl kernel.perf_event_paranoid=-1

- name: Build test simulation
working-directory: ${{github.workspace}}/profiling
run: cmake -S . -B build && cmake --build build

- name: Profile using cachegrind
working-directory: ${{github.workspace}}/profiling
run: |
valgrind --tool=cachegrind ./cache.out
cg_annotate cachegrind.out.*

- name: Profile using perf
working-directory: ${{github.workspace}}/profiling
run: |
perf stat -B -e cache-references,cache-misses,cycles,instructions,branches ./cache.out
perf record ./cache.out
perf record -e cache-misses ./cache.out
perf report -v
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
# valgrind generated files
*vgcore.*
*massif.*
*cachegrind*

# perf generated files
*perf.data*

# profiling log files
*.log
Expand All @@ -29,4 +33,4 @@ examples/*.csv

# Utils generated folders
__pycache__
images
images
12 changes: 8 additions & 4 deletions profiling/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,21 @@ set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

# Set the C++ flags
string(APPEND CMAKE_CXX_FLAGS "-Wall -Wextra -Os")

# Set the folder for the executable
set(EXECUTABLE_OUTPUT_PATH ../)

# Define the executable
add_executable(prof.out main.cpp)
target_include_directories(prof.out PRIVATE ../src/)
target_compile_options(prof.out PRIVATE -pg)
target_compile_options(prof.out PRIVATE -pg -Os)
target_link_options(prof.out PRIVATE -pg)

add_executable(mem.out main.cpp)
target_include_directories(mem.out PRIVATE ../src/)
target_compile_options(mem.out PRIVATE -Os)

add_executable(parse_massif.out parse_massif.cpp)

add_executable(cache.out main.cpp)
target_include_directories(cache.out PRIVATE ../src/)
target_compile_options(cache.out PRIVATE -pg -O2)
Loading