diff --git a/.github/workflows/cache_profiler.yml b/.github/workflows/cache_profiler.yml new file mode 100644 index 00000000..032475f1 --- /dev/null +++ b/.github/workflows/cache_profiler.yml @@ -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 diff --git a/.gitignore b/.gitignore index 3de1a023..3bbcecca 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,10 @@ # valgrind generated files *vgcore.* *massif.* +*cachegrind* + +# perf generated files +*perf.data* # profiling log files *.log @@ -29,4 +33,4 @@ examples/*.csv # Utils generated folders __pycache__ -images \ No newline at end of file +images diff --git a/profiling/CMakeLists.txt b/profiling/CMakeLists.txt index 2b7e0bae..c79b67b8 100644 --- a/profiling/CMakeLists.txt +++ b/profiling/CMakeLists.txt @@ -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)