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.

test_minddata_analyse.py 2.8 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. # Copyright 2020 Huawei Technologies Co., Ltd
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. # ============================================================================
  15. """
  16. Function:
  17. Test profiler to watch the performance of training.
  18. Usage:
  19. pytest tests/ut/profiler
  20. """
  21. import os
  22. from mindinsight.profiler.analyser.analyser_factory import AnalyserFactory
  23. from tests.ut.profiler import BASE_SUMMARY_DIR
  24. class TestMinddataAnalyser:
  25. """Test minddata analyser module."""
  26. @classmethod
  27. def setup_class(cls):
  28. """Initialization before test case execution."""
  29. cls.summary_dir = os.path.join(BASE_SUMMARY_DIR, "normal_run")
  30. cls.profiler = os.path.join(cls.summary_dir, "profiler")
  31. def setup_method(self):
  32. """Setup before each test."""
  33. self._analyser = AnalyserFactory.instance().get_analyser(
  34. 'minddata', self.profiler, '1')
  35. def test_analyse_get_next_info_all(self):
  36. """Test analysing the get_next operation info for info_type="queue" """
  37. expect_queue_result = {
  38. "info": {"queue": [3, 2, 1]},
  39. "size": 3,
  40. "summary": {"queue_summary": {"empty_queue": 0}}
  41. }
  42. expect_time_result = {
  43. "info": {"get_next": [0.001, 0, 0.001]},
  44. "size": 3,
  45. "summary": {"time_summary": {"avg_cost": "0.0006666666666666666"}}
  46. }
  47. queue_result, time_result = self._analyser.analyse_get_next_info(info_type="all")
  48. assert expect_queue_result == queue_result
  49. assert expect_time_result == time_result
  50. def test_analyse_device_queue_info_all(self):
  51. """Test analysing the device_queue operation info for info_type="queue" """
  52. expect_queue_result = {
  53. "info": {"queue": [0]},
  54. "size": 1,
  55. "summary": {"queue_summary": {"empty_queue": 1, "full_queue": 0}}
  56. }
  57. expect_time_result = {
  58. "info": {"total_cost": [4], "push_cost": [4], "get_cost": [0]},
  59. "size": 1,
  60. "summary": {"time_summary": {"avg_cost": 4, "get_cost": 0, "push_cost": 4}}
  61. }
  62. queue_result, time_result = self._analyser.analyse_device_queue_info(info_type="all")
  63. assert expect_queue_result == queue_result
  64. assert expect_time_result == time_result