From 68ba653fd50e27724c9103c5587400dc62ec4bb9 Mon Sep 17 00:00:00 2001 From: Xiaohan Fei Date: Tue, 3 Sep 2019 16:25:25 -0700 Subject: [PATCH] add gperftools for performance profiling --- CMakeLists.txt | 22 +++++++++--------- build.sh | 52 +++++++++++++++++++++++++++--------------- src/CMakeLists.txt | 9 ++++---- src/app/double_vio.cpp | 0 src/update.cpp | 13 +++++++++++ 5 files changed, 62 insertions(+), 34 deletions(-) delete mode 100644 src/app/double_vio.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 788f6226..1e666e14 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,17 +3,19 @@ project(feh) option(BUILD_ROSNODE "wrap the system in a rosnode" OFF) option(BUILD_G2O "build with g2o support" OFF) +option(USE_GPERFTOOLS "use gperf for performance profiling" OFF) + +if (USE_GPERFTOOLS) + add_definitions(-DUSE_GPERFTOOLS) +endif (USE_GPERFTOOLS) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O3 -std=c++17 -Wno-narrowing -Wno-register -fPIC -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=native -march=native") -# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -funroll-loops") -# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fopenmp") -# add_definitions(-DOMP_NUM_THREADS=4) -# set(CMAKE_BUILD_TYPE "RelWithDebInfo") -set(CMAKE_BUILD_TYPE "Release") +set(CMAKE_BUILD_TYPE "RelWithDebInfo") +# set(CMAKE_BUILD_TYPE "Release") add_definitions(-DNDEBUG) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/bin) @@ -23,11 +25,9 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/lib) # disable logging whose severity level is below the given integer # add_definitions(-DGOOGLE_STRIP_LOG=1) - # add_definitions(-DEIGEN_DEFAULT_TO_ROW_MAJOR) add_definitions(-DEIGEN_INITIALIZE_MATRICES_BY_ZERO) -# comment out the following line to disable NaN checks on Jacobians find_package(OpenCV REQUIRED) link_directories( @@ -36,11 +36,11 @@ link_directories( ${PROJECT_SOURCE_DIR}/thirdparty/glog/lib ${PROJECT_SOURCE_DIR}/thirdparty/Pangolin/lib ${PROJECT_SOURCE_DIR}/thirdparty/jsoncpp/lib - # ${PROJECT_SOURCE_DIR}/thirdparty/gperftools/lib - # /usr/local/lib + ${PROJECT_SOURCE_DIR}/thirdparty/gperftools/lib /usr/lib/x86_64-linux-gnu ) + include_directories( ${PROJECT_SOURCE_DIR}/common ${PROJECT_SOURCE_DIR}/src @@ -49,14 +49,14 @@ include_directories( ${PROJECT_SOURCE_DIR}/thirdparty/Pangolin/include ${PROJECT_SOURCE_DIR}/thirdparty/jsoncpp/include ${PROJECT_SOURCE_DIR}/thirdparty/eigen-3.3.7/include/eigen3 + ${PROJECT_SOURCE_DIR}/thirdparty/gperftools/include ${PROJECT_SOURCE_DIR}/thirdparty/pybind11/include ${JSONCPP_INCLUDE_DIRS} - # /usr/local/include/opencv2 /usr/include/opencv2 /usr/include/suitesparse + /usr/include # ${PROJECT_SOURCE_DIR}/thirdparty/libigl/include - # ${PROJECT_SOURCE_DIR}/thirdparty/gperftools/include ) diff --git a/build.sh b/build.sh index 83503b83..8fdb9e62 100755 --- a/build.sh +++ b/build.sh @@ -1,28 +1,47 @@ #!/bin/bash +# Build script of XIVO software. +# Author: Xiaohan Fei (feixh@cs.ucla.edu) +# Basic usage: execute the script in terminal +# ./build.sh +# Options: +# 1) ros: build with ROS support +# 2) g2o: build with pose graph optimization from g2o library +# 3) gperf: use google performance profiling tools +# Example: +# ./build.sh ros g2o gperf # parsing options BUILD_ROSNODE=false BUILD_G2O=false +USE_GPERFTOOLS=false for arg in "$@" do - if [ "$arg" == "ros" ]; then + if [ $arg == "ros" ]; then BUILD_ROSNODE=true fi - if [ "$arg" == "g2o" ]; then + if [ $arg == "g2o" ]; then BUILD_G2O=true fi + + if [ $arg == "gperf" ]; then + USE_GPERFTOOLS=true + fi done -if [ "$BUILD_ROSNODE" = true ]; then +if [ $BUILD_ROSNODE = true ]; then echo "BUILD WITH ROS SUPPORT" fi -if [ "$BUILD_G2O" = true ]; then +if [ $BUILD_G2O = true ]; then echo "BUILD WITH G2O SUPPORT" fi +if [ $USE_GPERFTOOLS = true ]; then + echo "USE GOOGLE PERFORMANCE TOOLS (GPERFTOOLS) FOR PROFILING" +fi + # build dependencies PROJECT_DIR=$(pwd) @@ -65,13 +84,15 @@ cmake .. -DCMAKE_INSTALL_PREFIX=.. -DBUILD_SHARED_LIBS=TRUE make install -j # to build gperftools, need to install autoconf and libtool first -# sudo apt-get install autoconf libtool -# cd $PROJECT_DIR/thirdparty/gperftools -# ./autogen.sh -# ./configure --prefix=$PROJECT_DIR/thirdparty/gperftools -# make install +if [ $USE_GPERFTOOLS = true ]; then + sudo apt-get install autoconf libtool + cd $PROJECT_DIR/thirdparty/gperftools + ./autogen.sh + ./configure --prefix=$PROJECT_DIR/thirdparty/gperftools + make install +fi -if [ "$BUILD_G2O" = true ]; then +if [ $BUILD_G2O = true ]; then cd $PROJECT_DIR/thirdparty/g2o mkdir build cd build @@ -84,13 +105,6 @@ fi mkdir ${PROJECT_DIR}/build cd ${PROJECT_DIR}/build -if [ "$BUILD_G2O" = true ] && [ "$BUILD_ROSNODE" = true ]; then - cmake .. -DBUILD_G2O=TRUE -DBUILD_ROSNODE=TRUE -elif [ "$BUILD_G2O" = true ]; then - cmake .. -DBUILD_G2O=TRUE -elif [ "$BUILD_ROSNODE" = true ]; then - cmake .. -DBUILD_ROSNODE=TRUE -else - cmake .. -fi +cmake .. -DBUILD_G2O=$BUILD_G2O -DBUILD_ROSNODE=$BUILD_ROSNODE -DUSE_GPERFTOOLS=$USE_GPERFTOOLS + make -j diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f51c2a58..e0984125 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -41,6 +41,10 @@ list(APPEND deps common ) +if (USE_GPERFTOOLS) + list(APPEND deps profiler) +endif (USE_GPERFTOOLS) + add_library(xapp SHARED estimator_process.cpp loader.cpp @@ -68,7 +72,7 @@ add_library(xest SHARED mm.cpp camera_manager.cpp imu.cpp) -target_link_libraries(xest ${deps}) # profiler) +target_link_libraries(xest ${deps}) set(libxivo xest xapp) @@ -83,9 +87,6 @@ endif(BUILD_G2O) add_executable(vio app/vio.cpp) target_link_libraries(vio ${libxivo} gflags::gflags) -# add_executable(double_vio app/double_vio.cpp) -# target_link_libraries(double_vio ${libxivo} gflags::gflags) - ################################################################################ # TOOLING ################################################################################ diff --git a/src/app/double_vio.cpp b/src/app/double_vio.cpp deleted file mode 100644 index e69de29b..00000000 diff --git a/src/update.cpp b/src/update.cpp index a0b800ed..8e967ec0 100644 --- a/src/update.cpp +++ b/src/update.cpp @@ -8,6 +8,10 @@ #include "absl/strings/str_format.h" #include "glog/logging.h" +#ifdef USE_GPERFTOOLS +#include "gperftools/profiler.h" +#endif + #include "estimator.h" #include "feature.h" #include "geometry.h" @@ -17,6 +21,11 @@ namespace xivo { void Estimator::Update() { + +#ifdef USE_GPERFTOOLS + ProfilerStart(); +#endif + if (instate_features_.empty() && oos_features_.empty()) return; @@ -149,6 +158,10 @@ void Estimator::Update() { timer_.Tock("update"); LOG(INFO) << "Error state absorbed"; + +#ifdef USE_GPERFTOOLS + ProfilerStop(); +#endif } std::vector