Merge lp:~michihenning/storage-framework/faster-header-tests into lp:storage-framework/devel

Proposed by Michi Henning
Status: Merged
Approved by: James Henstridge
Approved revision: 95
Merged at revision: 95
Proposed branch: lp:~michihenning/storage-framework/faster-header-tests
Merge into: lp:storage-framework/devel
Diff against target: 74 lines (+13/-10)
2 files modified
tests/headers/CMakeLists.txt (+2/-2)
tests/headers/compile_headers.py (+11/-8)
To merge this branch: bzr merge lp:~michihenning/storage-framework/faster-header-tests
Reviewer Review Type Date Requested Status
James Henstridge Approve
unity-api-1-bot continuous-integration Approve
Review via email: mp+311230@code.launchpad.net

Commit message

Don't use temporary file names for header test. This hugely speeds up the header compilation
tests if ccache is enabled.

Description of the change

Don't use temporary file names for header test. This hugely speeds up the header compilation
tests if ccache is enabled.

To post a comment you must log in.
Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:94
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/206/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1110
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1117
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/908
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/908/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/908
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/908/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/908
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/908/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/908
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/908/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/908
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/908/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/908
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/908/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/206/rebuild

review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

So when using ccache, this might do less work in the long run, but will do more work in the short term since you're not just checking the syntax.

As far as stable paths go, rather than generating a simple .cpp file that includes the header, couldn't you just try to compile the header directly?

review: Needs Information
Revision history for this message
Michi Henning (michihenning) wrote :

Removing -fsyntax-only means that no output is generated, and ccache won't cache anything, so everything gets re-compiled every time. It turns out that the code generation part of this costs essentially nothing. All the time is spent in parsing and semantic checks, and turning off -fsyntax-only doesn't save anything you would notice.

I guess we could change the script to compile the headers directly, yes.

95. By Michi Henning

Add test for double-inclusion of headers.

Revision history for this message
Michi Henning (michihenning) wrote :

I had a look at compiling the headers directly, but that is a lot more complex because the location of the header depends on the include path. It's way easier to just generate the source file and compile it like any other source file in the tree.

I made one change to the test script: it now #includes every header twice, to make sure that double-inclusion doesn't cause any problems.

I also tinkered with -fsyntax-only. It makes no perceptible difference in compilation speed. With the devel branch, it takes 29 seconds with and without this option.

Interestingly, with this branch, it only takes 25 seconds to run the header test with a cold ccache. I'm not sure where the 4-second difference comes from.

Once the cache is hot, it takes 1 second.

So, this is a big win, even without -fsyntax and without a warm ccache, and it is faster despite the double-inclusion of each header.

Revision history for this message
unity-api-1-bot (unity-api-1-bot) wrote :

PASSED: Continuous integration, rev:95
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/208/
Executed test runs:
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build/1127
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-0-fetch/1134
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/925
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=xenial+overlay/925/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/925
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=amd64,release=zesty/925/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/925
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=xenial+overlay/925/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/925
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=armhf,release=zesty/925/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/925
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=xenial+overlay/925/artifact/output/*zip*/output.zip
    SUCCESS: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/925
        deb: https://jenkins.canonical.com/unity-api-1/job/build-2-binpkg/arch=i386,release=zesty/925/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://jenkins.canonical.com/unity-api-1/job/lp-storage-framework-ci/208/rebuild

review: Approve (continuous-integration)
Revision history for this message
James Henstridge (jamesh) wrote :

Looks good.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/headers/CMakeLists.txt'
2--- tests/headers/CMakeLists.txt 2016-09-08 08:33:59 +0000
3+++ tests/headers/CMakeLists.txt 2016-11-21 01:32:18 +0000
4@@ -41,14 +41,14 @@
5 add_test(stand-alone-${location}-headers
6 ${CMAKE_CURRENT_SOURCE_DIR}/compile_headers.py
7 ${extra_defines}
8- ${public_inc_dir} ${CMAKE_CXX_COMPILER} "${CMAKE_CXX_COMPILER_ARG1} -fPIC -fsyntax-only -I${root_inc_dir} -I${public_inc_dir} ${other_inc_dirs} ${CMAKE_CXX_FLAGS} ${extra_inc_dirs}")
9+ ${public_inc_dir} ${CMAKE_CXX_COMPILER} "${CMAKE_CXX_COMPILER_ARG1} -fPIC -I${root_inc_dir} -I${public_inc_dir} ${other_inc_dirs} ${CMAKE_CXX_FLAGS} ${extra_inc_dirs}")
10
11 # Test that each internal header compiles stand-alone.
12 if (IS_DIRECTORY ${internal_inc_dir})
13 add_test(stand-alone-${location}-internal-headers
14 ${CMAKE_CURRENT_SOURCE_DIR}/compile_headers.py
15 ${extra_defines}
16- ${internal_inc_dir} ${CMAKE_CXX_COMPILER} "${CMAKE_CXX_COMPILER_ARG1} -fPIC -fsyntax-only -I${root_inc_dir} -I${internal_inc_dir} ${other_inc_dirs} ${CMAKE_CXX_FLAGS} ${extra_inc_dirs}")
17+ ${internal_inc_dir} ${CMAKE_CXX_COMPILER} "${CMAKE_CXX_COMPILER_ARG1} -fPIC -I${root_inc_dir} -I${internal_inc_dir} ${other_inc_dirs} ${CMAKE_CXX_FLAGS} ${extra_inc_dirs}")
18 endif()
19
20 if (NOT ${public_inc_dir} MATCHES "/internal/")
21
22=== modified file 'tests/headers/compile_headers.py'
23--- tests/headers/compile_headers.py 2016-08-22 04:35:33 +0000
24+++ tests/headers/compile_headers.py 2016-11-21 01:32:18 +0000
25@@ -52,7 +52,6 @@
26 import shlex
27 import subprocess
28 import sys
29-import tempfile
30 import concurrent.futures, multiprocessing
31
32 #
33@@ -74,16 +73,20 @@
34 #
35 def run_compiler(hdr, compiler, copts, define, verbose, hdr_dir):
36 try:
37- src = tempfile.NamedTemporaryFile(suffix='.cpp', dir='.')
38+ compile_dir = "./.header_tests"
39+ os.makedirs(compile_dir, exist_ok=True)
40+ src_name = os.path.join(compile_dir, hdr) + ".cpp"
41+
42+ if not os.path.exists(src_name):
43+ src_fd = os.open(src_name, os.O_WRONLY | os.O_CREAT)
44+ src = os.fdopen(src_fd, 'w')
45+ src.write("#include <" + hdr + ">" + "\n")
46+ src.write("#include <" + hdr + ">" + "\n") # To test that double-inclusion is safe
47
48 # Add any extra defines to the command line.
49 for flag in define:
50 copts = "-D" + flag + " " + copts
51
52- src.write(bytes("#include <" + hdr + ">" + "\n", 'UTF-8'))
53- src.flush() # Need this to make the file visible
54- src_name = os.path.join('.', src.name)
55-
56 if verbose:
57 print(compiler + " -c " + src_name + " " + copts)
58
59@@ -91,13 +94,13 @@
60 if status != 0:
61 message("cannot compile \"" + hdr + "\"") # Yes, write to stdout because this is expected output
62
63- obj = os.path.splitext(src_name)[0] + ".o"
64+ obj = hdr + ".o"
65 try:
66 os.unlink(obj)
67 except:
68 pass
69
70- gcov = os.path.splitext(src_name)[0] + ".gcno"
71+ gcov = hdr + ".gcno"
72 try:
73 os.unlink(gcov)
74 except:

Subscribers

People subscribed via source and target branches

to all changes: