Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ARROW-28: Adding google's benchmark library to the toolchain #29

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,21 @@ if("${CMAKE_SOURCE_DIR}" STREQUAL "${CMAKE_CURRENT_SOURCE_DIR}")
option(ARROW_BUILD_TESTS
"Build the Arrow googletest unit tests"
ON)

option(ARROW_BUILD_BENCHMARKS
"Build the Arrow micro benchmarks"
ON)

endif()

if(NOT ARROW_BUILD_TESTS)
set(NO_TESTS 1)
endif()

if(NOT ARROW_BUILD_BENCHMARKS)
set(NO_BENCHMARKSS 1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

endif()


############################################################
# Compiler flags
Expand Down Expand Up @@ -335,13 +344,27 @@ if ("$ENV{GTEST_HOME}" STREQUAL "")
set(GTest_HOME ${THIRDPARTY_DIR}/googletest-release-1.7.0)
endif()

## Google Benchmark
if ("$ENV{GBENCHMARK_HOME}" STREQUAL "")
set(GBENCHMARK_HOME ${THIRDPARTY_DIR}/benchmark-1.0.0)
endif()


if(ARROW_BUILD_TESTS)
find_package(GTest REQUIRED)
include_directories(SYSTEM ${GTEST_INCLUDE_DIR})
ADD_THIRDPARTY_LIB(gtest
STATIC_LIB ${GTEST_STATIC_LIB})
endif()

if (ARROW_BUILD_BENCHMARKS)
find_package(GBenchmark REQUIRED)
include_directories(SYSTEM ${GBENCHMARK_INCLUDE_DIR})
ADD_THIRDPARTY_LIB(benchmark
STATIC_LIB ${GBENCHMARK_STATIC_LIB})

endif()

## Google PerfTools
##
## Disabled with TSAN/ASAN as well as with gold+dynamic linking (see comment
Expand Down
88 changes: 88 additions & 0 deletions cpp/cmake_modules/FindGBenchmark.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Tries to find Google benchmark headers and libraries.
#
# Usage of this module as follows:
#
# find_package(GBenchark)
#
# Variables used by this module, they can change the default behaviour and need
# to be set before calling find_package:
#
# GBenchmark_HOME - When set, this path is inspected instead of standard library
# locations as the root of the benchark installation.
# The environment variable GBENCHMARK_HOME overrides this veriable.
#
# This module defines
# GBENCHMARK_INCLUDE_DIR, directory containing benchmark header directory
# GBENCHMARK_LIBS, directory containing benchmark libraries
# GBENCHMARK_STATIC_LIB, path to libbenchmark.a
# GBENCHMARK_FOUND, whether gbenchmark has been found

if( NOT "$ENV{GBENCHMARK_HOME}" STREQUAL "")
file( TO_CMAKE_PATH "$ENV{GBENCHMARK_HOME}" _native_path )
list( APPEND _gbenchmark_roots ${_native_path} )
elseif ( GBenchmark_HOME )
list( APPEND _gbenchmark_roots ${GBenchmark_HOME} )
endif()

# Try the parameterized roots, if they exist
if ( _gbenchmark_roots )
find_path( GBENCHMARK_INCLUDE_DIR NAMES benchmark/benchmark.h
PATHS ${_gbenchmark_roots} NO_DEFAULT_PATH
PATH_SUFFIXES "include" )
find_library( GBENCHMARK_LIBRARIES NAMES benchmark
PATHS ${_gbenchmark_roots} NO_DEFAULT_PATH
PATH_SUFFIXES "lib" )
else ()
find_path( GBENCHMARK_INCLUDE_DIR NAMES benchmark/benchmark.hh )
find_library( GBENCHMARK_LIBRARIES NAMES benchmark )
endif ()


if (GBENCHMARK_INCLUDE_DIR AND GBENCHMARK_LIBRARIES)
set(GBENCHMARK_FOUND TRUE)
get_filename_component( GBENCHMARK_LIBS ${GBENCHMARK_LIBRARIES} DIRECTORY )
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change DIRECTORY to PATH here for cmake 2.8

set(GBENCHMARK_LIB_NAME libbenchmark)
set(GBENCHMARK_STATIC_LIB ${GBENCHMARK_LIBS}/${GBENCHMARK_LIB_NAME}.a)
else ()
set(GBENCHMARK_FOUND FALSE)
endif ()

if (GBENCHMARK_FOUND)
if (NOT GBenchmark_FIND_QUIETLY)
message(STATUS "Found the GBenchmark library: ${GBENCHMARK_LIBRARIES}")
endif ()
else ()
if (NOT GBenchmark_FIND_QUIETLY)
set(GBENCHMARK_ERR_MSG "Could not find the GBenchmark library. Looked in ")
if ( _gbenchmark_roots )
set(GBENCHMARK_ERR_MSG "${GBENCHMARK_ERR_MSG} in ${_gbenchmark_roots}.")
else ()
set(GBENCHMARK_ERR_MSG "${GBENCHMARK_ERR_MSG} system search paths.")
endif ()
if (GBenchmark_FIND_REQUIRED)
message(FATAL_ERROR "${GBENCHMARK_ERR_MSG}")
else (GBenchmark_FIND_REQUIRED)
message(STATUS "${GBENCHMARK_ERR_MSG}")
endif (GBenchmark_FIND_REQUIRED)
endif ()
endif ()

mark_as_advanced(
GBENCHMARK_INCLUDE_DIR
GBENCHMARK_LIBS
GBENCHMARK_LIBRARIES
GBENCHMARK_STATIC_LIB
)
1 change: 1 addition & 0 deletions cpp/setup_build_env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ SOURCE_DIR=$(cd "$(dirname "${BASH_SOURCE:-$0}")"; pwd)
source thirdparty/versions.sh

export GTEST_HOME=$SOURCE_DIR/thirdparty/$GTEST_BASEDIR
export GBENCHMARK_HOME=$SOURCE_DIR/thirdparty/$GBENCHMARK_BASEDIR

echo "Build env initialized"
22 changes: 20 additions & 2 deletions cpp/thirdparty/build_thirdparty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ else
for arg in "$*"; do
case $arg in
"gtest") F_GTEST=1 ;;
*) echo "Unknown module: $arg"; exit 1 ;;
"gbenchmark") F_GBENCHMARK=1 ;;
*) echo "Unknown module: $arg"; exit 1 ;;
esac
done
fi
Expand Down Expand Up @@ -47,19 +48,36 @@ export PATH=$PREFIX/bin:$PATH
type cmake >/dev/null 2>&1 || { echo >&2 "cmake not installed. Aborting."; exit 1; }
type make >/dev/null 2>&1 || { echo >&2 "make not installed. Aborting."; exit 1; }

STANDARD_DARWIN_FLAGS="-std=c++11 -stdlib=libc++ -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-value -Wno-ignored-attributes"

# build googletest
GOOGLETEST_ERROR="failed for googletest!"
if [ -n "$F_ALL" -o -n "$F_GTEST" ]; then
cd $TP_DIR/$GTEST_BASEDIR

if [[ "$OSTYPE" == "darwin"* ]]; then
CXXFLAGS=-fPIC cmake -DCMAKE_CXX_FLAGS="-std=c++11 -stdlib=libc++ -DGTEST_USE_OWN_TR1_TUPLE=1 -Wno-unused-value -Wno-ignored-attributes" || { echo "cmake $GOOGLETEST_ERROR" ; exit 1; }
CXXFLAGS=-fPIC cmake -DCMAKE_CXX_FLAGS="$STANDARD_DARWIN_FLAGS" || { echo "cmake $GOOGLETEST_ERROR" ; exit 1; }
else
CXXFLAGS=-fPIC cmake . || { echo "cmake $GOOGLETEST_ERROR"; exit 1; }
fi

make VERBOSE=1 || { echo "Make $GOOGLETEST_ERROR" ; exit 1; }
fi

# build google benchmark
GBENCHMARK_ERROR="failed for google benchmark"
if [ -n "$F_ALL" -o -n "$F_GBENCHMARK" ]; then
cd $TP_DIR/$GBENCHMARK_BASEDIR

CMAKE_CXX_FLAGS="--std=c++11"
if [[ "$OSTYPE" == "darwin"* ]]; then
CMAKE_CXX_FLAGS=$STANDARD_DARWIN_FLAGS
fi
CXXFLAGS=-fPIC cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=. -DCMAKE_CXX_FLAGS="$CMAKE_CXX_FLAGS" . || { echo "cmake $GBENCHMARK_ERROR" ; exit 1; }

make VERBOSE=1 install || { echo "make $GBENCHMARK_ERROR" ; exit 1; }
fi


echo "---------------------"
echo "Thirdparty dependencies built and installed into $PREFIX successfully"
6 changes: 6 additions & 0 deletions cpp/thirdparty/download_thirdparty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,9 @@ if [ ! -d ${GTEST_BASEDIR} ]; then
echo "Fetching gtest"
download_extract_and_cleanup $GTEST_URL
fi

echo ${GBENCHMARK_BASEDIR}
if [ ! -d ${GBENCHMARK_BASEDIR} ]; then
echo "Fetching google benchmark"
download_extract_and_cleanup $GBENCHMARK_URL
fi
4 changes: 4 additions & 0 deletions cpp/thirdparty/versions.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
GTEST_VERSION=1.7.0
GTEST_URL="https://github.com/google/googletest/archive/release-${GTEST_VERSION}.tar.gz"
GTEST_BASEDIR=googletest-release-$GTEST_VERSION

GBENCHMARK_VERSION=1.0.0
GBENCHMARK_URL="https://github.com/google/benchmark/archive/v${GBENCHMARK_VERSION}.tar.gz"
GBENCHMARK_BASEDIR=benchmark-$GBENCHMARK_VERSION