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.

cpu_profiling.h 2.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. #ifndef MINDSPORE_CCSRC_PROFILER_DEVICE_CPU_PROFILING_H
  17. #define MINDSPORE_CCSRC_PROFILER_DEVICE_CPU_PROFILING_H
  18. #include <algorithm>
  19. #include <cstdio>
  20. #include <map>
  21. #include <memory>
  22. #include <string>
  23. #include <unordered_map>
  24. #include <utility>
  25. #include "profiler/device/profiling.h"
  26. #if ENABLE_GPU
  27. #include "profiler/device/gpu/gpu_profiling.h"
  28. #endif
  29. #include "actor/actormgr.h"
  30. namespace mindspore {
  31. namespace profiler {
  32. namespace cpu {
  33. const float kNanosecondToMillisecond = 1000000;
  34. class CPUProfiler : public Profiler {
  35. public:
  36. static std::shared_ptr<CPUProfiler> &GetInstance();
  37. CPUProfiler() = default;
  38. ~CPUProfiler() = default;
  39. CPUProfiler(const CPUProfiler &) = delete;
  40. CPUProfiler &operator=(const CPUProfiler &) = delete;
  41. void Init(const std::string &profileDataPath) override;
  42. void Stop() override;
  43. void StepProfilingEnable(const bool enable_flag) override;
  44. void OpDataProducerBegin(const std::string op_name, const uint32_t pid);
  45. void OpDataProducerEnd() override;
  46. void OpDataProducerEndParallel(const std::string op_name);
  47. void OpDataProducerBeginParallel(const std::string op_name, const uint32_t pid);
  48. float SetRuntimeEnd(const std::string op_name, const uint64_t stop_timestamp);
  49. void SetRuntimeStart(const std::string op_name, const uint64_t start_timestamp);
  50. private:
  51. void SetRunTimeData(const std::string &op_name, const uint32_t pid, bool is_parallel = false);
  52. void SaveProfileData() override;
  53. void ClearInst() override;
  54. static std::shared_ptr<CPUProfiler> profiler_inst_;
  55. uint64_t base_time_;
  56. std::string op_name_;
  57. uint32_t pid_;
  58. uint64_t op_time_start_;
  59. uint64_t op_time_mono_start_;
  60. uint64_t op_time_stop_;
  61. };
  62. } // namespace cpu
  63. } // namespace profiler
  64. } // namespace mindspore
  65. #endif // MINDSPORE_CCSRC_PROFILER_DEVICE_CPU_PROFILING_H