diff --git a/CMakeLists.txt b/CMakeLists.txt index e598f1dcd501b2ca09273a0914ff4cdf66f8b0e1..ad0bad7fc3bb83aedab9fff6337b06110ceefe1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -191,6 +191,8 @@ if (WITH_LITE AND LITE_WITH_LIGHT_WEIGHT_FRAMEWORK) include(external/gtest) # download, build, install gtest include(ccache) # set ccache for compilation include(external/protobuf) # download, build, install protobuf + elseif (LITE_WITH_PROFILE) + include(external/gflags) # download, build, install gflags endif() # for opencl diff --git a/lite/core/CMakeLists.txt b/lite/core/CMakeLists.txt index d51a93971ff197b6073cc80774322ca151377659..42c3b9e5b8763ca5a0b5eb5acbbd4f02ad5470da 100644 --- a/lite/core/CMakeLists.txt +++ b/lite/core/CMakeLists.txt @@ -140,6 +140,8 @@ if (NOT LITE_ON_TINY_PUBLISH) add_subdirectory(mir) add_subdirectory(profile) add_subdirectory(arena) +elseif (LITE_WITH_PROFILE) + add_subdirectory(profile) endif() # for mobile, unnecessary to compile the following testings. diff --git a/lite/core/profile/CMakeLists.txt b/lite/core/profile/CMakeLists.txt index b7ddd810af46a25e2c331c2f0364a72f466dc636..700ff89ccdf2f103ada89c44d9888ce170126b02 100644 --- a/lite/core/profile/CMakeLists.txt +++ b/lite/core/profile/CMakeLists.txt @@ -5,5 +5,5 @@ endif() lite_cc_library(basic_profiler SRCS basic_profiler.cc DEPS gflags) lite_cc_test(test_basic_profiler SRCS basic_profiler_test.cc DEPS basic_profiler) -lite_cc_library(lite_profiler SRCS profiler.cc DEPS context) +lite_cc_library(lite_profiler SRCS profiler.cc DEPS context gflags) lite_cc_test(test_lite_timer SRCS test_timer.cc DEPS lite_profiler) diff --git a/lite/core/profile/profiler.cc b/lite/core/profile/profiler.cc index e09851388388a99db6bccd93a2da30b65e29d9a6..0fd0d3d5009504f1db9c52dd66897cec91c0fbe7 100644 --- a/lite/core/profile/profiler.cc +++ b/lite/core/profile/profiler.cc @@ -127,14 +127,16 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { // Title. if (concise) { ss << "Timing cycle = " << units_.front().Timer(type)->LapTimes().Size() - << std::endl; + << "\n"; ss << "===== Concise " << TypeStr.find(type)->second << " Profiler Summary: " << name_ << ", Exclude " << w - << " warm-ups =====" << std::endl; + << " warm-ups =====" + << "\n"; } else { ss << "===== Detailed " << TypeStr.find(type)->second << " Profiler Summary: " << name_ << ", Exclude " << w - << " warm-ups =====" << std::endl; + << " warm-ups =====" + << "\n"; } ss << setw(20) << left << "OperatorType" << " " << setw(30) << left << "KerneAttr(Place)" @@ -169,7 +171,7 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { << " " << setw(12) << left << "LocalWorkSize"; } #endif - ss << std::endl; + ss << "\n"; // Profile information. if (concise) { @@ -248,7 +250,7 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { << item.second.cl_max << " " << left << fixed << setprecision(2) << cl_percent << "% "; #endif - ss << std::endl; + ss << "\n"; // clang-format on } } else { @@ -310,7 +312,7 @@ std::string Profiler::Summary(Type type, bool concise, size_t w) { << unit.Character().global_work_size << " " << setw(12) << left << fixed << unit.Character().local_work_size; #endif - ss << std::endl; + ss << "\n"; } } return ss.str(); diff --git a/lite/tools/build.sh b/lite/tools/build.sh index 07456e48eff8236d465aaa2cfedbec95c2845e86..06da3e47e07caeda129de0f3fc9dd1f121921119 100755 --- a/lite/tools/build.sh +++ b/lite/tools/build.sh @@ -110,6 +110,10 @@ function make_tiny_publish_so { local lang=$3 local android_stl=$4 + if [ ${WITH_PROFILE} == "ON" ]; then + prepare_thirdparty + fi + cur_dir=$(pwd) build_dir=$cur_dir/build.lite.${os}.${abi}.${lang} if [ -d $build_dir ] @@ -134,6 +138,7 @@ function make_tiny_publish_so { -DLITE_ON_TINY_PUBLISH=ON \ -DANDROID_STL_TYPE=$android_stl \ -DLITE_BUILD_EXTRA=$BUILD_EXTRA \ + -DLITE_WITH_PROFILE=${WITH_PROFILE} \ -DLITE_WITH_CV=$BUILD_CV \ -DLITE_BUILD_TAILOR=$BUILD_TAILOR \ -DLITE_OPTMODEL_DIR=$OPTMODEL_DIR \ diff --git a/lite/tools/build_android.sh b/lite/tools/build_android.sh index 7f8cd218fdf8f8bccbd820c003b14e100588b850..13092593a86e1486448236aab1361b706b9a0e61 100755 --- a/lite/tools/build_android.sh +++ b/lite/tools/build_android.sh @@ -32,6 +32,8 @@ MEDIATEK_APU_SDK_ROOT="$(pwd)/apu_ddk" # Download APU SDK from https://paddlelit WITH_OPENCL=OFF # options of adding training ops WITH_TRAIN=OFF +# options of time profile +WITH_PROFILE=OFF # num of threads used during compiling.. readonly NUM_PROC=${LITE_BUILD_THREADS:-4} ##################################################################################################### @@ -146,6 +148,10 @@ function make_tiny_publish_so { prepare_opencl_source_code $workspace $build_dir fi + # 3rd party is needed when profile option is ON + if [ "${WITH_PROFILE}" == "ON" ]; then + prepare_thirdparty + fi local cmake_mutable_options=" -DLITE_BUILD_EXTRA=$WITH_EXTRA \ @@ -155,6 +161,7 @@ function make_tiny_publish_so { -DLITE_OPTMODEL_DIR=$OPTMODEL_DIR \ -DLITE_WITH_JAVA=$WITH_JAVA \ -DLITE_WITH_CV=$WITH_CV \ + -DLITE_WITH_PROFILE=$WITH_PROFILE \ -DLITE_WITH_NPU=$WITH_HUAWEI_KIRIN_NPU \ -DNPU_DDK_ROOT=$HUAWEI_KIRIN_NPU_SDK_ROOT \ -DLITE_WITH_APU=$WITH_MEDIATEK_APU \ @@ -329,6 +336,11 @@ function main { WITH_STRIP="${i#*=}" shift ;; + # ON or OFF, default OFF + --with_profile=*) + WITH_PROFILE="${i#*=}" + shift + ;; # string, absolute path to optimized model dir --opt_model_dir=*) OPTMODEL_DIR="${i#*=}"