// // Created by zx on 22-11-3. // #ifndef SRC_LIO_LIVOX_SRC_UTILS_TIMERRECORD_H_ #define SRC_LIO_LIVOX_SRC_UTILS_TIMERRECORD_H_ #include #include #include #include #include #include #include #include struct FuncRecord { public: FuncRecord()=default; FuncRecord(std::string name,double time) { name_=name; timesqueue_.emplace_back(time); } std::string name_; std::vector timesqueue_; }; class TimerRecord { public: public: template inline static void Execute(F func, const std::string &func_name) { auto t1 = std::chrono::high_resolution_clock::now(); func(); auto t2 = std::chrono::high_resolution_clock::now(); auto time_used = std::chrono::duration_cast>(t2 - t1).count() * 1000; mutex_.lock(); if (records_.find(func_name) != records_.end()) { records_[func_name].timesqueue_.emplace_back(time_used); } else { records_.insert({func_name, FuncRecord(func_name, time_used)}); } mutex_.unlock(); } static void PrintAll(); protected: static std::mutex mutex_; static std::map records_; }; #endif //SRC_LIO_LIVOX_SRC_UTILS_TIMERRECORD_H_