How to record a job's memory usage

Docker executor users can output the max memory consumed by a job by adding the following step to their config:

- run:
   command: cat /sys/fs/cgroup/memory/memory.max_usage_in_bytes
   when: always

This step should be added as the last step in your job, to identify the max usage after all of the previous steps have completed.

This will be accurate if the job has one Docker image. Multiple Docker image builds will only report the memory usage of the primary image.

Memory usage will be reported in bytes. You can convert to GiB using your favorite search engine to check it against the amount of RAM available to your job, according to its assigned resource class.

This can help troubleshoot out-of-memory (OOM) errors. 

To log memory usage over time for both Docker and machine executors, you can also add this step as the first step in your job:

- run:
   command: |
     while true; do
       sleep 5
       ps auxwwf
       echo "======"
   background: true

Other enviroments may require a slightly different command.

for macOS you can use ps auxww, as the f parameter is not supported.

To get memory usage of the remote docker environment you can pass the ps command through SSH with ssh remote-docker ps auxwwf

Was this article helpful?
13 out of 17 found this helpful



Please sign in to leave a comment.