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

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