|
| 1 | +on: |
| 2 | + push: |
| 3 | + branches: |
| 4 | + - main |
| 5 | + |
| 6 | + pull_request: |
| 7 | + types: [opened, reopened, edited, synchronize] |
| 8 | + |
| 9 | +defaults: |
| 10 | + run: |
| 11 | + shell: bash -eux {0} |
| 12 | + |
| 13 | +jobs: |
| 14 | + generate_memory_flamegraph: |
| 15 | + name: Create flamegraph for scrape_flamegraph |
| 16 | + permissions: |
| 17 | + checks: write |
| 18 | + pull-requests: write |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@v4 |
| 22 | + |
| 23 | + - uses: actions/checkout@v4 |
| 24 | + with: |
| 25 | + repository: rust-lang/rustc-demangle |
| 26 | + path: rustc-demangle |
| 27 | + |
| 28 | + - uses: actions/checkout@v4 |
| 29 | + with: |
| 30 | + repository: KDE/heaptrack |
| 31 | + path: heaptrack |
| 32 | + |
| 33 | + - uses: actions/checkout@v4 |
| 34 | + with: |
| 35 | + repository: brendangregg/FlameGraph |
| 36 | + path: FlameGraph |
| 37 | + |
| 38 | + - name: Install Rust |
| 39 | + uses: actions-rust-lang/setup-rust-toolchain@v1 |
| 40 | + with: |
| 41 | + rustflags: "" |
| 42 | + |
| 43 | + - name: Install dependencies |
| 44 | + run: | |
| 45 | + sudo apt-get update |
| 46 | + sudo apt-get install -y \ |
| 47 | + build-essential libssl-dev pkg-config curl git \ |
| 48 | + cmake g++ libboost-dev libboost-iostreams-dev \ |
| 49 | + libboost-program-options-dev libdw-dev libelf-dev \ |
| 50 | + elfutils libunwind-dev zlib1g-dev binutils-dev \ |
| 51 | + libiberty-dev libdebuginfod-dev libboost-system-dev \ |
| 52 | + libboost-filesystem-dev libboost-thread-dev libboost-regex-dev |
| 53 | + cargo install rustfilt |
| 54 | +
|
| 55 | + - name: Build and install librustc_demangle.so |
| 56 | + run: | |
| 57 | + cd rustc-demangle |
| 58 | + cargo build -p rustc-demangle-capi --release |
| 59 | + sudo mv target/release/librustc_demangle.so /usr/lib |
| 60 | +
|
| 61 | + - name: Build and install heaptrack |
| 62 | + run: | |
| 63 | + cd heaptrack |
| 64 | + mkdir build && cd build |
| 65 | +
|
| 66 | + cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo -DCMAKE_INSTALL_PREFIX=/usr/local -DHEAPTRACK_USE_LIBUNWIND=ON -DHEAPTRACK_BUILD_PRINT_TRACES=ON |
| 67 | +
|
| 68 | + make -j$(nproc) |
| 69 | + sudo make install |
| 70 | +
|
| 71 | + - name: Build flamegraph |
| 72 | + run: | |
| 73 | + cargo build --profile profiling --test flamegraph_test |
| 74 | + env: |
| 75 | + RUSTFLAGS: "-C force-frame-pointers=yes -C symbol-mangling-version=v0" |
| 76 | + CARGO_PROFILE_RELEASE_DEBUG: true |
| 77 | + |
| 78 | + - name: Build heaptrack data |
| 79 | + run: | |
| 80 | + export TEST_BINARY=$(find "$GITHUB_WORKSPACE/target/profiling/deps" -name "flamegraph_test-*" -type f -executable | head -1) |
| 81 | +
|
| 82 | + if [ -z "$TEST_BINARY" ]; then |
| 83 | + echo "Error: Could not find test binary" |
| 84 | + exit 1 |
| 85 | + fi |
| 86 | +
|
| 87 | + "$TEST_BINARY" profile_with_flamegraph || echo "Test run exit code: #?" |
| 88 | +
|
| 89 | + heaptrack --output heaptrack-data "$TEST_BINARY" --ignored profile_with_flamegraph |
| 90 | + env: |
| 91 | + CARGO_MANIFEST_DIR: "$GITHUB_WORKSPACE/lustrefs-exporter" |
| 92 | + |
| 93 | + - name: Generate flamegraph |
| 94 | + run: | |
| 95 | + heaptrack_print --version |
| 96 | + HEAPTRACK_FILE=$(ls heaptrack-data.* | head -1) |
| 97 | +
|
| 98 | + echo "Writing flamegraph data to flamegraph-data.txt" |
| 99 | + heaptrack_print "$HEAPTRACK_FILE" -F flamegraph-data.txt > /dev/null |
| 100 | + echo "Done writing flamegraph data to flamegraph-data.txt: $?" |
| 101 | +
|
| 102 | + rustfilt < flamegraph-data.txt > demangled-flamegraph.txt |
| 103 | + awk '$NF > 1000' demangled-flamegraph.txt > significant_stacks.txt |
| 104 | + "$GITHUB_WORKSPACE/FlameGraph/flamegraph.pl" --colors mem --countname allocations < significant_stacks.txt > flamegraph.svg |
| 105 | +
|
| 106 | + - name: Upload flamegraph |
| 107 | + uses: actions/upload-artifact@v4 |
| 108 | + with: |
| 109 | + name: flamegraph |
| 110 | + path: "$GITHUB_WORKSPACEflamegraph.svg" |
| 111 | + |
0 commit comments