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.

minddata_proposer.py 5.5 kB

5 years ago
5 years ago
5 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. # Copyright 2020-2021 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. """The minddata proposer."""
  16. import os
  17. from collections import OrderedDict
  18. from mindinsight.profiler.analyser.analyser_factory import AnalyserFactory
  19. from mindinsight.profiler.analyser.minddata_analyser import MinddataAnalyser
  20. from mindinsight.profiler.proposer.allproposers.base_proposer import Proposer
  21. from mindinsight.profiler.common.log import logger as log
  22. from mindinsight.profiler.common.exceptions.exceptions import ProfilerRawFileException, ProfilerFileNotFoundException
  23. class MinddataProposer(Proposer):
  24. """The Minddata proposer."""
  25. def __init__(self, profiling_dir, device_id):
  26. super().__init__(profiling_dir, device_id)
  27. self.__proposer_type = "minddata"
  28. self.__proposal_dict = OrderedDict()
  29. def analyze(self, options=None):
  30. """
  31. Get the proposal from proposer.
  32. Args:
  33. options (dict): The options for proposer analysis.
  34. Returns:
  35. dict, the proposal from proposer instance,the dictionary key is a language internationalization
  36. label, and the value is used to format the value in the language internationalization string.
  37. Examples:
  38. >>> proposer_type = 'minddata'
  39. >>> proposer = ProposerFactory.instance().get_proposer(proposer_type, self.profiling_dir, self.device_id)
  40. >>> result = proposer.analyze(options)
  41. """
  42. self.minddata_outer_bounds_analyze()
  43. self.minddata_cpu_utilization_proposal()
  44. return self.__proposal_dict
  45. def minddata_outer_bounds_analyze(self):
  46. """Get the proposals of minddata outer bounds."""
  47. minddata_dict = OrderedDict()
  48. minddata_analyser = AnalyserFactory.instance().get_analyser(
  49. 'minddata', self.profiling_path, self.device_id)
  50. get_next_queue_info, _ = minddata_analyser.analyse_get_next_info(info_type="queue")
  51. device_queue_info, _ = minddata_analyser.analyse_device_queue_info(info_type="queue")
  52. result = MinddataAnalyser.analyse_queue_summary(get_next_queue_info, device_queue_info)
  53. if "get_next_queue_info" in result:
  54. get_next_queue_info_summary = result.get("get_next_queue_info").get("summary", {})
  55. empty_batch = get_next_queue_info_summary.get("empty_batch_count")
  56. total_batch = get_next_queue_info_summary.get("total_batch")
  57. minddata_dict["minddata_get_next_queue"] = [empty_batch, total_batch]
  58. self.__proposal_dict.update(minddata_dict)
  59. if "device_queue_info" in result:
  60. get_next_queue_info_summary = result.get("device_queue_info").get("summary", {})
  61. full_batch = get_next_queue_info_summary.get("full_batch_count", 0)
  62. empty_batch = get_next_queue_info_summary.get("empty_batch_count", 0)
  63. total_batch = get_next_queue_info_summary.get("total_batch", 0)
  64. minddata_dict["minddata_device_queue"] = [empty_batch, total_batch, full_batch, total_batch]
  65. self.__proposal_dict.update(minddata_dict)
  66. warning_op = list()
  67. for key, value in result.items():
  68. if isinstance(value, dict):
  69. status = value.get("status")
  70. if status == "warning":
  71. warning_op.append(key)
  72. if warning_op:
  73. minddata_dict["minddata_warning_op"] = [",".join(warning_op)]
  74. self.__proposal_dict.update(minddata_dict)
  75. def minddata_cpu_utilization_proposal(self):
  76. """Get the proposals of minddata cpu utilization"""
  77. filename = "minddata_cpu_utilization_{}.json".format(self.device_id)
  78. file_path = os.path.join(self.profiling_path, filename)
  79. # Forward compatibility, it is reasonable that the file does not exist.
  80. if not os.path.exists(file_path):
  81. return
  82. minddata_cpu_utilization = OrderedDict()
  83. minddata_cpu_utilization_analyser = AnalyserFactory.instance().get_analyser(
  84. 'minddata_cpu_utilization', self.profiling_path, self.device_id)
  85. try:
  86. idle_utilization_avg = minddata_cpu_utilization_analyser.get_idle_utilization_avg()
  87. # The maximum value of this cpu_activate_utilization_avg is 100%.
  88. cpu_activate_utilization_avg = 100 - idle_utilization_avg
  89. cpu_activate_utilization_threshold = 80
  90. if cpu_activate_utilization_avg > cpu_activate_utilization_threshold:
  91. minddata_cpu_utilization["minddata_cpu_utilization"] = [cpu_activate_utilization_avg]
  92. self.__proposal_dict.update(minddata_cpu_utilization)
  93. except (ProfilerRawFileException, ProfilerFileNotFoundException) as err:
  94. log.exception(err)