TimeRecord.h 911 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //
  2. // Created by zx on 22-11-3.
  3. //
  4. #ifndef SRC_LIO_LIVOX_SRC_UTILS_TIMERECORD_H_
  5. #define SRC_LIO_LIVOX_SRC_UTILS_TIMERECORD_H_
  6. #include <chrono>
  7. #include <fstream>
  8. #include <map>
  9. #include <numeric>
  10. #include <string>
  11. #include <vector>
  12. class TimeRecord
  13. {
  14. public:
  15. struct Record {
  16. Record() = default;
  17. Record(const std::string& name, double time_usage) {
  18. func_name_ = name;
  19. time_usage_in_ms_.emplace_back(time_usage);
  20. }
  21. std::string func_name_;
  22. std::vector<double> time_usage_in_ms_;
  23. };
  24. template <class F>
  25. static void Evaluate(F&& func, const std::string& func_name);
  26. static void PrintAll();
  27. static void DumpIntoFile(const std::string& file_name);
  28. static double GetMeanTime(const std::string& func_name);
  29. private:
  30. static std::map<std::string, Record> records_;
  31. };
  32. #endif //SRC_LIO_LIVOX_SRC_UTILS_TIMERECORD_H_