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_context.h 2.8 kB

5 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /**
  2. * Copyright 2019-2020 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_PROFILING_CONTEXT_H_
  17. #define MINDSPORE_PROFILING_CONTEXT_H_
  18. #include <sys/syscall.h>
  19. #include <unistd.h>
  20. #include <atomic>
  21. #include <cstdint>
  22. #include <unordered_map>
  23. #include "profiler/device/ascend/ascend_profiling.h"
  24. namespace mindspore {
  25. namespace profiler {
  26. namespace ascend {
  27. inline pid_t GetTid() {
  28. thread_local static pid_t tid = syscall(__NR_gettid);
  29. return tid;
  30. }
  31. #define RECORD_PROFILING_EVENT(profiler, evt_type, fmt, category, node_name, ...) \
  32. do { \
  33. if (profiler != nullptr) { \
  34. if (node_name != nullptr) { \
  35. profiler->RecordEvent(evt_type, "tid:%lu [%s] [%s] " fmt, GetTid(), node_name, category, ##__VA_ARGS__); \
  36. } else { \
  37. profiler->RecordEvent(evt_type, "tid:%lu [%s] " fmt, GetTid(), category, ##__VA_ARGS__); \
  38. } \
  39. } \
  40. } while (0)
  41. #define RECORD_MODEL_EXECUTION_EVENT(profiler, fmt, ...) \
  42. RECORD_PROFILING_EVENT((profiler), kGeneral, fmt, "ModelExecutor", nullptr, ##__VA_ARGS__)
  43. #define RECORD_COMPILE_EVENT(profiler, name, fmt, ...) \
  44. RECORD_PROFILING_EVENT((profiler), kCompiler, fmt, "Compilation", name, ##__VA_ARGS__)
  45. #define RECORD_EXECUTION_EVENT(profiler, name, fmt, ...) \
  46. RECORD_PROFILING_EVENT((profiler), kExecution, fmt, "Execution", name, ##__VA_ARGS__)
  47. #define RECORD_CALLBACK_EVENT(profiler, name, fmt, ...) \
  48. RECORD_PROFILING_EVENT((profiler), kCallback, fmt, "Callback", name, ##__VA_ARGS__)
  49. } // namespace ascend
  50. } // namespace profiler
  51. } // namespace mindspore
  52. #endif // MINDSPORE_PROFILING_CONTEXT_H_