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

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