Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/ut/utils/show_kernel_debug_data/show_kernel_debug_data/__init__.py: 71%

28 statements  

« prev     ^ index     » next       coverage.py v7.15.2, created at 2026-07-27 14:38 +0800

1#!/usr/bin/python 

2# -*- coding: utf-8 -*- 

3# ---------------------------------------------------------------------------------------------------------- 

4# Copyright (c) 2025 Huawei Technologies Co., Ltd. 

5# This program is free software, you can redistribute it and/or modify it under the terms and conditions of 

6# CANN Open Software License Agreement Version 2.0 (the "License"). 

7# Please refer to the License for details. You may not use this file except in compliance with the License. 

8# THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, 

9# INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE. 

10# See LICENSE in the root of the software repository for the full text of the License. 

11# ---------------------------------------------------------------------------------------------------------- 

12 

13import sys 

14import os 

15from show_kernel_debug_data.dump_parser import ( 

16 parse_dump_bin, 

17 _collect_bin_files, 

18 _make_parser_output_dir, 

19) 

20from show_kernel_debug_data.dump_logger import DUMP_PARSER_LOG 

21 

22 

23def show_kernel_debug_data(bin_file_path: str, output_path: str = './'): 

24 if not bin_file_path or not os.path.exists(bin_file_path): 

25 raise RuntimeError(f'({bin_file_path}) file does not exist or permission denied!!!') 

26 if not os.path.isfile(bin_file_path) and not os.path.isdir(bin_file_path): 

27 raise RuntimeError(f'({bin_file_path}) is neither a file nor a directory!!!') 

28 

29 if not output_path: 

30 raise RuntimeError(f'({output_path}) directory does not exist or permission denied!!!') 

31 if os.path.exists(output_path): 

32 if not os.path.isdir(output_path): 

33 raise RuntimeError(f'({output_path}) is not a directory!!!') 

34 else: 

35 try: 

36 os.makedirs(output_path, exist_ok=True) 

37 except OSError as err: 

38 raise RuntimeError(f'({output_path}) directory does not exist or permission denied!!!') from err 

39 

40 dump_bins = _collect_bin_files(bin_file_path) 

41 if not dump_bins: 

42 raise RuntimeError(f'({bin_file_path}) does not contain any .bin file!!!') 

43 

44 if os.path.isdir(bin_file_path): 

45 parser_output_dir = _make_parser_output_dir(output_path) 

46 DUMP_PARSER_LOG.set_log_file(os.path.join(parser_output_dir, "parser.log")) 

47 DUMP_PARSER_LOG.set_log_level(os.environ.get('ASCEND_GLOBAL_LOG_LEVEL', '3')) 

48 for dump_bin in dump_bins: 

49 parse_dump_bin(dump_bin, output_path, parse_output_dir=parser_output_dir, init_logger=False) 

50 else: 

51 parse_dump_bin(dump_bins[0], output_path)