diff --git a/runtime/.gitignore b/runtime/.gitignore index 9aa98ef7d..a654dae49 100644 --- a/runtime/.gitignore +++ b/runtime/.gitignore @@ -4,3 +4,4 @@ engine/common/base/log.h tools/valgrind* *log fc_patch/* +test diff --git a/runtime/CMakeLists.txt b/runtime/CMakeLists.txt index 5d8469fbd..bdce2046e 100644 --- a/runtime/CMakeLists.txt +++ b/runtime/CMakeLists.txt @@ -63,9 +63,7 @@ option(WITH_TESTING "unit test" ON) ############################################################################### include(gflags) - include(glog) -add_dependencies(glog gflags) # gtest if(WITH_TESTING) diff --git a/runtime/cmake/glog.cmake b/runtime/cmake/glog.cmake index d45226181..cbb97d2d3 100644 --- a/runtime/cmake/glog.cmake +++ b/runtime/cmake/glog.cmake @@ -4,17 +4,18 @@ if(ANDROID) else() # UNIX add_definitions(-DWITH_GLOG) FetchContent_Declare( - extern_glog + glog URL https://paddleaudio.bj.bcebos.com/build/glog-0.4.0.zip URL_HASH SHA256=9e1b54eb2782f53cd8af107ecf08d2ab64b8d0dc2b7f5594472f3bd63ca85cdc ) - FetchContent_MakeAvailable(extern_glog) + FetchContent_MakeAvailable(glog) include_directories(${glog_BINARY_DIR} ${glog_SOURCE_DIR}/src) endif() -add_library(glog INTERFACE) if(ANDROID) + add_library(extern_glog INTERFACE) else() # UNIX - add_dependencies(gtest extern_glog) + add_dependencies(glog gflags) + add_library(extern_glog ALIAS glog) endif() \ No newline at end of file diff --git a/runtime/cmake/gtest.cmake b/runtime/cmake/gtest.cmake index 53336f101..6b1eda409 100644 --- a/runtime/cmake/gtest.cmake +++ b/runtime/cmake/gtest.cmake @@ -4,20 +4,22 @@ include(FetchContent) if(ANDROID) else() # UNIX FetchContent_Declare( - extern_gtest + gtest URL https://paddleaudio.bj.bcebos.com/build/gtest-release-1.11.0.zip URL_HASH SHA256=353571c2440176ded91c2de6d6cd88ddd41401d14692ec1f99e35d013feda55a ) - FetchContent_MakeAvailable(extern_gtest) + FetchContent_MakeAvailable(gtest) include_directories(${gtest_BINARY_DIR} ${gtest_SOURCE_DIR}/src) endif() -add_library(gtest INTERFACE) + if(ANDROID) + add_library(extern_gtest INTERFACE) else() # UNIX - add_dependencies(gtest extern_gtest) + add_dependencies(gtest gflags gflog) + add_library(extern_gtest ALIAS gtest) endif() if(WITH_TESTING) diff --git a/runtime/cmake/summary.cmake b/runtime/cmake/summary.cmake index 511c83974..fd47c6bd4 100644 --- a/runtime/cmake/summary.cmake +++ b/runtime/cmake/summary.cmake @@ -17,6 +17,8 @@ function(pps_summary) message(STATUS "*************PaddleSpeech Building Summary**********") message(STATUS " CMake version : ${CMAKE_VERSION}") message(STATUS " CMake command : ${CMAKE_COMMAND}") + message(STATUS " UNIX : ${UNIX}") + message(STATUS " ANDROID : ${ANDROID}") message(STATUS " System : ${CMAKE_SYSTEM_NAME}") message(STATUS " C++ compiler : ${CMAKE_CXX_COMPILER}") message(STATUS " C++ compiler version : ${CMAKE_CXX_COMPILER_VERSION}") diff --git a/runtime/engine/codelab/glog/CMakeLists.txt b/runtime/engine/codelab/glog/CMakeLists.txt index 08a98641f..492e33c61 100644 --- a/runtime/engine/codelab/glog/CMakeLists.txt +++ b/runtime/engine/codelab/glog/CMakeLists.txt @@ -1,8 +1,8 @@ cmake_minimum_required(VERSION 3.14 FATAL_ERROR) add_executable(glog_main ${CMAKE_CURRENT_SOURCE_DIR}/glog_main.cc) -target_link_libraries(glog_main glog) +target_link_libraries(glog_main extern_glog) add_executable(glog_logtostderr_main ${CMAKE_CURRENT_SOURCE_DIR}/glog_logtostderr_main.cc) -target_link_libraries(glog_logtostderr_main glog) +target_link_libraries(glog_logtostderr_main extern_glog) diff --git a/runtime/engine/common/base/CMakeLists.txt b/runtime/engine/common/base/CMakeLists.txt index fce31c72c..a49b78bdd 100644 --- a/runtime/engine/common/base/CMakeLists.txt +++ b/runtime/engine/common/base/CMakeLists.txt @@ -31,12 +31,12 @@ message(STATUS "Generated ${CMAKE_CURRENT_SOURCE_DIR}/log.h") if(ANDROID) -set(csrc - log_impl.cc - glog_utils.cc -) + set(csrc + log_impl.cc + glog_utils.cc + ) + add_library(base ${csrc}) else() # UNIX set(csrc) -endif() - -add_library(base ${csrc}) \ No newline at end of file + add_library(base INTERFACE) +endif() \ No newline at end of file diff --git a/runtime/engine/common/base/glog_utils.cc b/runtime/engine/common/base/glog_utils.cc index bd4f7f9cb..4ab3c2516 100644 --- a/runtime/engine/common/base/glog_utils.cc +++ b/runtime/engine/common/base/glog_utils.cc @@ -2,11 +2,11 @@ #include "base/glog_utils.h" namespace google { - void InitGoogleLogging(const char* name) { - LOG(INFO) << "dummpy InitGoogleLogging."; - } +void InitGoogleLogging(const char* name) { + LOG(INFO) << "dummpy InitGoogleLogging."; +} - void InstallFailureSignalHandler(){ - LOG(INFO) << "dummpy InstallFailureSignalHandler."; - } -} // namespace google +void InstallFailureSignalHandler() { + LOG(INFO) << "dummpy InstallFailureSignalHandler."; +} +} // namespace google diff --git a/runtime/engine/common/base/glog_utils.h b/runtime/engine/common/base/glog_utils.h index 17aebded4..9cffcafb0 100644 --- a/runtime/engine/common/base/glog_utils.h +++ b/runtime/engine/common/base/glog_utils.h @@ -3,7 +3,7 @@ #include "base/common.h" namespace google { - void InitGoogleLogging(const char* name); +void InitGoogleLogging(const char* name); - void InstallFailureSignalHandler(); -} // namespace google \ No newline at end of file +void InstallFailureSignalHandler(); +} // namespace google \ No newline at end of file diff --git a/runtime/engine/common/base/log_impl.cc b/runtime/engine/common/base/log_impl.cc index f7942554c..8286f1e70 100644 --- a/runtime/engine/common/base/log_impl.cc +++ b/runtime/engine/common/base/log_impl.cc @@ -8,84 +8,98 @@ static char __progname[] = "paddlespeech"; namespace log { -std::mutex LogMessage::lock_; +std::mutex LogMessage::lock_; std::string LogMessage::s_debug_logfile_(""); std::string LogMessage::s_info_logfile_(""); std::string LogMessage::s_warning_logfile_(""); std::string LogMessage::s_error_logfile_(""); std::string LogMessage::s_fatal_logfile_(""); - void LogMessage::get_curr_proc_info(std::string* pid, std::string* proc_name) { - std::stringstream ss; - ss << getpid(); - ss >> *pid; - *proc_name = ::ppspeech::__progname; +void LogMessage::get_curr_proc_info(std::string* pid, std::string* proc_name) { + std::stringstream ss; + ss << getpid(); + ss >> *pid; + *proc_name = ::ppspeech::__progname; } - LogMessage::LogMessage(const char* file, int line, Severity level, bool verbose, bool out_to_file /* = false */) : level_(level), verbose_(verbose), out_to_file_(out_to_file) { - - if (FLAGS_logtostderr == 0){ - stream_ = std::shared_ptr(&std::cout); - } else if (FLAGS_logtostderr == 1){ - stream_ = std::shared_ptr(&std::cerr); - }else if (out_to_file_){ - // logfile - lock_.lock(); - init(file, line); - } - } - - LogMessage:: ~LogMessage(){ - stream() << std::endl; - - if(out_to_file_){ - lock_.unlock(); - } - - if (level_ == FATAL){ - std::abort(); - } - } - - void LogMessage::init(const char* file, int line) { - time_t t = time(0); - char tmp[100]; - strftime(tmp, sizeof(tmp), "%Y%m%d-%H%M%S", localtime(&t)); - - if (s_info_logfile_.empty()) { - std::string pid; - std::string proc_name; - get_curr_proc_info(&pid, &proc_name); - - s_debug_logfile_ = std::string("log." + proc_name + ".log.DEBUG." + tmp + "." + pid); - s_info_logfile_ = std::string("log." + proc_name + ".log.INFO." + tmp + "." + pid); - s_warning_logfile_ = std::string("log." + proc_name + ".log.WARNING." + tmp + "." + pid); - s_error_logfile_ = std::string("log." + proc_name + ".log.ERROR." + tmp + "." + pid); - s_fatal_logfile_ = std::string("log." + proc_name + ".log.FATAL." + tmp + "." + pid); - } - - std::ofstream ofs; - if (level_ == DEBUG) { - stream_ = std::make_shared(s_debug_logfile_.c_str(), std::ios::out | std::ios::app); - // ofs.open(s_debug_logfile_.c_str(), std::ios::out | std::ios::app); - } else if (level_ == INFO) { - // ofs.open(s_warning_logfile_.c_str(), std::ios::out | std::ios::app); - stream_ = std::make_shared(s_warning_logfile_.c_str(), std::ios::out | std::ios::app); - } else if (level_ == WARNING) { - // ofs.open(s_warning_logfile_.c_str(), std::ios::out | std::ios::app); - stream_ = std::make_shared(s_warning_logfile_.c_str(), std::ios::out | std::ios::app); - } else if (level_ == ERROR) { - // ofs.open(s_error_logfile_.c_str(), std::ios::out | std::ios::app); - stream_ = std::make_shared(s_error_logfile_.c_str(), std::ios::out | std::ios::app); - } else { - // ofs.open(s_fatal_logfile_.c_str(), std::ios::out | std::ios::app); - stream_ = std::make_shared(s_fatal_logfile_.c_str(), std::ios::out | std::ios::app); - } - - // stream_ = &ofs; - - stream() << tmp << " " << file << " line " << line << "; "; - stream() << std::flush; - } -} // namespace log +LogMessage::LogMessage(const char* file, + int line, + Severity level, + bool verbose, + bool out_to_file /* = false */) + : level_(level), verbose_(verbose), out_to_file_(out_to_file) { + if (FLAGS_logtostderr == 0) { + stream_ = std::shared_ptr(&std::cout); + } else if (FLAGS_logtostderr == 1) { + stream_ = std::shared_ptr(&std::cerr); + } else if (out_to_file_) { + // logfile + lock_.lock(); + init(file, line); + } +} + +LogMessage::~LogMessage() { + stream() << std::endl; + + if (out_to_file_) { + lock_.unlock(); + } + + if (level_ == FATAL) { + std::abort(); + } +} + +void LogMessage::init(const char* file, int line) { + time_t t = time(0); + char tmp[100]; + strftime(tmp, sizeof(tmp), "%Y%m%d-%H%M%S", localtime(&t)); + + if (s_info_logfile_.empty()) { + std::string pid; + std::string proc_name; + get_curr_proc_info(&pid, &proc_name); + + s_debug_logfile_ = + std::string("log." + proc_name + ".log.DEBUG." + tmp + "." + pid); + s_info_logfile_ = + std::string("log." + proc_name + ".log.INFO." + tmp + "." + pid); + s_warning_logfile_ = + std::string("log." + proc_name + ".log.WARNING." + tmp + "." + pid); + s_error_logfile_ = + std::string("log." + proc_name + ".log.ERROR." + tmp + "." + pid); + s_fatal_logfile_ = + std::string("log." + proc_name + ".log.FATAL." + tmp + "." + pid); + } + + std::ofstream ofs; + if (level_ == DEBUG) { + stream_ = std::make_shared( + s_debug_logfile_.c_str(), std::ios::out | std::ios::app); + // ofs.open(s_debug_logfile_.c_str(), std::ios::out | std::ios::app); + } else if (level_ == INFO) { + // ofs.open(s_warning_logfile_.c_str(), std::ios::out | std::ios::app); + stream_ = std::make_shared( + s_warning_logfile_.c_str(), std::ios::out | std::ios::app); + } else if (level_ == WARNING) { + // ofs.open(s_warning_logfile_.c_str(), std::ios::out | std::ios::app); + stream_ = std::make_shared( + s_warning_logfile_.c_str(), std::ios::out | std::ios::app); + } else if (level_ == ERROR) { + // ofs.open(s_error_logfile_.c_str(), std::ios::out | std::ios::app); + stream_ = std::make_shared( + s_error_logfile_.c_str(), std::ios::out | std::ios::app); + } else { + // ofs.open(s_fatal_logfile_.c_str(), std::ios::out | std::ios::app); + stream_ = std::make_shared( + s_fatal_logfile_.c_str(), std::ios::out | std::ios::app); + } + + // stream_ = &ofs; + + stream() << tmp << " " << file << " line " << line << "; "; + stream() << std::flush; +} +} // namespace log } // namespace ppspeech \ No newline at end of file diff --git a/runtime/engine/common/base/log_impl.h b/runtime/engine/common/base/log_impl.h index 15315c6ed..935736205 100644 --- a/runtime/engine/common/base/log_impl.h +++ b/runtime/engine/common/base/log_impl.h @@ -13,27 +13,30 @@ // limitations under the License. // modified from https://github.com/Dounm/dlog -// modified form https://android.googlesource.com/platform/art/+/806defa/src/logging.h +// modified form +// https://android.googlesource.com/platform/art/+/806defa/src/logging.h #pragma once #include -#include +#include #include -#include #include -#include +#include +#include -#include #include +#include #include "base/common.h" #include "base/macros.h" +#ifndef WITH_GLOG #include "base/glog_utils.h" +#endif DECLARE_int32(logtostderr); -namespace ppspeech{ +namespace ppspeech { namespace log { @@ -47,57 +50,60 @@ enum Severity { }; class LogMessage { - public: - static void get_curr_proc_info(std::string* pid, std::string* proc_name); + public: + static void get_curr_proc_info(std::string* pid, std::string* proc_name); - LogMessage(const char* file, int line, Severity level, bool verbose, bool out_to_file = false); + LogMessage(const char* file, + int line, + Severity level, + bool verbose, + bool out_to_file = false); - ~LogMessage(); + ~LogMessage(); - std::ostream& stream() { return *stream_; } + std::ostream& stream() { return *stream_; } - private: - void init(const char* file, int line); + private: + void init(const char* file, int line); - private: - std::shared_ptr stream_; - Severity level_; - bool verbose_; - bool out_to_file_; + private: + std::shared_ptr stream_; + Severity level_; + bool verbose_; + bool out_to_file_; - static std::mutex lock_; // stream write lock - static std::string s_debug_logfile_; - static std::string s_info_logfile_; - static std::string s_warning_logfile_; - static std::string s_error_logfile_; - static std::string s_fatal_logfile_; + static std::mutex lock_; // stream write lock + static std::string s_debug_logfile_; + static std::string s_info_logfile_; + static std::string s_warning_logfile_; + static std::string s_error_logfile_; + static std::string s_fatal_logfile_; - DISALLOW_COPY_AND_ASSIGN(LogMessage); + DISALLOW_COPY_AND_ASSIGN(LogMessage); }; -} //namespace log - -} //namespace ppspeech +} // namespace log +} // namespace ppspeech #ifndef NDEBUG - #define DLOG_DEBUG ppspeech::log::LogMessage \ - (__FILE__, __LINE__, ppspeech::log::DEBUG, false) +#define DLOG_DEBUG \ + ppspeech::log::LogMessage(__FILE__, __LINE__, ppspeech::log::DEBUG, false) #else - #define DLOG_DEBUG ppspeech::log::LogMessage \ - (__FILE__, __LINE__, ppspeech::log::DEBUG, true) +#define DLOG_DEBUG \ + ppspeech::log::LogMessage(__FILE__, __LINE__, ppspeech::log::DEBUG, true) #endif -#define DLOG_INFO ppspeech::log::LogMessage \ - (__FILE__, __LINE__, ppspeech::log::INFO, true) -#define DLOG_WARNING ppspeech::log::LogMessage \ - (__FILE__, __LINE__, ppspeech::log::WARNING, true) -#define DLOG_ERROR ppspeech::log::LogMessage \ - (__FILE__, __LINE__, ppspeech::log::ERROR, true) -#define DLOG_FATAL ppspeech::log::LogMessage \ - (__FILE__, __LINE__, ppspeech::log::FATAL, true) +#define DLOG_INFO \ + ppspeech::log::LogMessage(__FILE__, __LINE__, ppspeech::log::INFO, true) +#define DLOG_WARNING \ + ppspeech::log::LogMessage(__FILE__, __LINE__, ppspeech::log::WARNING, true) +#define DLOG_ERROR \ + ppspeech::log::LogMessage(__FILE__, __LINE__, ppspeech::log::ERROR, true) +#define DLOG_FATAL \ + ppspeech::log::LogMessage(__FILE__, __LINE__, ppspeech::log::FATAL, true) #define DLOG_0 DLOG_DEBUG #define DLOG_1 DLOG_INFO @@ -110,8 +116,11 @@ class LogMessage { #define VLOG(verboselevel) LOG(verboselevel) -#define CHECK(exp) ppspeech::log::LogMessage \ - (__FILE__, __LINE__, ppspeech::log::FATAL, !(exp)).stream() << "Check Failed: " #exp +#define CHECK(exp) \ + ppspeech::log::LogMessage( \ + __FILE__, __LINE__, ppspeech::log::FATAL, !(exp)) \ + .stream() \ + << "Check Failed: " #exp #define CHECK_EQ(x, y) CHECK((x) == (y)) #define CHECK_NE(x, y) CHECK((x) != (y)) @@ -129,27 +138,19 @@ class LogMessage { #define DCHECK_GT(x, y) CHECK_GT(x, y) #else // NDEBUG #define DCHECK(condition) \ - while (false) \ - CHECK(condition) + while (false) CHECK(condition) #define DCHECK_EQ(val1, val2) \ - while (false) \ - CHECK_EQ(val1, val2) + while (false) CHECK_EQ(val1, val2) #define DCHECK_NE(val1, val2) \ - while (false) \ - CHECK_NE(val1, val2) + while (false) CHECK_NE(val1, val2) #define DCHECK_LE(val1, val2) \ - while (false) \ - CHECK_LE(val1, val2) + while (false) CHECK_LE(val1, val2) #define DCHECK_LT(val1, val2) \ - while (false) \ - CHECK_LT(val1, val2) + while (false) CHECK_LT(val1, val2) #define DCHECK_GE(val1, val2) \ - while (false) \ - CHECK_GE(val1, val2) + while (false) CHECK_GE(val1, val2) #define DCHECK_GT(val1, val2) \ - while (false) \ - CHECK_GT(val1, val2) + while (false) CHECK_GT(val1, val2) #define DCHECK_STREQ(str1, str2) \ - while (false) \ - CHECK_STREQ(str1, str2) + while (false) CHECK_STREQ(str1, str2) #endif \ No newline at end of file diff --git a/runtime/engine/common/base/macros.h b/runtime/engine/common/base/macros.h index 860e354e6..e60baf55a 100644 --- a/runtime/engine/common/base/macros.h +++ b/runtime/engine/common/base/macros.h @@ -24,7 +24,7 @@ #endif namespace ppspeech { - + // kSpaceSymbol in UTF-8 is: ▁ const char kSpaceSymbo[] = "\xe2\x96\x81"; diff --git a/runtime/engine/common/frontend/CMakeLists.txt b/runtime/engine/common/frontend/CMakeLists.txt index f73588af6..4ff3117c9 100644 --- a/runtime/engine/common/frontend/CMakeLists.txt +++ b/runtime/engine/common/frontend/CMakeLists.txt @@ -24,5 +24,5 @@ set(BINS foreach(bin_name IN LISTS BINS) add_executable(${bin_name} ${CMAKE_CURRENT_SOURCE_DIR}/${bin_name}.cc) target_include_directories(${bin_name} PRIVATE ${SPEECHX_ROOT} ${SPEECHX_ROOT}/kaldi) - target_link_libraries(${bin_name} PUBLIC frontend base utils kaldi-util gflags glog) -endforeach() + target_link_libraries(${bin_name} PUBLIC frontend base utils kaldi-util gflags extern_glog) +endforeach() \ No newline at end of file diff --git a/runtime/engine/common/frontend/compute_fbank_main.cc b/runtime/engine/common/frontend/compute_fbank_main.cc index 354283341..e022207d9 100644 --- a/runtime/engine/common/frontend/compute_fbank_main.cc +++ b/runtime/engine/common/frontend/compute_fbank_main.cc @@ -16,7 +16,6 @@ #include "base/flags.h" #include "base/log.h" -#include "base/log_impl.h" #include "frontend/audio_cache.h" #include "frontend/data_cache.h" #include "frontend/fbank.h" diff --git a/runtime/engine/common/matrix/kaldi-vector.cc b/runtime/engine/common/matrix/kaldi-vector.cc index 90817f0d4..1d0b55b96 100644 --- a/runtime/engine/common/matrix/kaldi-vector.cc +++ b/runtime/engine/common/matrix/kaldi-vector.cc @@ -584,7 +584,7 @@ template void VectorBase::CopyColFromMat(const MatrixBase &mat, // Real *data = data_; //// implement the function according to a dimension cutoff for computation -///efficiency +/// efficiency // if (num_rows <= 64) { // cblas_Xscal(dim, beta, data, 1); // const Real *m_data = M.Data(); @@ -605,7 +605,7 @@ template void VectorBase::CopyColFromMat(const MatrixBase &mat, // MatrixIndexT num_cols = M.NumCols(); //// implement the function according to a dimension cutoff for computation -///efficiency +/// efficiency // if (num_cols <= 64) { // for (MatrixIndexT i = 0; i < dim_; i++) { // double sum = 0.0; @@ -1224,7 +1224,7 @@ void Vector::Swap(Vector *other) { // for (MatrixIndexT i = 0; i < dim; i++, Mdata += M_row_stride, Ndata += // N_col_stride, data++) { //*data = beta * *data + alpha * cblas_Xdot(M_col_dim, Mdata, M_col_stride, -//Ndata, N_row_stride); +// Ndata, N_row_stride); //} //} diff --git a/runtime/engine/common/utils/process_utils.h b/runtime/engine/common/utils/process_utils.h new file mode 100644 index 000000000..97483b6f1 --- /dev/null +++ b/runtime/engine/common/utils/process_utils.h @@ -0,0 +1,29 @@ + +#pragma once + +#include +#include + +namespace ppspeech { + +pid_t GetPid() { + return getpid(); +} + +void GetPrpocessName(const pid_t pid, std::string& name){ + char tmp[256]; + sprintf(tmp, "/proc/%d/cmdline", pid); + + FILE* f = fopen(tmp, "r"); + if(f){ + size_t size; + size = fread(name.data(), sizeof(char), sizeof(tmp), f); + if(size > 0){ + if ('\n' == tmp[size-1]){ + tmp + } + } + } +} + +} // namespace ppspeech \ No newline at end of file diff --git a/runtime/engine/vad/CMakeLists.txt b/runtime/engine/vad/CMakeLists.txt index 75f6200d2..f1e6a6692 100644 --- a/runtime/engine/vad/CMakeLists.txt +++ b/runtime/engine/vad/CMakeLists.txt @@ -1,4 +1,4 @@ add_executable(infer_onnx_silero_vad ${CMAKE_CURRENT_SOURCE_DIR}/infer_onnx_silero_vad.cc wav.h vad.cc vad.h) # 添加FastDeploy库依赖 -target_link_libraries(infer_onnx_silero_vad ${FASTDEPLOY_LIBS} gflags glog) +target_link_libraries(infer_onnx_silero_vad ${FASTDEPLOY_LIBS} gflags extern_glog)