Skip to content

Commit

Permalink
Add capability to flatdata-cpp for analysing data access patterns (#239)
Browse files Browse the repository at this point in the history
Add an option to analyse data access patterns:
* To provide analysis of data accessed from each resource
* bytes / pages accessed
* analysis of inefficient struct layout (e.g. members that are never accessed)
* Performance is not an objective, this will cause significant slowdowns

All of this will be a compile-time opt-in.

Example of output (based on flatdata benchmark)

```
===== flatdata debug statistics =====
Total pages: 185635
Usage statistics:
    benchmark.flatdata/edge_data(63.1573% of pages): 
        bytes [count]: 160073112 out of 480219352
        bytes [accessed]: 33.3333%
        pages [count]: 117242 out of 117241
        pages [data access]: 33.3331%
        unused struct members:
            byte   0 redundant: 100%
            byte   1 redundant: 100%
            byte   2 redundant: 100%
            byte   3 redundant: 100%
            byte   4 redundant: 100%
            byte   5 redundant: 100%
            byte   6 redundant: 100%
            byte   7 redundant: 100%
            byte  16 redundant: 100%
            byte  17 redundant: 100%
            byte  18 redundant: 100%
            byte  19 redundant: 100%
            byte  20 redundant: 100%
            byte  21 redundant: 100%
            byte  22 redundant: 100%
            byte  23 redundant: 100%
    benchmark.flatdata/adjacent_edges(21.0526% of pages): 
        bytes [count]: 160073112 out of 160073120
        bytes [accessed]: 100%
        pages [count]: 39081 out of 39080
        pages [data access]: 99.9983%
        unused struct members:
    benchmark.flatdata/nodes(15.7896% of pages): 
        bytes [count]: 40018288 out of 120054856
        bytes [accessed]: 33.3333%
        pages [count]: 29311 out of 29310
        pages [data access]: 33.3325%
        unused struct members:
            byte   0 redundant: 100%
            byte   1 redundant: 100%
            byte   2 redundant: 100%
            byte   3 redundant: 100%
            byte   4 redundant: 100%
            byte   5 redundant: 100%
            byte   6 redundant: 100%
            byte   7 redundant: 100%
```
  • Loading branch information
VeaaC authored Jun 7, 2023
1 parent 4dab673 commit abde70e
Show file tree
Hide file tree
Showing 7 changed files with 475 additions and 8 deletions.
12 changes: 9 additions & 3 deletions .github/workflows/cpp.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: flatdata-rs
name: flatdata-cpp
on:
push:
branches: [ master ]
Expand All @@ -12,6 +12,9 @@ env:
jobs:
GCC:
runs-on: ubuntu-latest
strategy:
matrix:
debug-stats: ["", "-DWITH_DEBUG_DATA_ACCESS_STATISTICS=ON"]
steps:
- uses: actions/checkout@v2
- name: Dependencies
Expand All @@ -20,9 +23,12 @@ jobs:
run: pip3 install ./flatdata-generator
- name: Build and Test
run: |
CC=gcc CXX=g++ flatdata-cpp/ci/build-and-test-cpp.sh
CC=gcc CXX=g++ EXTRA_CMAKE_ARGS=${{ matrix.debug-stats }} flatdata-cpp/ci/build-and-test-cpp.sh
Clang:
runs-on: ubuntu-latest
strategy:
matrix:
debug-stats: ["", "-DWITH_DEBUG_DATA_ACCESS_STATISTICS=ON"]
steps:
- uses: actions/checkout@v2
- name: Dependencies
Expand All @@ -31,4 +37,4 @@ jobs:
run: pip3 install ./flatdata-generator
- name: Build and Test
run: |
CC=clang CXX=clang++ flatdata-cpp/ci/build-and-test-cpp.sh
CC=clang CXX=clang++ EXTRA_CMAKE_ARGS=${{ matrix.debug-stats }} flatdata-cpp/ci/build-and-test-cpp.sh
5 changes: 5 additions & 0 deletions flatdata-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ add_library(flatdata STATIC ${FLATDATA_SOURCE})

set_target_properties(flatdata PROPERTIES POSITION_INDEPENDENT_CODE ON)

if(WITH_DEBUG_DATA_ACCESS_STATISTICS)
message(STATUS "WITH_DEBUG_DATA_ACCESS_STATISTICS enabled")
target_compile_definitions(flatdata PUBLIC DEBUG_DATA_ACCESS_STATISTICS)
endif()

target_include_directories(flatdata
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
PUBLIC $<INSTALL_INTERFACE:include>
Expand Down
4 changes: 2 additions & 2 deletions flatdata-cpp/ci/build-and-test-cpp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
set -ex
mkdir build
cd build
cmake ../flatdata-cpp -DCMAKE_CXX_FLAGS="-Wall -pedantic -Wextra"
cmake ../flatdata-cpp -DCMAKE_CXX_FLAGS="-Wall -pedantic -Wextra" $EXTRA_CMAKE_ARGS
make -j$(nproc)
make test
make test ARGS="--verbose"
Loading

0 comments on commit abde70e

Please sign in to comment.