You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

profiling.cc 1.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /**
  2. * Copyright 2021 Huawei Technologies Co., Ltd
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #include "profiler/device/profiling.h"
  17. #include <time.h>
  18. #include <cxxabi.h>
  19. #include <cmath>
  20. #include "profiler/device/cpu/cpu_data_saver.h"
  21. #include "pybind_api/api_register.h"
  22. #include "utils/log_adapter.h"
  23. #include "utils/utils.h"
  24. namespace mindspore {
  25. namespace profiler {
  26. uint64_t Profiler::GetHostMonoTimeStamp() {
  27. struct timespec ts;
  28. #if defined(_WIN32) || defined(_WIN64)
  29. clock_gettime(CLOCK_MONOTONIC, &ts);
  30. #else
  31. clock_gettime(CLOCK_MONOTONIC_RAW, &ts);
  32. #endif
  33. constexpr uint64_t kNSecondInSecond = 1000000000;
  34. uint64_t cur_time_stamp = ts.tv_sec * kNSecondInSecond + ts.tv_nsec;
  35. return cur_time_stamp;
  36. }
  37. void Profiler::SetRunTimeData(const std::string &op_name, const float time_elapsed) {
  38. auto iter = op_info_map_.find(op_name);
  39. if (iter != op_info_map_.end()) {
  40. iter->second.op_host_cost_time += time_elapsed;
  41. }
  42. }
  43. void Profiler::SetRunTimeData(const std::string &op_name, const uint64_t start, const float duration) {
  44. auto iter = op_info_map_.find(op_name);
  45. if (iter != op_info_map_.end()) {
  46. iter->second.start_duration.emplace_back(StartDuration({start, duration}));
  47. }
  48. }
  49. } // namespace profiler
  50. } // namespace mindspore