Ccache: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
(Created page with "(There didn't seem to be a good central source, so here goes… please update if you have anything to add!) = Basic steps = *Create a place for ccache to put its files. Ideall...")
 
(formatting)
Line 1: Line 1:
(There didn't seem to be a good central source, so here goes… please update if you have anything to add!)
[http://ccache.samba.org/ ccache] is a compiler cache for C and C++. It does what its function implies: caches the results of compilations. The net result: builds are faster!


= Basic steps =
==Installing==
ccache is typically available in your operating system's package manager of choice.


*Create a place for ccache to put its files. Ideally this should be on a separate disk with fast random access. I settled for a 4GB partition on my SSD.
On Mac:
*Install ccache. On a Mac: <tt>brew install ccache</tt>.<br>
*S<span style="display: none;" id="1311716903304E">&nbsp;</span>et the cache location:<br>
<pre>export CCACHEPATH=/usr/local/Cellar/ccache/3.1.4/libexec
export CCACHE_DIR=/Volumes/Scratch/ccache
</pre>
*Set the cache size:&nbsp;<tt>ccache --max-size 2GB</tt>, for example.
*Verify that ccache is being used: <tt>which gcc</tt> should show something like <tt>/usr/local/Cellar/ccache/3.1.4/libexec/gcc</tt>.
*Enable ccache in ~/.mozconfig:
<pre>mk_add_options --with-ccache=ccache
ac_add_options --with-ccache=/usr/local/bin/ccache
</pre>
(I'm not sure if both of those are necessary.)


Now running <tt>make -f client.mk</tt> in a Mozilla tree as usual should touch the cache:<br>
$ brew install ccache
<pre>$ ccache --show-stats
cache directory /Volumes/Scratch/ccache
cache hit (direct) 24969
cache hit (preprocessed) 16738
cache miss 207772
called for link 1407
compile failed 102
preprocessor error 122
bad compiler arguments 94
unsupported source language 111
autoconf compile/link 1629
unsupported compiler option 8626
no input file 625
files in cache 11340
cache size 1.8 Gbytes
max cache size 2.0 Gbytes
</pre>
<br>


= Related links  =
On Ubuntu:


$ apt-get install ccache
==Configuring ccache==
By default, ccache will put its cache in ''~/.ccache''. You can verify this by running:
$ ccache -s
That prints out the location of the current cache with some statistics.
You can modify the location of the cache via environment variables such as '''CCACHE_DIR'''. For more, see the man page (''man ccache'').
Like most anything that is I/O bound, ccache will benefit from having its cache on a fast I/O device, like an SSD. If you can, configure your cache to run off the fastest device you can. If you are using magnetic storage, put the cache on a separate spindle from the source tree you are building.
For example,
$ export CCACHE_DIR=/Volumes/Scratch/ccache
The default cache size is 1GB. A typical '''mozilla-central''' build of Firefox will fully saturate a cache of this size, evicting entries and thus lowering cache hit rate. You can modify the cache size as follows:
$ ccache --max-size 2GB
==Configuring Mozilla Builds==
To configure Mozilla builds to use ccache, you'll need to configure some make and configure options. In your ''.mozconfig'', add the following:
mk_add_options --with-ccache=ccache
ac_add_options --with-ccache=ccache
This will work as long as ccache is installed in the $PATH. If you want to be more proper, specify the full path to ccache:
mk_add_options --with-ccache=/usr/bin/ccache
ac_add_options --with-ccache=/usr/bin/ccache
Now, run a build and verify the cache is being utilized:
$ ccache -s
  cache directory                    /home/gps/.ccache
  cache hit (direct)                    0
  cache hit (preprocessed)              0
  cache miss                            0
  files in cache                        0
  cache size                            0 Kbytes
  max cache size                      2.0 Gbytes
$ make -f client.mk build
# in another shell, after the build has churned for a while:
$ ccache -s
  cache directory                    /home/gps/.ccache
  cache hit (direct)                    2
  cache hit (preprocessed)              7
  cache miss                          2044
  called for link                      27
  preprocessor error                    1
  unsupported source language            1
  autoconf compile/link                19
  unsupported compiler option            4
  files in cache                      6226
  cache size                        659.0 Mbytes
  max cache size                      2.0 Gbytes
== Related links==
*http://blog.lassey.us/2010/07/19/ccache-configure-option-for-mozilla/  
*http://blog.lassey.us/2010/07/19/ccache-configure-option-for-mozilla/  
*http://forums.mozillazine.org/viewtopic.php?f=42&amp;t=405015  
*http://forums.mozillazine.org/viewtopic.php?f=42&amp;t=405015  
*http://weblogs.mozillazine.org/darin/archives/005504.html
*http://weblogs.mozillazine.org/darin/archives/005504.html

Revision as of 19:38, 11 August 2011

ccache is a compiler cache for C and C++. It does what its function implies: caches the results of compilations. The net result: builds are faster!

Installing

ccache is typically available in your operating system's package manager of choice.

On Mac:

$ brew install ccache

On Ubuntu:

$ apt-get install ccache

Configuring ccache

By default, ccache will put its cache in ~/.ccache. You can verify this by running:

$ ccache -s

That prints out the location of the current cache with some statistics.

You can modify the location of the cache via environment variables such as CCACHE_DIR. For more, see the man page (man ccache).

Like most anything that is I/O bound, ccache will benefit from having its cache on a fast I/O device, like an SSD. If you can, configure your cache to run off the fastest device you can. If you are using magnetic storage, put the cache on a separate spindle from the source tree you are building.

For example,

$ export CCACHE_DIR=/Volumes/Scratch/ccache

The default cache size is 1GB. A typical mozilla-central build of Firefox will fully saturate a cache of this size, evicting entries and thus lowering cache hit rate. You can modify the cache size as follows:

$ ccache --max-size 2GB

Configuring Mozilla Builds

To configure Mozilla builds to use ccache, you'll need to configure some make and configure options. In your .mozconfig, add the following:

mk_add_options --with-ccache=ccache
ac_add_options --with-ccache=ccache

This will work as long as ccache is installed in the $PATH. If you want to be more proper, specify the full path to ccache:

mk_add_options --with-ccache=/usr/bin/ccache
ac_add_options --with-ccache=/usr/bin/ccache

Now, run a build and verify the cache is being utilized:

$ ccache -s
 cache directory                     /home/gps/.ccache
 cache hit (direct)                     0
 cache hit (preprocessed)               0
 cache miss                             0
 files in cache                         0
 cache size                             0 Kbytes
 max cache size                       2.0 Gbytes

$ make -f client.mk build
# in another shell, after the build has churned for a while:
$ ccache -s
 cache directory                     /home/gps/.ccache
 cache hit (direct)                     2
 cache hit (preprocessed)               7
 cache miss                          2044
 called for link                       27
 preprocessor error                     1
 unsupported source language            1
 autoconf compile/link                 19
 unsupported compiler option            4
 files in cache                      6226
 cache size                         659.0 Mbytes
 max cache size                       2.0 Gbytes

Related links