I want to make our standard build flags match what other projects tend to
supply. In submitting a patch for this (https://reviews.apache.org/r/26426/),
Ben Mahler asked for some numbers as to what effect the different
combinations of flags have.

Attached in testing_methodology.txt is the steps, build host config (AWS
c3.2xlarge running Ubuntu 14.04 64 bit, fresh install), and full results.
With each configuration I collected both the file size, as well as time to
build everything in mesos (But not actually run the testcases). The
attached diff was applied to remove the always appending '-O2 -g2' to
CXXFLAGS when --disable-optimize isn't specified.

*My Suggestions:*
Current default: -O2 -g2 (NOTE: -g2 is undocumented by GCC)
Suggested new default:
-O0 (my preference) or -O0 -g1 for developers
-O2 for release

I think -O0 should be the general default, which is overwritten whenever
CXXFLAGS is specified at any level (So that distribution packaging works
correctly). This gives us fast, small developer builds. And makes packaging
builds work correctly. Hand constructing packages I can add a '--release'
or '--mode=release' flag to configure so they get the right flags (If you
package natively for common distros CXXFLAGS and the like will be
automatically set to that distribution's packaging guidelines).

*What about backtraces? Coredumps? Will they be harder to read without a
'-g' flag?*
*NO. *Nothing inside of mesos will have a worse experience now. Only if you
attach external programs which actually use dwarf debug information (GDB,
AddressSanitizer, ThreadSanitizer, etc), will enabling debug information
(-g{1,3}) change their output significantly. For those cases, we can add a
'--debug' flag. which will cause the debug info to be emitted (Or you can
manually specify CXXFLAGS to provide the debug info. Everything internal
(Such as the glog backtraces on fatal messages), simply looks up the
function name and demangles it. The callsite line / file is passed by macro
and as a result always there.

More thorough information / explanation:
https://reviews.apache.org/r/26426/#comment_rc96919-56878

*Useful References:*
GCC Debug levels (Look at '-glevel'):
https://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html#Debugging-Options

Why debug info gets big (and bigger), it's effect on comple time:
https://gcc.gnu.org/wiki/DebugFission
diff --git a/3rdparty/libprocess/configure.ac b/3rdparty/libprocess/configure.ac
index 
ee482fcc312199823040798ac3c279d03d92c19f..89189e66d6f5f75b7028a2eae4b6a8ca47b97626
 100644
--- a/3rdparty/libprocess/configure.ac
+++ b/3rdparty/libprocess/configure.ac
@@ -468,15 +468,6 @@ AC_SUBST([PROTOBUF_JAR])
 AC_PROG_CXX([g++])
 AC_PROG_CC([gcc])

-# Check if we should try and enable optimizations.
-if test "x$enable_optimize" = "xyes"; then
-  # For now, we only turn on optimizations for gcc.
-  if test "x$GCC" = "xyes"; then
-    CXXFLAGS="$CXXFLAGS -g2 -O2"
-  fi
-fi
-
-
 # Check if clang was provided instead.
 AC_MSG_CHECKING([if compiling with clang])

diff --git a/configure.ac b/configure.ac
index 
bb4fee4e7c7497336d61d5a47da3667a9bc14ee5..097f78ac6492eb04cb8b6f55033d86f78ad3f48f
 100644
--- a/configure.ac
+++ b/configure.ac
@@ -267,15 +267,6 @@ AC_PROG_CXX([g++])
 AC_PROG_CC([gcc])


-# Check if we should try and enable optimizations.
-if test "x$enable_optimize" = "xyes"; then
-  # For now, we only turn on optimizations for gcc.
-  if test "x$GCC" = "xyes"; then
-    CXXFLAGS="$CXXFLAGS -g2 -O2"
-  fi
-fi
-
-
 # Attempt to use preinstalled dependencies instead of the bundled
 # versions in cases where the user specified their location
 # (--with-XXX=DIR) or asked us to attempt to detect them
######################################################################
General methodology:
######################################################################
Tests all run 10/22/2014

Host:
Amazon AWS c3.2xlarge: (8 vCPU, 15GiB RAM)
Ubuntu 14.04 64 bit
All tests run on instance SSD. 

If you run on a classic hard drive, the larger file sizes will make a much 
larger change in compile times.

Exact commands used for both machine preparation, and for each individual test 
are below in Test Steps.

Run time of the compile as well as disk usage of both the build directory and 
install directory are collected. I suspect the memory usage will vary roughly 
matching the file size variations, although I did not collect statistics on 
that.

Notes:
The first test was run twice to ensure that the disk caches could warm up (give 
it a level playing field), and maven dependencies were all installed locally / 
could be grabbed from the local cache.
Mesos and Libprocess configure.ac were patched to remove appending ‘-O2 -g2’ to 
CXXFLAGS when --disable-optimize isn’t specified
The current debug level flag mesos uses from GCC isn’t documented as a valid 
level.

In the ’-O2’ build, the install is still over 100MB by default. This is because 
of three things we are doing wrong in install:
1) Installing static library (54M: /lib/libmesos.a). Every major distro strips 
these out, it isn’t useful in practice. People should use the shared library or 
link directly against the .o files
2) Python native mesos egg is being built incorrectly. (21M: 
lib/python2.7/site-packages/mesos/native/_mesos.so). This should be a couple of 
KB and link against libmesos.so. Currently it contains all of libmesos.so in 
itself.
3) 20M: /lib/libmesos.so exports every symbol. If we made it only export the 
public mesos interface, then the size would be 2 MB or less. Doing so also 
enables far greater optimization inside of libmesos.

Not everything is built with the specified flags. Specifically, at least libev 
when bundled isn’t.


######################################################################
Test Steps
######################################################################

Prep
----------------------------------------------------------------------
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install build-essential openjdk-6-jdk python-dev python-boto 
libcurl4-nss-dev libsasl2-dev maven autoconf libtool git
sudo reboot

git clone http://git-wip-us.apache.org/repos/asf/mesos.git
cd mesos
#Apply the patch to remove the flag messing of --disable-optimize
git apply ~/enable_optimize_cxxflags.diff
./bootstrap
cd ../


Build
----------------------------------------------------------------------
mkdir build
cd build
$CONFIGURE_COMMAND
#Build line:
time make check -j8 GTEST_FILTER="asdfasdf"
#NOTE: Grab the timing info
make install

du -sh ../build ../install
#NOTE: Grab the sizes

cd ../
rm -rf build install


######################################################################
Results
######################################################################
----------------------------------------------------------------------
TEST: -O0
----------------------------------------------------------------------
CFLAGS='-O0' CXXFLAGS='-O0' ../mesos/configure --prefix=/mnt/build_test/install

real    11m54.824s
user    73m25.464s
sys     3m48.098s

1.9G    ../build
478M    ../install

----------------------------------------------------------------------
TEST: -O0 -g1
----------------------------------------------------------------------
CFLAGS='-O0 -g1' CXXFLAGS='-O0 -g1' ../mesos/configure 
--prefix=/mnt/build_test/install

real    12m20.722s
user    74m32.398s
sys     3m53.699s

2.7G    ../build
664M    ../install

----------------------------------------------------------------------
TEST: -O0 -g
----------------------------------------------------------------------
CFLAGS='-O0 -g' CXXFLAGS='-O0 -g' ../mesos/configure 
--prefix=/mnt/build_test/install

real    13m47.380s
user    83m27.045s
sys     4m28.014s

4.2G    ../build
1005M   ../install

----------------------------------------------------------------------
TEST: -O2
----------------------------------------------------------------------
CFLAGS='-O2' CXXFLAGS='-O2' ../mesos/configure --prefix=/mnt/build_test/install

real    14m8.224s
user    94m37.498s
sys     3m28.739s

578M    ../build
106M    ../install

----------------------------------------------------------------------
TEST: -O2 -g
----------------------------------------------------------------------
CFLAGS='-O2 -g' CXXFLAGS='-O2 -g' ../mesos/configure 
--prefix=/mnt/build_test/install
real    18m33.176s
user    119m27.640s
sys     4m36.252s

4.9G    ../build
980M    ../install

----------------------------------------------------------------------
TEST: -O2 -g1
----------------------------------------------------------------------
CFLAGS='-O2 -g1' CXXFLAGS='-O2 -g1' ../mesos/configure 
--prefix=/mnt/build_test/install

real    14m20.746s
user    96m33.797s
sys     3m35.859s

827M    ../build
166M    ../install

Reply via email to