279a3 HOWTO: FreeBSD with CCACHE - The FreeBSD Forums
The FreeBSD Forums  

Go Back   The FreeBSD Forums > Miscellaneous > Howtos & FAQs (Moderated)

Howtos & FAQs (Moderated) Would you like to share some of your solutions for certain problems? Tips or tricks? Post here. All new topics are automatically moderated.

Reply
 
Thread Tools Display Modes
  #1  
Old November 16th, 2008, 22:53
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,192
Thanks: 59
Thanked 633 Times in 349 Posts
Post HOWTO: FreeBSD with CCACHE

install ccache port or add a package:
Code:
# cd /usr/ports/devel/ccache && make install clean
# pkg_add -r ccache
add the following to /etc/make.conf:
Code:
.if !defined(NO_CCACHE)
  CC=  /usr/local/libexec/ccache/world-cc
  CXX= /usr/local/libexec/ccache/world-c++
.endif

.if ${.CURDIR:M*/ports/devel/ccache}
  NO_CCACHE= yes
.endif
add the following to /.cshrc:
Code:
# set ccache varibles
setenv PATH /usr/local/libexec/ccache:$PATH
setenv CCACHE_PATH /usr/bin:/usr/local/bin
setenv CCACHE_DIR /var/tmp/ccache
setenv CCACHE_LOGFILE /var/log/ccache.log

# set ccache temp size to 512MB (default 1GB)
if ( -x /usr/local/bin/ccache ) then
  /usr/local/bin/ccache -M 512m > /dev/null
endif
logout and login again before using ccache because when You dont ccache will use /root/.ccache dir instead of /var/tmp/ccache.

ccache can be shared between several computers the same as ports tree for example, check man ccache for more info.

ADDED 2007.2.15:
example ccache stats from my box.
Code:
% ccache -s
cache directory                     /var/tmp/ccache
cache hit                          18562
cache miss                        102820
called for link                     9824
multiple source files                 75
compile failed                      1610
preprocessor error                  1446
not a C/C++ file                    3747
autoconf compile/link              16982
unsupported compiler option          511
no input file                       6698
files in cache                     49631
cache size                         464.3 Mbytes
max cache size                     512.0 Mbytes
ADDED 2007.2.16:
comparasion of buildworld times with and without ccache:
Code:
# without ccache
make -j1 buildworld  4148.38s user 937.02s system 97% cpu 1:27:00.40 total

# with ccache
make -j1 buildworld  1043.30s user 703.76s system 88% cpu 32:50.02 total
If you face a problem with /root/.ccache being used instead of /var/tmp/ccache then you may solve it that way:

Code:
% cd /home/${USER}
% rm -rf .ccache
% ln -s /var/tmp/ccache .ccache
% ls -l .ccache
lrwxr-xr-x  1 ${USER}  ${USER}  15 Dec 19 15:20 .ccache -> /var/tmp/ccache
% ccache -s
cache directory                     /var/tmp/ccache
cache hit                         165292
cache miss                        327142
called for link                    38002
multiple source files                216
compile failed                      5182
preprocessor error                  4934
couldn't find the compiler             1
not a C/C++ file                   26249
autoconf compile/link              52665
unsupported compiler option         1379
no input file                      23289
files in cache                     79438
cache size                         530.2 Mbytes
max cache size                     512.0 Mbytes
% sudo ccache -s
cache directory                     /home/vermaden/.ccache
cache hit                         165292
cache miss                        327142
called for link                    38002
multiple source files                216
compile failed                      5182
preprocessor error                  4934
couldn't find the compiler             1
not a C/C++ file                   26249
autoconf compile/link              52665
unsupported compiler option         1379
no input file                      23289
files in cache                     79438
cache size                         530.2 Mbytes
max cache size                     512.0 Mbytes
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com

Last edited by vermaden; April 12th, 2010 at 22:49.
Reply With Quote
The Following 18 Users Say Thank You to vermaden For This Useful Post:
Alt (August 28th, 2009), Artefact2 (July 27th, 2009), ckeeper (May 6th, 2011), ckester (March 23rd, 2010), dennylin93 (July 27th, 2009), fraenki (January 7th, 2009), gnemmi (September 19th, 2009), graudeejs (April 23rd, 2009), leoandru (November 2nd, 2009), miggir (May 21st, 2013), nakal (November 25th, 2008), rbelk (February 12th, 2009), smooth (January 28th, 2009), troberts (August 18th, 2009), tuck (January 14th, 2009), Weaseal (January 2nd, 2009), z0ran (December 22nd, 2008), zeissoctopus (August 31st, 2012)
  #2  
Old November 17th, 2008, 09:19
kamikaze's Avatar
kamikaze kamikaze is offline
Member
 
Join Date: Nov 2008
Location: /earth/europe/germany
Posts: 366
Thanks: 6
Thanked 66 Times in 45 Posts
Default

<shameless advertising>
I'm using buildflags from sysutils/bsdadminscripts to do that. It also deals with using both, ccache and distcc at the same time.
</shameless advertising>

I have come to the conclusion that the default cache size of 1GB is way too low. At the moment I'm using 4GB:
Code:
# ccache -s
cache directory                     /root/.ccache
cache hit                         607814
cache miss                        993734
called for link                    76913
multiple source files                316
compile failed                     11642
preprocessor error                  7718
couldn't find the compiler             4
not a C/C++ file                   90356
autoconf compile/link              97184
unsupported compiler option        14339
no input file                      29725
files in cache                    269281
cache size                           3.6 Gbytes
max cache size                       4.0 Gbytes
As you can see I have a hit rate of ~38%, which is a pretty impressive number, I think. I don't know how mature that previous example is (ccache has to be in use for some time to bring benefits), but the shown 512MB cache only has a hit rate of ~15%
Reply With Quote
  #3  
Old November 17th, 2008, 09:43
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,192
Thanks: 59
Thanked 633 Times in 349 Posts
Default

Quote:
Originally Posted by kamikaze View Post
<shameless advertising>
I'm using buildflags from sysutils/bsdadminscripts to do that. It also deals with using both, ccache and distcc at the same time.
</shameless advertising>

I have come to the conclusion that the default cache size of 1GB is way too low. At the moment I'm using 4GB (...) As you can see I have a hit rate of ~38%, which is a pretty impressive number, I think. I don't know how mature that previous example is (ccache has to be in use for some time to bring benefits), but the shown 512MB cache only has a hit rate of ~15%
Thanks for tips, propably it was used for short period of time, the last stats from my post give these stats with 512MB size:
Code:
cache hit                         165292
cache miss                        327142
About 33% so not so bad.
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com
Reply With Quote
  #4  
Old November 17th, 2008, 10:10
kamikaze's Avatar
kamikaze kamikaze is offline
Member
 
Join Date: Nov 2008
Location: /earth/europe/germany
Posts: 366
Thanks: 6
Thanked 66 Times in 45 Posts
Default

More than 30% is very decent. Compiling OpenOffice would blow your cache apart, though. Everything useful would be flushed out. OpenOffice is the reason I stepped from 1GB to 4GB.
Reply With Quote
  #5  
Old November 17th, 2008, 10:16
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,192
Thanks: 59
Thanked 633 Times in 349 Posts
Default

Compiling OpenOffice is like suicide, I always use packages for such big blobs like that
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com

Last edited by vermaden; November 17th, 2008 at 10:24.
Reply With Quote
  #6  
Old November 17th, 2008, 10:27
kamikaze's Avatar
kamikaze kamikaze is offline
Member
 
Join Date: Nov 2008
Location: /earth/europe/germany
Posts: 366
Thanks: 6
Thanked 66 Times in 45 Posts
Default

You normally have to wait for a long time for new OOo packages. That's why I build them myself and share them.
Reply With Quote
  #7  
Old November 17th, 2008, 10:52
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,192
Thanks: 59
Thanked 633 Times in 349 Posts
Default

Propably I do not use OpenOffice that much to care about newest version, current 2.4 version seems to work fine.

Where do you keep your builds mate?

Maybe I will try them some day.
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com
Reply With Quote
  #8  
Old November 17th, 2008, 11:05
kamikaze's Avatar
kamikaze kamikaze is offline
Member
 
Join Date: Nov 2008
Location: /earth/europe/germany
Posts: 366
Thanks: 6
Thanked 66 Times in 45 Posts
Default

http://wiki.bsdforen.de/anwendungen/...iellen_paketen

I've switched over to 3, because it doesn't have the font rendering problems of the 2-branch.
Reply With Quote
  #9  
Old January 2nd, 2009, 02:15
Weaseal Weaseal is offline
Junior Member
 
Join Date: Nov 2008
Posts: 57
Thanks: 5
Thanked 6 Times in 4 Posts
Default

Is there an ad-hoc way to disable CCACHE? For example, something like:
Code:
make install clean WITHOUT_CCACHE=yes
Reply With Quote
  #10  
Old January 2nd, 2009, 02:44
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,192
Thanks: 59
Thanked 633 Times in 349 Posts
Default

like that mate:
# make NO_CACHE=yes install clean
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com
Reply With Quote
  #11  
Old January 14th, 2009, 08:15
kegf kegf is offline
Junior Member
 
Join Date: Nov 2008
Posts: 12
Thanks: 1
Thanked 1 Time in 1 Post
Default

change
Quote:
Originally Posted by vermaden View Post
Code:
.if !defined(NO_CACHE)
  CC=  /usr/local/libexec/ccache/world-cc
  CCX= /usr/local/libexec/ccache/world-cc++
.endif

.if ${.CURDIR:M*/ports/devel/ccache}
  NO_CCACHE= yes
.endif
to
Code:
.if !defined(NO_CACHE)
  CC=  /usr/local/libexec/ccache/world-cc
  CCX= /usr/local/libexec/ccache/world-c++
.endif

.if ${.CURDIR:M*/ports/devel/ccache}
  NO_CCACHE= yes
.endif
Reply With Quote
The Following User Says Thank You to kegf For This Useful Post:
smooth (January 28th, 2009)
  #12  
Old January 14th, 2009, 08:48
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,192
Thanks: 59
Thanked 633 Times in 349 Posts
Default

@kegf

Thanks.
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com
Reply With Quote
  #13  
Old February 13th, 2009, 21:30
Mel_Flynn Mel_Flynn is offline
Member
 
Join Date: Nov 2008
Location: Drachten, Netherlands
Posts: 379
Thanks: 7
Thanked 74 Times in 57 Posts
Default

Add a note:
You have to reinstall devel/libtool15 if it's installed, as changing CC/CXX will screw things up for it.

Adding the PATH change is not required and can create problems with lang/gcc* ports as dependencies, as it will add gcc## to $PATH and BUILD_DEPENDS will think it's installed, but once compilation starts it doesn't work.

I use:
:setenv=....<stripped other stuff>,CCACHE_DIR=/var/db/ccache/$:

in /etc/login.conf to make CCACHE_DIR independant of shell semantics and dot.profile files.

Finally the stats from my package builder:
Code:
cache directory                     /var/db/ccache/root
cache hit                         508615
cache miss                        379447
called for link                    66381
multiple source files                228
compile failed                     13214
ccache internal error                  2
preprocessor error                 21943
not a C/C++ file                   27067
autoconf compile/link             118453
unsupported compiler option         6337
no input file                      38147
files in cache                    650587
cache size                           8.6 Gbytes
max cache size                      10.0 Gbytes

Last edited by Mel_Flynn; February 13th, 2009 at 21:31. Reason: smilies code bleh
Reply With Quote
The Following User Says Thank You to Mel_Flynn For This Useful Post:
graudeejs (April 23rd, 2009)
  #14  
Old July 27th, 2009, 13:57
dennylin93 dennylin93 is offline
Member
 
Join Date: Dec 2008
Posts: 784
Thanks: 34
Thanked 103 Times in 71 Posts
Default

Quote:
Originally Posted by vermaden View Post
Code:
.if !defined(NO_CACHE)
  CC=  /usr/local/libexec/ccache/world-cc
  CCX= /usr/local/libexec/ccache/world-c++
.endif
A small question. It is CCX or CXX? In /usr/local/share/doc/ccache/ccache-howto-freebsd.txt, is's CXX.
Reply With Quote
  #15  
Old July 27th, 2009, 14:15
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,192
Thanks: 59
Thanked 633 Times in 349 Posts
Default

Its CXX.
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com
Reply With Quote
  #16  
Old July 27th, 2009, 23:38
Artefact2's Avatar
Artefact2 Artefact2 is offline
Junior Member
 
Join Date: Mar 2009
Location: France
Posts: 23
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thanks for this tip.

A little precision : if you use a non-csh shell, you have to edit the rc file of your shell, not /.cshrc. The syntax might change (export instead of setenv, ...).
Reply With Quote
  #17  
Old July 28th, 2009, 07:01
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,192
Thanks: 59
Thanked 633 Times in 349 Posts
Default

@Artefact2

That's obvious, but thanks for pointing it out.
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com
Reply With Quote
  #18  
Old August 22nd, 2009, 20:17
graudeejs's Avatar
graudeejs graudeejs is offline
Style(9) Addict
 
Join Date: Nov 2008
Location: Riga, Latvia
Posts: 4,523
Thanks: 422
Thanked 607 Times in 475 Posts
Default

My Stats:

I build OpenOffice.org-3.1 uncached (with ccache on) in about 10-11 hours

It took about 3h 40min to compile OOO3.1 when it was cached in ccache

My PC:
Pentium 4 HTT @ 3GHz
RAM: 2.5GB @ 400Mhz
on GELI encrypted zpool

Code:
killasmurf86 $ ccache -s
cache directory                     /var/db/ccache
cache hit                          79143
cache miss                        139100
called for link                    14059
multiple source files                 75
compile failed                      3599
ccache internal error                  1
preprocessor error                  2494
couldn't find the compiler             2
not a C/C++ file                    7095
autoconf compile/link              28680
unsupported compiler option          932
no input file                      10850
files in cache                    278200
cache size                           2.6 Gbytes
max cache size                       4.0 Gbytes

Last edited by graudeejs; August 23rd, 2009 at 07:29.
Reply With Quote
  #19  
Old September 26th, 2009, 21:38
nal nal is offline
Junior Member
 
Join Date: Nov 2008
Location: Russia, Orenburg
Posts: 13
Thanks: 1
Thanked 3 Times in 2 Posts
Default

Code:
# Allow CCACHE for PORTS only (the buildworld has error with CCACHE)
.if ${.CURDIR:M*/ports*}
.if exists(/usr/local/libexec/ccache/world-cc) && !defined(NO_CCACHE)
CC=/usr/local/libexec/ccache/world-cc
CXX=/usr/local/libexec/ccache/world-c++
.endif
CFLAGS= ...
CXXFLAGS=${CFLAGS}
...
...
.endif

Last edited by nal; September 27th, 2009 at 03:34.
Reply With Quote
  #20  
Old April 12th, 2010, 22:41
Seeker's Avatar
Seeker Seeker is offline
Member
 
Join Date: May 2009
Location: Europe/Croatia/Zagreb
Posts: 832
Thanks: 13
Thanked 11 Times in 10 Posts
Default

Quote:
Originally Posted by vermaden View Post
like that mate:
# make NO_CACHE=yes install clean
A lots of luniz here will just copy-paste it and hit a wall:
Code:
.if !defined(NO_CACHE)
  CC=  /usr/local/libexec/ccache/world-cc
  CXX= /usr/local/libexec/ccache/world-c++
.endif

.if ${.CURDIR:M*/ports/devel/ccache}
  NO_CCACHE= yes
.endif
Reply With Quote
  #21  
Old April 12th, 2010, 22:50
vermaden's Avatar
vermaden vermaden is offline
Giant Locked
 
Join Date: Nov 2008
Location: pl_PL.lodz
Posts: 2,192
Thanks: 59
Thanked 633 Times in 349 Posts
Default

@Seeker

Thanks, its also funny how long it was here without notifying
__________________
Religions, worst damnation of mankind.
"FreeBSD has always been the operating system that GNU/Linux should have been." Frank Pohlmann, IBM
http://vermaden.blogspot.com
Reply With Quote
  #22  
Old June 13th, 2010, 07:03
mfaridi's Avatar
mfaridi mfaridi is offline
Member
 
Join Date: Nov 2008
Location: Afghanistan
Posts: 622
Thanks: 161
Thanked 12 Times in 12 Posts
Default

my apace of /var is limit and I use this command
Code:
portmaster -D -r -w gettext
and I see ccache take many space of
Code:
/var
what happen when I delete all files in ccache folder , because I do not have many space ?
Reply With Quote
  #23  
Old June 13th, 2010, 09:30
dennylin93 dennylin93 is offline
Member
 
Join Date: Dec 2008
Posts: 784
Thanks: 34
Thanked 103 Times in 71 Posts
Default

Simply limit the size of your cache using # ccache -M

If you delete the files, your cache will be empty.
Reply With Quote
  #24  
Old August 9th, 2010, 07:26
Slade Slade is offline
Junior Member
 
Join Date: Jul 2010
Posts: 19
Thanks: 0
Thanked 5 Times in 3 Posts
Default

I'm wondering how I would go about using a new version of gcc (gcc45) with ccache. Right now I have just gcc45 running per the instructions at: http://www.freebsd.org/doc/en/articl...c/article.html

That works fine but how would I go about getting ccache to use that. It seems like the instructions are for the standard version of gcc that comes with FreeBSD.

My current /etc/make.conf
Code:
.if !empty(.CURDIR:M/usr/ports/*) && exists(/usr/local/bin/gcc45)
CC=gcc45
CXX=g++45
CPP=cpp45
CPUTYPE?=amd64
.endif
my current /etc/libmap.conf
Code:
libgcc_s.so.1   gcc45/libgcc_s.so.1
libgomp.so.1    gcc45/libgomp.so.1
libobjc.so.3    gcc45/libobjc.so.2
libssp.so.0     gcc45/libssp.so.0
libstdc++.so.6  gcc45/libstdc++.so.6
I've tried looking over the examples in this thread and the ccache-howto-freebsd.txt when I installed ccache from ports but I just don't know enough about the make process to figure out how to get it working with gcc45.
Reply With Quote
  #25  
Old August 9th, 2010, 14:16
oliverh's Avatar
oliverh oliverh is offline
Member
 
Join Date: Nov 2008
Location: 127.0.0.1
Posts: 557
Thanks: 51
Thanked 36 Times in 33 Posts
Default

Using e.g. USE_GCC= 4.5+ is sufficient to my understanding.

According to http://ftp2.pl.freebsd.org/pub/FreeB.../Mk/bsd.gcc.mk
__________________
What was the goal of the Linux community--to replace Windows? One can imagine higher aspirations., Bill Joy
Reply With Quote
Reply

Tags
ccache, kiss

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
HOWTO: FreeBSD CPU Scaling and Power Saving vermaden Howtos & FAQs (Moderated) 47 December 30th, 2011 15:25


All times are GMT +1. The time now is 23:28.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.
The mark FreeBSD is a registered trademark of The FreeBSD Foundation and is used by The FreeBSD Project with the permission of The FreeBSD Foundation.
Web protection and acceleration provided by CloudFlare
0