This is minimalistic project showing problem I found out.
In paths below there are logs presenting my problem, generated before and after changing timestamp of header included in pch file:
Ccache settings:
run_second_cpp=true
depend_mode=true
direct_mode=true
file_clone=true
inode_cache=true
sloppiness=ivfsoverlay,modules,include_file_mtime,include_file_ctime,time_macros,pch_defines,clang_index_store,system_headers,locale
I prepared Dockerfile with clang
and qbs
to reproduce it.
To build docker use script (may take a while):
./docker_build.sh
To run docker's container with prepared image use:
./docker_run.sh
To build go to dir project
:
- Run script:
./qbs_install.sh
First build so obviously we cache no hits, ccache -s
output:
Summary:
Hits: 0 / 2 (0.00 %)
Direct: 0 / 2 (0.00 %)
Preprocessed: 0 / 2 (0.00 %)
Misses: 2
Direct: 2
Preprocessed: 2
Primary storage:
Hits: 0 / 3 (0.00 %)
Misses: 3
Cache size (GB): 0.01 / 20.00 (0.04 %)
- Delete previous build and build it again:
./qbs_install.sh
Now we have hits, ccache -s
output:
Summary:
Hits: 2 / 4 (50.00 %)
Direct: 2 / 4 (50.00 %)
Preprocessed: 0 / 2 (0.00 %)
Misses: 2
Direct: 2
Preprocessed: 2
Primary storage:
Hits: 4 / 7 (57.14 %)
Misses: 3
Cache size (GB): 0.01 / 20.00 (0.04 %)
- Here is where the problems begin, before next build change timestamp of headerfile and then build again:
touch common/common.hpp
./qbs_install.sh
Now again we have no hits, ccache -s
output:
Summary:
Hits: 2 / 6 (33.33 %)
Direct: 2 / 6 (33.33 %)
Preprocessed: 0 / 4 (0.00 %)
Misses: 4
Direct: 4
Preprocessed: 4
Primary storage:
Hits: 6 / 10 (60.00 %)
Misses: 4
Cache size (GB): 0.01 / 20.00 (0.04 %)
Above are logs from that scenario which leads to undesirable cache misses.
In project.qbs change value useWorkaround
to true
to use pch
files as prefix headers and just include them instead of using them as precompile headers.