Coverage for /opt/cloud/slavespace/usr1/096471637100f3de0fcfc01072822a80/ut/src/asys/collect/stacktrace/interface.py: 100%
36 statements
« prev ^ index » next coverage.py v7.15.3, created at 2026-08-11 18:39 +0800
« prev ^ index » next coverage.py v7.15.3, created at 2026-08-11 18:39 +0800
1#!/usr/bin/env python3
2# -*- coding: utf-8 -*-
3# ----------------------------------------------------------------------------
4# Copyright (c) 2025 Huawei Technologies Co., Ltd.
5#
6# Licensed under the Apache License, Version 2.0 (the "License");
7# you may not use this file except in compliance with the License.
8# You may obtain a copy of the License at
9#
10# http://www.apache.org/licenses/LICENSE-2.0
11#
12# Unless required by applicable law or agreed to in writing, software
13# distributed under the License is distributed on an "AS IS" BASIS,
14# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15# See the License for the specific language governing permissions and
16# limitations under the License.
17# ----------------------------------------------------------------------------
19import ctypes
20import os
22from common import log_error, log_info
23from common.const import SIGRTMIN
24from drv import LoadSoType
26IN_CLOSE_WRITE = 0x00000008 # inotify.h
27SIGNAL_ONE_TASK = 0xAABB0002
28SIGNAL_ALL_TASK = 0xAABB0003
31class AscendTraceDll:
33 def __init__(self):
34 self.trace_dll = LoadSoType().get_ascend_trace()
36 def send_signal_to_pid(self, is_all_task, remote_id):
37 """
38 use the sigqueue to send signal
39 """
40 class SignalVal(ctypes.Structure):
41 _fields_ = [("sival_int", ctypes.c_int)]
43 val = SIGNAL_ALL_TASK if is_all_task else SIGNAL_ONE_TASK
44 try:
45 ret_code = self.trace_dll.sigqueue(
46 ctypes.c_int32(remote_id),
47 ctypes.c_int32(SIGRTMIN + 1), # signal 35
48 SignalVal(val)
49 )
50 except Exception as e:
51 log_error(f"Send signal failed, error msg: {e}.")
52 return False
54 if ret_code != 0:
55 log_error("Send signal failed.")
56 return False
57 return True
59 def parse_stackcore_bin_to_txt(self, bin_file_path):
60 """
61 use the stackcore function to parse the bin file.
62 """
63 log_info("start parse bin file")
64 try:
65 ret_code = self.trace_dll.AtraceStackcoreParse(bin_file_path.encode(), ctypes.c_int32(len(bin_file_path)))
66 except Exception as e:
67 log_error(f"Parse stackcore bin file failed, error msg: {e}.")
68 return False
70 if ret_code == 0:
71 log_info(f"stackcore file path: {bin_file_path[:-4]}.txt")
72 return True
73 else:
74 log_error("Parse stackcore bin file failed, check trace logs in the plog.")
75 return False