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_parser.py 4.5 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. """Minddata aicpu parser."""
  16. import os
  17. from mindspore.profiler.common.util import get_file_join_name, fwrite_format
  18. from mindspore import log as logger
  19. class MinddataParser:
  20. """Minddata Aicpu Parser."""
  21. @staticmethod
  22. def parse_minddata_aicpu_data(minddata_aicpu_source_path):
  23. """
  24. Parse minddata get_next info which contains queue size and execute time.
  25. Args:
  26. minddata_aicpu_source_path (str): the source file path.
  27. Returns:
  28. list[Union[str, float]], the converted data.
  29. """
  30. result = list()
  31. try:
  32. with open(minddata_aicpu_source_path) as source_data_file:
  33. source_data = source_data_file.read()
  34. step_data = source_data.split("\x00")
  35. for one_step in step_data:
  36. if one_step:
  37. node_info = one_step.split(", ")
  38. node_name, node_start, node_end, queue_size = "", 0, 0, 0
  39. if node_info:
  40. node_name = node_info[0].replace("Node:", "")
  41. if len(node_info) > 3 and "queue" in node_info[1]:
  42. queue_size = node_info[1].replace("queue size:", "")
  43. queue_size = int(queue_size) if queue_size.isdigit() else queue_size
  44. node_start = node_info[2].replace("Run start:", "")
  45. node_start = int(node_start) if node_start.isdigit() else node_start
  46. node_end = node_info[3].replace("Run end:", "")
  47. node_end = int(node_end) if node_end.isdigit() else node_end
  48. elif len(node_info) > 3 and "Run" in node_info[1]:
  49. queue_size = node_info[3].replace("queue size:", "")
  50. queue_size = int(queue_size) if queue_size.isdigit() else queue_size
  51. node_start = node_info[1].replace("Run start:", "")
  52. node_start = int(node_start) if node_start.isdigit() else node_start
  53. node_end = node_info[2].replace("Run end:", "")
  54. node_end = int(node_end) if node_end.isdigit() else node_end
  55. one_step_list = [node_name, node_start, node_end, queue_size]
  56. result.append(one_step_list)
  57. except OSError:
  58. logger.error("Open get_next profiling file error.")
  59. return result
  60. @staticmethod
  61. def execute(source_path, output_path, device_id):
  62. """
  63. Execute the parser.
  64. Args:
  65. source_path (str): the source file path.
  66. output_path (str): the output file path.
  67. device_id (str): the device id.
  68. """
  69. col_names = ["node_name", "start_time", "end_time", "queue_size"]
  70. minddata_aicpu_source_path = get_file_join_name(
  71. input_path=source_path, file_name='DATA_PREPROCESS.dev.AICPUMI')
  72. if not minddata_aicpu_source_path:
  73. minddata_aicpu_source_path = get_file_join_name(
  74. input_path=os.path.join(source_path, "data"), file_name='DATA_PREPROCESS.dev.AICPUMI')
  75. if not minddata_aicpu_source_path:
  76. return
  77. minddata_aicpu_output_path = os.path.join(output_path, "minddata_aicpu_" + device_id + ".txt")
  78. minddata_aicpu_data = MinddataParser.parse_minddata_aicpu_data(minddata_aicpu_source_path)
  79. if minddata_aicpu_data:
  80. fwrite_format(minddata_aicpu_output_path, " ".join(col_names), is_start=True)
  81. fwrite_format(minddata_aicpu_output_path, minddata_aicpu_data, is_start=True)