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.

ascend_profiling_test.cc 3.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /**
  2. * Copyright 2019 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 <iostream>
  17. #include <memory>
  18. #include "./prof_reporter.h"
  19. #include "common/common_test.h"
  20. #include "runtime/device/ascend/profiling/profiling_manager.h"
  21. #define private public
  22. #include "runtime/device/ascend/profiling/plugin_impl.h"
  23. #undef private
  24. #include "runtime/device/ascend/profiling/profiling_engine_impl.h"
  25. namespace mindspore {
  26. namespace device {
  27. namespace ascend {
  28. class stubReporter : public Reporter {
  29. public:
  30. stubReporter() = default;
  31. ~stubReporter() = default;
  32. int Report(const Msprof::Engine::ReporterData *data) override;
  33. int Flush() override;
  34. };
  35. int stubReporter::Report(const Msprof::Engine::ReporterData *data) { return 0; }
  36. int stubReporter::Flush() { return 0; }
  37. class TestAscendProfiling : public UT::Common {
  38. public:
  39. TestAscendProfiling() {}
  40. };
  41. TEST_F(TestAscendProfiling, test_profiling_GetJobId) {
  42. auto job_id = ProfilingManager::GetInstance().GetJobId();
  43. printf("get job_id:%ld\n", job_id);
  44. }
  45. int test_profiling_start() {
  46. (void)setenv("PROFILING_MODE", "true", 1);
  47. (void)setenv("PROFILING_OPTIONS", "training_trace:task_trace", 1);
  48. auto ret = ProfilingManager::GetInstance().StartupProfiling(0);
  49. (void)unsetenv("PROFILING_MODE");
  50. (void)unsetenv("PROFILING_OPTIONS");
  51. return ret;
  52. }
  53. TEST_F(TestAscendProfiling, test_profiling_start) {
  54. auto ret = test_profiling_start();
  55. ASSERT_EQ(ret, true);
  56. }
  57. int test_profiling_stop() {
  58. (void)setenv("PROFILING_MODE", "true", 1);
  59. auto engine = std::make_shared<ProfilingEngineImpl>();
  60. auto report = std::make_shared<stubReporter>();
  61. auto plug = engine->CreatePlugin();
  62. plug->Init(report.get());
  63. auto ret = ProfilingManager::GetInstance().StopProfiling();
  64. plug->UnInit();
  65. engine->ReleasePlugin(plug);
  66. (void)unsetenv("PROFILING_OPTIONS");
  67. return ret;
  68. }
  69. TEST_F(TestAscendProfiling, test_profiling_stop) {
  70. auto ret = test_profiling_stop();
  71. ASSERT_EQ(ret, true);
  72. }
  73. int test_profiling_rpt() {
  74. (void)setenv("PROFILING_MODE", "true", 1);
  75. std::map<uint32_t, std::string> op_taskId_map;
  76. op_taskId_map[1] = "add";
  77. op_taskId_map[2] = "mul";
  78. auto engine = std::make_shared<ProfilingEngineImpl>();
  79. auto report = std::make_shared<stubReporter>();
  80. auto plug = engine->CreatePlugin();
  81. plug->Init(report.get());
  82. ProfilingManager::GetInstance().ReportProfilingData(op_taskId_map);
  83. plug->UnInit();
  84. engine->ReleasePlugin(plug);
  85. (void)unsetenv("PROFILING_OPTIONS");
  86. return 0;
  87. }
  88. TEST_F(TestAscendProfiling, test_profiling_rpt) {
  89. auto ret = test_profiling_rpt();
  90. ASSERT_EQ(ret, false);
  91. }
  92. int test_profiling_rpt_abnormal() {
  93. std::map<uint32_t, std::string> op_taskId_map;
  94. ProfilingManager::GetInstance().ReportProfilingData(op_taskId_map);
  95. (void)setenv("PROFILING_MODE", "true", 1);
  96. ProfilingManager::GetInstance().ReportProfilingData(op_taskId_map);
  97. op_taskId_map[1] = "add";
  98. op_taskId_map[2] = "mul";
  99. ProfilingManager::GetInstance().ReportProfilingData(op_taskId_map);
  100. (void)unsetenv("PROFILING_OPTIONS");
  101. return 0;
  102. }
  103. TEST_F(TestAscendProfiling, test_profiling_rpt_abnormal) {
  104. auto ret = test_profiling_rpt_abnormal();
  105. ASSERT_EQ(ret, false);
  106. }
  107. } // namespace ascend
  108. } // namespace device
  109. } // namespace mindspore