簡體   English   中英

GitHub Actions CI 中的緩存命中率為 0.00 %

[英]Hit rate 0.00 % for cache in GitHub Actions CI

我有一個虛擬 C++ 項目,我有以下 github 操作配置:

name: CI

on: [push, pull_request] # on all pushes and PRs

jobs:
  dummy:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        distro: ["ros:foxy-ros-base-focal"]
    container:
      image: ${{ matrix.distro }}
    env:
      CCACHE_DIR: "${{ github.workspace }}/.ccache"
    steps:
      - uses: actions/checkout@v2
      - name: install ccache
        run: |
          sudo apt-get update -y
          sudo apt-get -qq install ccache
      - name: ccache cache
        uses: actions/cache@v2
        with:
          path: ${{ env.CCACHE_DIR }}
          key: ccache-${{ matrix.distro }}-${{github.run_id}}
          restore-keys: |
            ccache-${{ matrix.distro }}
      - name: ccache stats
        run: ccache -s
      - name: Build workspace
        run: |
          bash ./build_bridge.sh

我通過在CMakeLists.txt中添加/刪除庫來測試ccache ,但每次ccache命中率為 0%

cache directory                     /__w/action_test/action_test/.ccache
primary config                      /__w/action_test/action_test/.ccache/ccache.conf
secondary config      (readonly)    /etc/ccache.conf
cache hit (direct)                     0
cache hit (preprocessed)               0
cache miss                             0
cache hit rate                      0.00 %
cleanups performed                     0
files in cache                         0
cache size                           0.0 kB
max cache size                       5.0 GB

從中恢復緩存的上一個作業具有 output:

Post job cleanup.
/usr/bin/docker exec  b170bb77ebaac32aed0561984bb959d515d8a025b9329b6309b986f6b676c6c4 sh -c "cat /etc/*release | grep ^ID"
/usr/bin/tar --posix -z -cf cache.tgz -P -C /__w/action_test/action_test --files-from manifest.txt
Cache saved successfully

我需要做任何特定的事情來保存特定於 cmake 的緩存嗎?

CMake應該使用ccache的編譯器包裝參考:“在您的項目中啟用 ccache” 我將構建步驟修改為:

      - name: Build workspace
        run: |
          sudo /usr/sbin/update-ccache-symlinks
          export PATH="/usr/lib/ccache:$PATH"
          bash ./build_bridge.sh

CMake output:

-- Check for working C compiler: /usr/lib/ccache/cc -- works
-- Check for working CXX compiler: /usr/lib/ccache/c++ -- works

現在 ccache 統計數據看起來不錯

stats updated                       Wed Mar 31 17:30:50 2021
cache hit (direct)                     1
cache hit (preprocessed)               0
cache miss                            48
cache hit rate                      2.04 %
called for link                       41
cleanups performed                     0
files in cache                        94
cache size                          42.8 MB
max cache size                       5.0 GB

構建時間從 1 分鍾 ~20 秒減少到 24 秒。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM