Skip to content

Commit

Permalink
add gperftools for performance profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
feixh committed Sep 3, 2019
1 parent bd1aa37 commit 68ba653
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 34 deletions.
22 changes: 11 additions & 11 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(
Expand All @@ -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
Expand All @@ -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
)


Expand Down
52 changes: 33 additions & 19 deletions build.sh
Original file line number Diff line number Diff line change
@@ -1,28 +1,47 @@
#!/bin/bash
# Build script of XIVO software.
# Author: Xiaohan Fei ([email protected])
# 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)
Expand Down Expand Up @@ -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
Expand All @@ -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
9 changes: 5 additions & 4 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand All @@ -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
################################################################################
Expand Down
Empty file removed src/app/double_vio.cpp
Empty file.
13 changes: 13 additions & 0 deletions src/update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -17,6 +21,11 @@
namespace xivo {

void Estimator::Update() {

#ifdef USE_GPERFTOOLS
ProfilerStart();
#endif

if (instate_features_.empty() && oos_features_.empty())
return;

Expand Down Expand Up @@ -149,6 +158,10 @@ void Estimator::Update() {
timer_.Tock("update");

LOG(INFO) << "Error state absorbed";

#ifdef USE_GPERFTOOLS
ProfilerStop();
#endif
}

std::vector<FeaturePtr>
Expand Down

0 comments on commit 68ba653

Please sign in to comment.