Bazel cache analysis - magma/magma GitHub Wiki

Bazel cache analysis

Bazel uses remote and disk caches. In case you have to debug something cache related or want to monitor cache usage for different artifacts, then the easiest way to do is with BuildBuddy. It is free and can be used without creating an account.

Setup

Getting BuildBuddy flags

  1. Go to BuildBuddy
  2. "Get started for free"
  3. "Use BuildBuddy without an account"
  4. "Enable cache" -> "Full cache"
  5. Copy the provided build flags to your .bazelrc

The result should look similar to this:

build --bes_results_url=https://app.buildbuddy.io/invocation/
build --bes_backend=grpcs://remote.buildbuddy.io
build --remote_cache=grpcs://remote.buildbuddy.io
build --remote_timeout=3600

Removing other cache options

The .bazelrc should already contain some cache related setup. These should be removed so that it does not collide with what you just pasted there. Comment out any lines which start with one of the followings:

  1. build:disk_cache
  2. common:disk_cache
  3. build:remote_caching_ro
  4. build:remote_download_optimization
  5. run:remote_download_optimization
  6. import %workspace%/bazel/bazelrcs/cache.bazelrc

Remove any bazel caches from your system

  1. cd $MAGMA_ROOT
  2. bazel clean --expunge
  3. rm -rf .bazel-cache*
  4. git restore .bazel-cache-repo/.gitignore .bazel-cache/.gitignore

Using BuildBuddy

After the setup is done, you can execute a bazel build and it will use BuildBuddy as remote cache.

bazel build //lte/gateway/python/magma/monitord

The first build will fill up the caches and every subsequent build will read from these caches. Among the first few lines from the build there will be a line similar to this one:

INFO: Streaming build results to: https://app.buildbuddy.io/invocation/43d5d90e-9bbd-48e7-81d1-e08d77718d7d

You can follow the link and there you can find a lot of useful data about your build, for example how much cache and data was used.