Skip to content

Commit

Permalink
Use hardware accelerated CRC32C if platform library is present
Browse files Browse the repository at this point in the history
This enables non-couchbase server builds to also take advantage
of the performance benefits gained from the new hardware accelerated
CRC32C by just fetching the platform library.
For users who cannot fetch this library normal software CRC32 will
continue to work.
In many tests this improved performance by upto 10%

Change-Id: I7997e94239f8df0238e621de8f74b826b6a8654b
  • Loading branch information
hisundar authored and chiyoung committed Aug 27, 2015
1 parent 0c7d89b commit 6d0ca5b
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
couchstore_api/couchbench_fdb
build
coverage
platform
dummy2
errorlog.txt
forestdb_test
Expand Down
10 changes: 10 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@ else(COUCHBASE_SERVER_BUILD)
if (_JEMALLOC EQUAL 1)
INCLUDE(FindJemalloc)
endif(_JEMALLOC EQUAL 1)
if (EXISTS "${PROJECT_SOURCE_DIR}/platform/")
INCLUDE(CouchbaseCodeCoverage)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
INCLUDE (CMakePushCheckState)
include_directories(BEFORE ${CMAKE_CURRENT_BINARY_DIR}/platform/include)
ADD_SUBDIRECTORY(platform)
set(PLATFORM_LIBRARY platform)
ADD_DEFINITIONS(-D_CRC32C=1)
include_directories(AFTER ${PROJECT_SOURCE_DIR}/platform/include)
endif(EXISTS "${PROJECT_SOURCE_DIR}/platform/")
endif(COUCHBASE_SERVER_BUILD)

INCLUDE(FindAsyncIOLib)
Expand Down
69 changes: 69 additions & 0 deletions CouchbaseCodeCoverage.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# Support for running code coverage reporting.
#
# Usage:
# 1). Add a call to ADD_COVERAGE_REPORT() to the module(s) you wish to
# obtain code coverage reports on.
# 2). Enable the option CB_CODE_COVERAGE (e.g. pass -DCB_CODE_COVERAGE=ON to cmake).
# 3). Build as normal.
# 4). Run unit test(s) to exercise the codebase.
# 5). Run `make coverage-report-html` and/or `coverage-report-xml`
# (from the selected module subdirectory) to generate the reports.
# 6) (Optional) to zero coverage counters before a re-run run `make coverage-zero-counters`.


OPTION(CB_CODE_COVERAGE "Enable code coverage testing."
OFF)

IF (CB_CODE_COVERAGE)
FIND_PROGRAM(GCOV_PATH gcov)
FIND_PROGRAM(GCOVR_PATH gcovr)

IF (NOT GCOV_PATH)
MESSAGE(STATUS "gcov not found.")
ENDIF (NOT GCOV_PATH)

IF (NOT GCOVR_PATH)
MESSAGE(STATUS "gcovr [www.gcovr.com] not found.")
ENDIF ()

IF (NOT GCOV_PATH OR NOT GCOVR_PATH)
MESSAGE(FATAL_ERROR "CB_CODE_COVERAGE enabled but one of more required tools not found - cannot continue.")
ENDIF()
ENDIF(CB_CODE_COVERAGE)

# Defines a coverage report for the current module. If CB_CODE_COVERAGE is enabled,
# adds three new targets to that module:
# <project>-coverage-zero-counters: Zeros the code coverage counters for the module.
# <project>-coverage-report-html: Generates a code coverage report in HTML.
# <project>-coverage-report-xml: Generates a code coverage report in XML.
# Usage:
# 1) `make <project>-coverage-zero-counters` to clear any counters from
# previously-executed programs.
# 2) Run whatever programs to excercise the code (unit tests, etc).
# 3) `make <project>-coverage-report-{html,xml}` to generate a report.
#
FUNCTION(ENABLE_CODE_COVERAGE_REPORT)
GET_FILENAME_COMPONENT(_cc_project ${CMAKE_CURRENT_BINARY_DIR} NAME)

IF (CB_CODE_COVERAGE)
MESSAGE(STATUS "Setting up code coverage for ${PROJECT_NAME}")

ADD_CUSTOM_TARGET(${_cc_project}-coverage-zero-counters
COMMAND find . -name *.gcda -exec rm {} \;
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Zeroing coverage counters for objects in ${CMAKE_CURRENT_BINARY_DIR}"
VERBATIM)

ADD_CUSTOM_TARGET(${_cc_project}-coverage-report-html
COMMAND ${CMAKE_COMMAND} -E remove_directory coverage
COMMAND ${CMAKE_COMMAND} -E make_directory coverage
COMMAND ${GCOVR_PATH} --root=${CMAKE_SOURCE_DIR} --filter="${CMAKE_CURRENT_SOURCE_DIR}/.*" --html --html-details -o coverage/index.html
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating code coverage report for ${PROJECT_NAME} to ${CMAKE_CURRENT_BINARY_DIR}/coverage/index.html")

ADD_CUSTOM_TARGET(${_cc_project}-coverage-report-xml
COMMAND ${GCOVR_PATH} --root=${CMAKE_SOURCE_DIR} --filter="${CMAKE_CURRENT_SOURCE_DIR}/.*" --xml -o coverage.xml
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
COMMENT "Generating code coverage report for ${PROJECT_NAME} to ${CMAKE_CURRENT_BINARY_DIR}/coverage.xml")
ENDIF (CB_CODE_COVERAGE)
ENDFUNCTION()
8 changes: 8 additions & 0 deletions INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,11 @@ To run all the unit tests:
`make test_valgrind`

This target will run the tests and output the memory report to the console

* For hardware accelerated CRC32C which can improve ForestDB performance, please fetch the optional couchbase platform repository into the forestdb source directory before building.

`cd forestdb`

`git clone https://github.com/couchbase/platform.git`

`Follow the rest of the platform specific build instructions from above`

0 comments on commit 6d0ca5b

Please sign in to comment.