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.

cpu_analyser.py 2.4 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. # Copyright 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 cpu base analyser."""
  16. from mindinsight.profiler.analyser.gpu_analyser import GpuAnalyser
  17. from mindinsight.profiler.common.validator import validate
  18. from mindinsight.profiler.common.exceptions.exceptions import ProfilerRawFileException
  19. from mindinsight.profiler.common.log import logger as log
  20. class CpuOpTypeAnalyser(GpuAnalyser):
  21. """Cpu operation type analyser."""
  22. _col_names = validate.CPU_TYPE_COL
  23. _csv_file_to_analyse = 'cpu_op_type_info_{}.csv'
  24. @staticmethod
  25. def _convert_field_type(row):
  26. """
  27. Convert the field type to the specific type.
  28. Args:
  29. row (list): One row data from parsed data.
  30. Returns:
  31. list, the converted data.
  32. """
  33. try:
  34. return [row[0], int(row[1]), int(row[2]), float(row[3]), float(row[4]), float(row[5])*100]
  35. except IndexError as err:
  36. log.exception(err)
  37. raise ProfilerRawFileException('failed to get HOST CPU operator type data.')
  38. class CpuOpInfoAnalyser(GpuAnalyser):
  39. """Cpu operation detail info analyser."""
  40. _col_names = validate.CPU_DETAIL_COL
  41. _csv_file_to_analyse = 'cpu_op_detail_info_{}.csv'
  42. @staticmethod
  43. def _convert_field_type(row):
  44. """
  45. Convert the field type to the specific type.
  46. Args:
  47. row (list): One row data from parsed data.
  48. Returns:
  49. list, the converted data.
  50. """
  51. try:
  52. return [row[0], row[1], row[2], row[3], int(row[4]), float(row[5]), float(row[6]), float(row[7]), row[8]]
  53. except IndexError as err:
  54. log.exception(err)
  55. raise ProfilerRawFileException('failed to get HOST CPU operator detail data.')