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.1 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. namespace mindspore {
  30. namespace profiler {
  31. namespace cpu {
  32. const float kNanosecondToMillisecond = 1000000;
  33. class CPUProfiler : public Profiler {
  34. public:
  35. static std::shared_ptr<CPUProfiler> &GetInstance();
  36. CPUProfiler() = default;
  37. ~CPUProfiler() = default;
  38. CPUProfiler(const CPUProfiler &) = delete;
  39. CPUProfiler &operator=(const CPUProfiler &) = delete;
  40. void Init(const std::string &profileDataPath) override;
  41. void Stop() override;
  42. void StepProfilingEnable(const bool enable_flag) override;
  43. void OpDataProducerBegin(const std::string op_name, const uint32_t pid);
  44. void OpDataProducerEnd() override;
  45. private:
  46. void SetRunTimeData(const std::string &op_name, const uint32_t pid);
  47. void SaveProfileData() override;
  48. void ClearInst() override;
  49. static std::shared_ptr<CPUProfiler> profiler_inst_;
  50. uint64_t base_time_;
  51. std::string op_name_;
  52. uint32_t pid_;
  53. uint64_t op_time_start_;
  54. uint64_t op_time_mono_start_;
  55. uint64_t op_time_stop_;
  56. };
  57. } // namespace cpu
  58. } // namespace profiler
  59. } // namespace mindspore
  60. #endif // MINDSPORE_CCSRC_PROFILER_DEVICE_CPU_PROFILING_H