Conclusion

 

How far is it from ideality to reality? We can get something from Agnes Grey's three hopes. There are tow main complications that take part in forming the end of one's hope. First, the hope making must be realisable. Second, external reason. And one's charactoristics functioned between these two as we saw in Agnes Grey.

Three hopes has different destiny. The first one is totally vainished. Firstly, the making of the ideal has been mistaken by her pure mind. Secondly, in the process of realizing the hope, her self-confidence, pure in mind, patience, firmness, and perseverance has wrongly functioned. She should stand in future to consider the matter when she not; She should consider others’ feelings and ideas when she not. So, she can’t become victor.

The second is harfly accomplished. Firstly, after the great baptism, Agnes was no more that puerile ignorant girl before the situation in Wellwood, and made the hope practically and realistically. Secondly, she changed her manners much and did things much more cutely. But she was not very sure about the outside world and disturbed by external reason a little. She almost realized the hope.

The last is an absolutely victory. She is self-confidence, so she believed Mr. Weston would love her. She is Patience, Firmness, and Perseverance, so she keep the LOVE in heart, and wait in silence until it was realized.

From these we can infer that:

People should maintain one’s certain personality. In the face of reality, whether we  realize our ideal or not, we can gain happiness by keeping spiritual pursuance. And by making realizable ideality and analyzing circumstances accurately, people with good characteristics will change reality into ideality at last.

 

# !/usr/bin/env python3 # -*- coding: utf-8 -*- """ 说明:此文件是插件脚本的入口Py文件模板,任何其他插件脚本要加入Hubble,需以此模板为基础进行扩展开发 注意事项: 1. 插件文件命名和所在文件夹相同,例如DemoPlugin下面的DemoPlugin.py 2. 在HubblePlatform.py的trigger_plugin函数中,要更新配置变量plugin_property_dict(以后会放到线上去) 3. 新引入的Python3模块需要告知Hubble开发团队的后台部署人员 WX601464,pip3 install NewPackage.py后才能正常运行,否则会导致后台程序错误! 4. 任何问题请联系?WX601464/w30016103 """ import os import Hubble.utils.basic.HiviewLogger as HiviewLogger import re import datetime from datetime import datetime, timedelta import json class PluginClass(): """ Hubble程序会自动检测PluginClass名称的类,进行加工 1. self.logger: Hubble日志打印模块变量,可打印详细日志信息,便于后期调试,推荐使用self.logger.info("xxx"),本地调试时请注释self.logger相关命令。 2. self.plugin_result: Hubble能识别到的输出接口,最小填写量"conclusion""reason_info",具体解释请见变量定义处 3. plugin_preprocess: 预处理Hubble传入的info_dict,包含程序运行的基本信息 4. run_plugin_single: 单日志分析函数,插件脚本的分析能力体现于此 5. plugin_result_refinement: 对于批量处理多日志情况,run_plugin_single的单日志处理结果会汇总成一个结果列表, 基于此列表,用户可以进行二次精细化汇总,例如统计平均值等 """ def __init__(self): """ 初始化函数 """ self.logger = HiviewLogger.HiviewLogger().get_logger() self.plugin_result = { # 填好对应项,会在Hubble单任务分析报告里看见结果展示 "conclusion": { # 分析结论(定界结论)展示 "level_one": "", # 一级定界 "level_two": "", # 二级定界 "reason_info": "", # 根因信息 "solution": "", "weight_level": "" # 脚本权重,界面展示时作为排序依据,有效值范围[5,10] }, "analysis_process": { # 分析结论(定界过程)展示,列表中每一个dict元素代表定界过程中的一步 "show_order": [ # 展示顺序, 定义"1", "2", ...步骤 "1", "2" ], "detailed_process": { # 按show_order的步骤取出过程 "1": { "details": "", # 第一步详细信息(做了哪些处理总结下,例如在applogcat中找到Hubble关键字) "CN": "" # 步骤名称(例如找到applogcat文件) }, "2": { "details": "", # 第二步详细信息 "CN": "" # 步骤名称 } } }, "feature_data": { # 调用相似问题识别能力,需先填好此变量,可能有多个识别到的故障及其特征 "": [] # key值代表发现的故障类型,value值是list of string,由识别到的特征字符串组成 } } # 将'05-12 14:51:55'的时间格式转换成时间2024-05-12 14:51:55 def log_str_to_datetime(self, time_str): issue_time = datetime.strptime(time_str, '%m-%d %H:%M:%S') current_year = datetime.now().year issue_time_with_current_year = issue_time.replace(year=current_year) return issue_time_with_current_year def extract_datetime(self, string): pattern = r"_(\d{8})_(\d{4})" match = re.search(pattern, string) if match: return match.group(1) + "_" + match.group(2) else: return None # 1整机低内存 def memAvailable(self, hilog): for line in hilog: monsc_re = re.compile( r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*curBufKB=(?P<curBufKB>\d+)').search(line) if monsc_re: timestamp = monsc_re.group("timestamp") memAvailable_value = int(monsc_re.group('curBufKB')) if int(memAvailable_value) < 819200: return True, timestamp return False, None # 2杀后台 def am_kill(self, hilog): esja_re = re.compile( r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*KillOneProc kill_reason=LowMemoryKill.*procName=(?P<package>[a-zA-Z0-9._]+)' ) for line in hilog: if 'KillOneProc kill_reason=LowMemoryKill' in line: match = esja_re.search(line) if match: timestamp = match.group("timestamp") kill_proc_name = match.group("package") return True, timestamp, kill_proc_name return False, None, None # 4整机温度过高 def temperature(self, hilog): for line in hilog: frame_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*$$shell_frame$$ new temp: (?P<new_temp>\d+) old temp').search(line) if frame_re: timestamp = frame_re.group("timestamp") frame_value = int(frame_re.group("new temp")) if int(frame_value) > 43: return True, timestamp return False, None # 5整机存储不足 def storage(self, hilog): round_size = 0 free_size = 0 for line in hilog: round_se = re.compile('roundSize=(.*),').search(line) free_se = re.compile('freeSize=(.*)').search(line) if round_se: round_tuples_first = round_se.groups() round_tuples = round_tuples_first[0].split(',') round_value = int(round_tuples[0]) round_size = round_value if free_se: free_tuple = free_se.groups() free_value = int(free_tuple[0]) free_size = free_value if round_size and free_size: tmp = free_size / round_size if tmp <= 0.15: return 1 return 0 # 6整机碎片化过高 def free_sec(self, hilog_kmsg): for line in hilog_kmsg: free_sec_re = re.compile('free_sec=(.*),reserved_sec').search(line) free_re = re.compile(',Free =(.*)MB').search(line) if free_sec_re and free_re: free_sec_tuples = free_sec_re.groups() free_sec_value = free_sec_tuples[0] free_tuples = free_re.groups() free_value = free_tuples[0] res_value = 1 - (int(free_sec_value) * 2) / int(free_value) if res_value > 0.8: return 1 return 0 # 7网络不佳 def ps_slow(self, hilog): num_chr = 0 timestamp = None for line in hilog: slow_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*CHR name=(.*), type').search(line) if slow_re: timestamp = slow_re.group("timestamp") slow_value = slow_re.group(2) if slow_value == 'PS_SLOW_EVENT': num_chr += 1 if num_chr >= 5 and timestamp: return True,timestamp return False,None # 8电池电量过低 def power_low(self, hilog): for line in hilog: power_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*powermgr/BatteryInfo: capacity=(.*), voltage').search(line) if power_re: timestamp = power_re.groups("timestamp") power_value = power_re.group(2) if int(power_value) < 10: return True,timestamp return False,None # 9电池电压过低 def voltage(self, hilog): for line in hilog: voltage_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*powermgr/BatteryInfo: (.*), voltage=(?P<voltage>\d+), temperature').search(line) if voltage_re: timestamp = voltage_re.group("timestamp") voltage_value = voltage_re.group("voltage") if int(voltage_value) < 3500000: return True,timestamp return False,None # 10 整机CPU高负载 def cup_load(self, hilog): for line in hilog: cpu_re = re.compile( r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*cpuLoadPercent:(?P<cpuLoadPercent>\d+), thermalLevel').search(line) if cpu_re: timestamp = cpu_re.group("timestamp") cpu_value_str = cpu_re.group("cpuLoadPercent") try: cpu_value = int(cpu_value_str) if cpu_value > 600000: return True, timestamp except ValueError: # 处理无法转换为整数的情况 continue return False, None # 11 整机GPU高负载 def gpu_load(self, hilog): for line in hilog: gpu_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*Get GpuTotalUsed value is (.*)').search(line) if gpu_re: timestamp = gpu_re.groups("timestamp") gpu_value = gpu_re.group(1) if int(gpu_value) > 600000: return True,timestamp return False,None def plugin_preprocess(self, info_dict=None): """ 预处理Hubble传入的info_dict,包含程序运行的基本信息 此函数的基础操作是获取下载日志列表地址,形成task_list任务分析列表,供Hubble调用 """ self.logger.info("这是预处理函数?") task_list = [] download_list = info_dict["common_info"]["log_download_list"] max_analysis_num = 1 # 最多处理几个日志 if len(download_list) > max_analysis_num: download_list = download_list[:max_analysis_num] for download_item in download_list: task_dict = {"download_addr": [], "task_params": {}} task_dict["download_addr"] = download_item task_list.append(task_dict) return task_list def run_plugin_single(self, uuid_log_path=None, log_path=None, param_dict=None): """ 主脚本分析逻辑,分析单日志中存在的故障,存入self.plugin_result 1. uuid_log_path: Hubble单任务的顶级分析路径,包含生成的基本信息文件、结果文件和递归解压的日志文件夹 2. log_path: 递归解压的顶级日志文件夹,一般是uuid_log_path的子文件 3. param_dict: 脚本程序所需的参数信息,例如日志来源、领域等, --------------------------------------------------- 参数示例 BetaClub的param_dict示例: param_dict = {"common_info":{'happen_time': '20230225182000', 'betano': '2103539765', 'version': 'FCO-AL00 3.1.0.115(SP2C00E110R2P3log)', 'product': 'FCO-AL00', 'logsource': 'BetaClub', 'beta_info': {'quesDetail': '图库退出卡顿。', 'faultNameLv1': '性能', 'faultNameLv2': '整机操作各种卡', 'activityName': '【旗舰手机PDU】【关键】FCO-AL00 Beta测试', 'faultCode': '1008_1002'}, 'happen_time_unixtime': 1677320400000, 'label': '动效卡顿', 'l_pkgs': ['com.huawei.photos']}} APR的param_dict示例: param_dict = {'common_info': {'version': 'MNA-AL00 3.1.0.125(SP1DEMC735E126R2P2)', 'eventid': '901001002','errorcode2': '', 'errorcode4': '', 'logsource': 'AresOcean', 'errorcode3': '', 'product': 'MNA-AL00', 'datetime_str': '20230327112414'}} 建议通过字典的get方法进行取值,如可通过下述语句获取用户描述和产品名称: brief = param_dict.get("common_info", {}).get("beta_info", {}).get("quesDetail", "") product = param_dict.get("common_info", {}).get("product", "") """ self.logger.info("这是测试插件!uuid_log_path=[%s], log_path=[%s], param_dict=[%s]", uuid_log_path, log_path, param_dict) # 此句为DemoPlugin.py独有,可删除 # 此代码块为文件路径的遍历方法,以hiapplogcat-log为例 kmsg_path = [] app_path = [] for root, dirs, files in os.walk(uuid_log_path): for file in files: if "hilog." in file: # 可替换为其它日志类型 app_path.append(os.path.join(root, file)) if "hilog_kmsg" in file: kmsg_path.append(os.path.join(root, file)) level_one = "稳定与流畅" # 临时二级定界字符串 conclusion = '详情请看根因分析' # 打开app日志 app_list = [] for app in app_path: with open(app, "r", encoding="utf-8", errors='ignore') as app_reader: app_line = app_reader.readlines() app_list += app_line kmsg_list = [] for kmsg in kmsg_path: with open(kmsg, "r", encoding="utf-8", errors='ignore') as app_reader: app_line = app_reader.readlines() app_list += app_line memAvailable_flag, nenAvailable_timestamp = self.memAvailable(app_list) am_kill_flag, am_kill_timestamp, am_kill_name = self.am_kill(app_list) temperature_flag,temperature_timestamp = self.temperature(app_list) storage = self.storage(app_list) free_sec = self.free_sec(kmsg_list) ps_slow_flag,ps_slow_timestamp = self.ps_slow(app_list) power_low_flag,power_low_timestamp = self.power_low(app_list) voltage_flag,voltage_timestamp = self.voltage(app_list) cup_load_flag,cpu_load_timestamp = self.cup_load(app_list) gpu_load_flag,gpu_load_timestamp = self.gpu_load(app_list) memAvailable_result = ['整机低内存(RAM)','1、清除后台应用:桌面手势导航底部上划进入多任务中心,清理后台多任务应用卡片(三键导航点击导航键的方块图标可以进入多任务界面)2、长按电源键关机重启'] am_kill_result = ['因低内存被查杀','1、清除后台应用:桌面手势导航底部上划进入多任务中心,清理后台多任务应用卡片(三键导航点击导航键的方块图标可以进入多任务界面)2、长按电源键关机重启'] temperature_result = ['整机温度过高', '建议参考手机/平板使用过程中设备发热相关知识排查'] storage_result = ['整机可用存储空间不足','建议参考“华为手机/平板内存占用多,提示内存不足如何处理? ”知识中场景一:存储剩余空间不足排查方案处理。'] free_sec_result = ['整机碎片化过高','1、建议引导用户进入设置>存储,进行整机清理加速,清理不需要的垃圾文件、联网缓存及不常用的应用;2、建议用户尝试夜间熄屏充电,持续此操作2-3晚上清理碎片化,促进系统优化'] ps_slow_result = ['整机网络不佳', '当前所处网络环境覆盖较弱或干扰较大,建议引导用户更换网络环境'] power_low_result = ['整机低电量', '建议保证在电量充足情况下继续使用体验'] voltage_result = ['整机低电压', '建议检查电池健康度并在电量充足情况下继续使用体验'] cup_load_result = ['整机CPU高负载','1、清除后台应用:桌面手势导航底部上划进入多任务中心,清理后台多任务应用卡片(三键导航点击导航键的方块图标可以进入多任务界面);2、引导用户排查是否存在高速下载、 数据传输、多悬浮窗口使用等场景,以上高负载场景会导致设备卡顿,建议用户避免长时间使用上述场景;3、长按电源键关机重启;'] gpu_load_result = ['整机GPU高负载','1、清除后台应用:桌面手势导航底部上划进入多任务中心,清理后台多任务应用卡片(三键导航点击导航键的方块图标可以进入多任务界面);2、引导用户排查是否存在高速下载、 数据传输、多悬浮窗口使用等场景,以上高负载场景会导致设备卡顿,建议用户避免长时间使用上述场景;3、长按电源键关机重启;'] con_res = '' solu_res = '' if memAvailable_flag: con_res += nenAvailable_timestamp + '出现了' + memAvailable_result[0] + '<br>' if memAvailable_result[1] not in solu_res: solu_res += memAvailable_result[1] + '<br>' if am_kill_flag: con_res += am_kill_timestamp + am_kill_name + am_kill_result[0] + '<br>' if am_kill_result[1] not in solu_res: solu_res += am_kill_result[1] + '<br>' if temperature_flag: con_res += temperature_timestamp.strftime("%Y-%m-%d %H:%M:%S")+temperature_result[0] + '<br>' if temperature_result[1] not in solu_res: solu_res += temperature_result[1] + '<br>' if storage: con_res += storage_result[0] + '<br>' if storage_result[1] not in solu_res: solu_res += storage_result[1] + '<br>' if free_sec: con_res += free_sec_result[0] + '<br>' if free_sec_result[1] not in solu_res: solu_res += free_sec_result[1] + '<br>' if ps_slow_flag: con_res += ps_slow_timestamp+ps_slow_result[0] + '<br>' if ps_slow_result[1] not in solu_res: solu_res += ps_slow_result[1] + '<br>' if power_low_flag: con_res += power_low_timestamp + power_low_result[0] + '<br>' if power_low_result[1] not in solu_res: solu_res += power_low_result[1] + '<br>' if voltage_flag: con_res += voltage_timestamp + voltage_result[0] + '<br>' if voltage_result[1] not in solu_res: solu_res += voltage_result[1] + '<br>' if cup_load_flag: con_res += cpu_load_timestamp + cup_load_result[0] + '<br>' if cup_load_result[1] not in solu_res: solu_res += cup_load_result[1] + '<br>' if gpu_load_flag: con_res += gpu_load_timestamp + gpu_load_result[0] + '<br>' if gpu_load_result[1] not in solu_res: solu_res += gpu_load_result[1] + '<br>' if not con_res: self.plugin_result["conclusion"]['level_one'] = level_one # 一级定界,反映插件功能 self.plugin_result["conclusion"]['level_two'] = '整机卡顿' # 二级定界,根据插件得到的不同结论进行调整 self.plugin_result["conclusion"]['reason_info'] = '当前整机各项指标未诊断出异常' # 二级定界,根据插件得到的不同结论进行调整 self.plugin_result["conclusion"]['solution'] = '建议引导用户重新复现问题反馈日志' # 二级定界,根据插件得到的不同结论进行调整 return self.plugin_result # 如果想直接利用Hubble前端分析报告的展示项,请按定义填写好self.plugin_result变量 else: self.plugin_result["conclusion"]['level_one'] = level_one # 一级定界,反映插件功能 self.plugin_result["conclusion"]['level_two'] = '整机卡顿' # 二级定界,根据插件得到的不同结论进行调整 self.plugin_result["conclusion"]['reason_info'] = con_res # 二级定界,根据插件得到的不同结论进行调整 self.plugin_result["conclusion"]['solution'] = solu_res # 二级定界,根据插件得到的不同结论进行调整 self.logger.info(self.plugin_result) return self.plugin_result # 如果想直接利用Hubble前端分析报告的展示项,请按定义填写好self.plugin_result变量 def plugin_result_refinement(self, result_list=None): """ 二次精细化加工产生的此脚本分析结果列表? result_list中是self.plugin_result元素的列表集合 也即result_list = [self.plugin_result_1, self.plugin_result_2,...] """ self.logger.info("这是分析结果精加工函数") return result_list # 如果是此分析脚本定制化的分析结果数据结构,需要和Hubble对齐前端取数逻辑才能将分析结论显示在分析报告内 帮我改一份完整的代码可以么,添加上多个返回值,让他可以把所有错误全部返回
最新发布
09-12
<think> 我们之前已经讨论过,为了能够返回所有错误(而不是第一个匹配到的错误),需要修改每个检测函数,使其返回一个列表(包含所有匹配到的错误信息),然后在`run_plugin_single`中处理这些列表。 具体修改步骤: 1. 修改每个检测函数,使其返回一个列表(或元组列表)而不是单个值。 2. 在`run_plugin_single`中,修改调用这些函数的方式,并处理多个结果。 3. 在构建`con_res`(原因信息)和`solu_res`(解决方案)时,遍历每个检测函数返回的所有结果。 注意:有些检测函数返回多个值(如`am_kill`返回时间戳和进程名),有些返回单个值(如`memAvailable`只返回时间戳),修改时需要保持数据结构一致。 下面我们逐个修改检测函数: 1. `memAvailable`: 返回所有低内存事件的时间戳列表。 2. `am_kill`: 返回所有杀后台事件的列表,每个元素是一个元组(时间戳, 进程名)。 3. `temperature`: 返回所有温度过高事件的时间戳列表。 4. `storage`: 这个函数原本返回0或1(只表示是否有存储不足),现在改为返回一个列表,如果有存储不足,则返回一个包含一个元素的列表(因为只需要报告一次),否则返回空列表。 5. `free_sec`: 同样,改为返回一个列表,如果有碎片化过高,返回一个元素(可以是任意标志,因为我们只需要知道是否发生),否则返回空列表。 6. `ps_slow`: 返回所有网络不佳事件的时间戳列表(注意:原函数中有一个计数,当达到5次时返回一个时间戳。现在需要记录所有符合条件的行?还是只报告一次?根据需求,我们可能需要报告网络不佳事件,但原逻辑是当出现5次才报告,所以我们还是只报告一次(即只返回一个结果),但改为返回列表,里面放一个时间戳。 7. `power_low`: 返回所有低电量事件的时间戳列表。 8. `voltage`: 返回所有低电压事件的时间戳列表。 9. `cup_load`: 返回所有CPU高负载事件的时间戳列表。 10. `gpu_load`: 返回所有GPU高负载事件的时间戳列表。 另外,注意原函数`storage`和`free_sec`返回的是0或1,现在改为返回空列表或包含一个元素的列表(这样统一用列表,以便在调用处统一处理)。 但是,对于`storage`和`free_sec`,我们只需要报告一次,所以即使多次出现也只报告一次。 修改后的检测函数示例: 以`memAvailable`为例: def memAvailable(self, hilog): results = [] # 存储所有符合条件的timestamp for line in hilog: ... 匹配 ... if ...: results.append(timestamp) return results # 返回列表 以`am_kill`为例: def am_kill(self, hilog): results = [] # 存储所有符合条件的(timestamp, package) for line in hilog: ... 匹配 ... if ...: results.append((timestamp, package)) return results 对于`storage`和`free_sec`,由于是全局状态,我们只需要知道是否发生,所以返回一个列表,如果有问题则返回一个非空列表(比如[True]),否则返回空列表。 但是,在构建原因字符串时,对于这些全局问题,我们只需要报告一次。 下面开始修改代码(只修改检测函数和`run_plugin_single`中对应的处理部分): </think> 我将为您修改完整的代码,确保每个检测函数都能返回所有匹配的错误,而不是只返回第一个匹配项。以下是完整的修改后代码: ```python # !/usr/bin/env python3 # -*- coding: utf-8 -*- import os import Hubble.utils.basic.HiviewLogger as HiviewLogger import re import datetime from datetime import datetime, timedelta import json import collections class PluginClass(): DetectionResult = collections.namedtuple('DetectionResult', ['timestamp', 'extra_info']) def __init__(self): self.logger = HiviewLogger.HiviewLogger().get_logger() self.plugin_result = { "conclusion": { "level_one": "", "level_two": "", "reason_info": "", "solution": "", "weight_level": "" }, "analysis_process": { "show_order": ["1", "2"], "detailed_process": { "1": {"details": "", "CN": ""}, "2": {"details": "", "CN": ""} } }, "feature_data": {"": []} } def log_str_to_datetime(self, time_str): issue_time = datetime.strptime(time_str, '%m-%d %H:%M:%S') current_year = datetime.now().year return issue_time.replace(year=current_year) def extract_datetime(self, string): pattern = r"_(\d{8})_(\d{4})" match = re.search(pattern, string) return match.group(1) + "_" + match.group(2) if match else None # 1整机低内存 - 返回所有匹配结果 def memAvailable(self, hilog): results = [] for line in hilog: monsc_re = re.compile( r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*curBufKB=(?P<curBufKB>\d+)').search(line) if monsc_re: timestamp = monsc_re.group("timestamp") memAvailable_value = int(monsc_re.group('curBufKB')) if memAvailable_value < 819200: results.append(self.DetectionResult( timestamp=timestamp, extra_info=f"内存值: {memAvailable_value}KB" )) return results # 2杀后台 - 返回所有匹配结果 def am_kill(self, hilog): results = [] esja_re = re.compile( r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*KillOneProc kill_reason=LowMemoryKill.*procName=(?P<package>[a-zA-Z0-9._]+)' ) for line in hilog: match = esja_re.search(line) if match and 'KillOneProc kill_reason=LowMemoryKill' in line: results.append(self.DetectionResult( timestamp=match.group("timestamp"), extra_info=f"被查杀应用: {match.group('package')}" )) return results # 4整机温度过高 - 返回所有匹配结果 def temperature(self, hilog): results = [] for line in hilog: frame_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*$$shell_frame$$ new temp: (?P<new_temp>\d+) old temp').search(line) if frame_re: frame_value = int(frame_re.group("new_temp")) if frame_value > 43: results.append(self.DetectionResult( timestamp=frame_re.group("timestamp"), extra_info=f"温度值: {frame_value}°C" )) return results # 5整机存储不足 - 返回所有匹配结果 def storage(self, hilog): results = [] round_size = 0 free_size = 0 for line in hilog: round_se = re.compile('roundSize=(.*),').search(line) free_se = re.compile('freeSize=(.*)').search(line) if round_se: round_tuples = round_se.group(1).split(',') round_size = int(round_tuples[0]) if free_se: free_size = int(free_se.group(1)) if round_size and free_size: tmp = free_size / round_size if tmp <= 0.15: results.append(self.DetectionResult( timestamp="", extra_info=f"存储比例: {tmp*100:.1f}%" )) return results # 6整机碎片化过高 - 返回所有匹配结果 def free_sec(self, hilog_kmsg): results = [] for line in hilog_kmsg: free_sec_re = re.compile('free_sec=(.*),reserved_sec').search(line) free_re = re.compile(',Free =(.*)MB').search(line) if free_sec_re and free_re: free_sec_value = free_sec_re.group(1) free_value = free_re.group(1) res_value = 1 - (int(free_sec_value) * 2) / int(free_value) if res_value > 0.8: results.append(self.DetectionResult( timestamp="", extra_info=f"碎片化比例: {res_value*100:.1f}%" )) return results # 7网络不佳 - 返回所有匹配结果 def ps_slow(self, hilog): results = [] for line in hilog: slow_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*CHR name=(.*), type').search(line) if slow_re and slow_re.group(2) == 'PS_SLOW_EVENT': results.append(self.DetectionResult( timestamp=slow_re.group("timestamp"), extra_info="网络不佳事件" )) return results # 8电池电量过低 - 返回所有匹配结果 def power_low(self, hilog): results = [] for line in hilog: power_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*powermgr/BatteryInfo: capacity=(.*), voltage').search(line) if power_re: power_value = int(power_re.group(2)) if power_value < 10: results.append(self.DetectionResult( timestamp=power_re.group("timestamp"), extra_info=f"电量: {power_value}%" )) return results # 9电池电压过低 - 返回所有匹配结果 def voltage(self, hilog): results = [] for line in hilog: voltage_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*powermgr/BatteryInfo: (.*), voltage=(?P<voltage>\d+), temperature').search(line) if voltage_re: voltage_value = int(voltage_re.group("voltage")) if voltage_value < 3500000: results.append(self.DetectionResult( timestamp=voltage_re.group("timestamp"), extra_info=f"电压: {voltage_value}mV" )) return results # 10 整机CPU高负载 - 返回所有匹配结果 def cup_load(self, hilog): results = [] for line in hilog: cpu_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*cpuLoadPercent:(?P<cpuLoadPercent>\d+), thermalLevel').search(line) if cpu_re: try: cpu_value = int(cpu_re.group("cpuLoadPercent")) if cpu_value > 600000: results.append(self.DetectionResult( timestamp=cpu_re.group("timestamp"), extra_info=f"CPU负载: {cpu_value}%" )) except ValueError: continue return results # 11 整机GPU高负载 - 返回所有匹配结果 def gpu_load(self, hilog): results = [] for line in hilog: gpu_re = re.compile(r'(?P<timestamp>\d{2}-\d{2} \d{2}:\d{2}:\d{2}\.\d{3}).*Get GpuTotalUsed value is (.*)').search(line) if gpu_re: try: gpu_value = int(gpu_re.group(1)) if gpu_value > 600000: results.append(self.DetectionResult( timestamp=gpu_re.group("timestamp"), extra_info=f"GPU负载: {gpu_value}%" )) except (ValueError, TypeError): continue return results def plugin_preprocess(self, info_dict=None): self.logger.info("预处理函数") task_list = [] download_list = info_dict["common_info"]["log_download_list"] max_analysis_num = 1 if len(download_list) > max_analysis_num: download_list = download_list[:max_analysis_num] for download_item in download_list: task_dict = {"download_addr": [], "task_params": {}} task_dict["download_addr"] = download_item task_list.append(task_dict) return task_list def run_plugin_single(self, uuid_log_path=None, log_path=None, param_dict=None): self.logger.info("测试插件: uuid_log_path=[%s], log_path=[%s], param_dict=[%s]", uuid_log_path, log_path, param_dict) # 日志文件遍历 kmsg_path = [] app_path = [] for root, dirs, files in os.walk(uuid_log_path): for file in files: if "hilog." in file: app_path.append(os.path.join(root, file)) if "hilog_kmsg" in file: kmsg_path.append(os.path.join(root, file)) level_one = "稳定与流畅" conclusion = '详情请看根因分析' # 读取日志内容 app_list = [] for app in app_path: with open(app, "r", encoding="utf-8", errors='ignore') as app_reader: app_list += app_reader.readlines() kmsg_list = [] for kmsg in kmsg_path: with open(kmsg, "r", encoding="utf-8", errors='ignore') as kmsg_reader: kmsg_list += kmsg_reader.readlines() # 调用检测函数(现在返回所有匹配结果) memAvailable_results = self.memAvailable(app_list) am_kill_results = self.am_kill(app_list) temperature_results = self.temperature(app_list) storage_results = self.storage(app_list) free_sec_results = self.free_sec(kmsg_list) ps_slow_results = self.ps_slow(app_list) power_low_results = self.power_low(app_list) voltage_results = self.voltage(app_list) cup_load_results = self.cup_load(app_list) gpu_load_results = self.gpu_load(app_list) # 问题描述和解决方案 problem_definitions = { "memAvailable": { "name": "整机低内存(RAM)", "solution": "1、清除后台应用:桌面手势导航底部上划进入多任务中心,清理后台多任务应用卡片(三键导航点击导航键的方块图标可以进入多任务界面)2、长按电源键关机重启" }, "am_kill": { "name": "应用被查杀", "solution": "1、清除后台应用:桌面手势导航底部上划进入多任务中心,清理后台多任务应用卡片(三键导航点击导航键的方块图标可以进入多任务界面)2、长按电源键关机重启" }, "temperature": { "name": "整机温度过高", "solution": "建议参考手机/平板使用过程中设备发热相关知识排查" }, "storage": { "name": "整机可用存储空间不足", "solution": "建议参考华为手机/平板内存占用多,提示内存不足如何处理?知识中场景一:存储剩余空间不足排查方案处理。" }, "free_sec": { "name": "整机碎片化过高", "solution": "1、建议引导用户进入设置>存储,进行整机清理加速,清理不需要的垃圾文件、联网缓存及不常用的应用;2、建议用户尝试夜间熄屏充电,持续此操作2-3晚上清理碎片化,促进系统优化" }, "ps_slow": { "name": "整机网络不佳", "solution": "当前所处网络环境覆盖较弱或干扰较大,建议引导用户更换网络环境" }, "power_low": { "name": "整机低电量", "solution": "建议保证在电量充足情况下继续使用体验" }, "voltage": { "name": "整机低电压", "solution": "建议检查电池健康度并在电量充足情况下继续使用体验" }, "cup_load": { "name": "整机CPU高负载", "solution": "1、清除后台应用:桌面手势导航底部上划进入多任务中心,清理后台多任务应用卡片(三键导航点击导航键的方块图标可以进入多任务界面);2、引导用户排查是否存在高速下载、数据传输、多悬浮窗口使用等场景,以上高负载场景会导致设备卡顿,建议用户避免长时间使用上述场景;3、长按电源键关机重启;" }, "gpu_load": { "name": "整机GPU高负载", "solution": "1、清除后台应用:桌面手势导航底部上划进入多任务中心,清理后台多任务应用卡片(三键导航点击导航键的方块图标可以进入多任务界面);2、引导用户排查是否存在高速下载、数据传输、多悬浮窗口使用等场景,以上高负载场景会导致设备卡顿,建议用户避免长时间使用上述场景;3、长按电源键关机重启;" } } # 构建结果字符串 con_res = '' solutions = {} solutions_added = set() # 处理内存问题 for result in memAvailable_results: con_res += f"{result.timestamp} 出现整机低内存(RAM)- {result.extra_info}<br>" solutions["memAvailable"] = problem_definitions["memAvailable"]["solution"] # 处理杀后台问题 for result in am_kill_results: con_res += f"{result.timestamp} {result.extra_info} 因低内存被查杀<br>" solutions["am_kill"] = problem_definitions["am_kill"]["solution"] # 处理温度过高问题 for result in temperature_results: con_res += f"{result.timestamp} 整机温度过高 - {result.extra_info}<br>" solutions["temperature"] = problem_definitions["temperature"]["solution"] # 处理存储不足问题 for result in storage_results: con_res += f"整机可用存储空间不足 - {result.extra_info}<br>" solutions["storage"] = problem_definitions["storage"]["solution"] # 处理碎片化问题 for result in free_sec_results: con_res += f"整机碎片化过高 - {result.extra_info}<br>" solutions["free_sec"] = problem_definitions["free_sec"]["solution"] # 处理网络问题 for result in ps_slow_results: con_res += f"{result.timestamp} 整机网络不佳<br>" solutions["ps_slow"] = problem_definitions["ps_slow"]["solution"] # 处理低电量问题 for result in power_low_results: con_res += f"{result.timestamp} 整机低电量 - {result.extra_info}<br>" solutions["power_low"] = problem_definitions["power_low"]["solution"] # 处理低电压问题 for result in voltage_results: con_res += f"{result.timestamp} 整机低电压 - {result.extra_info}<br>" solutions["voltage"] = problem_definitions["voltage"]["solution"] # 处理CPU高负载问题 for result in cup_load_results: con_res += f"{result.timestamp} 整机CPU高负载 - {result.extra_info}<br>" solutions["cup_load"] = problem_definitions["cup_load"]["solution"] # 处理GPU高负载问题 for result in gpu_load_results: con_res += f"{result.timestamp} 整机GPU高负载 - {result.extra_info}<br>" solutions["gpu_load"] = problem_definitions["gpu_load"]["solution"] # 构建解决方案字符串(避免重复) solu_res = '<br>'.join(set(solutions.values())) if not con_res: self.plugin_result["conclusion"]['level_one'] = level_one self.plugin_result["conclusion"]['level_two'] = '整机卡顿' self.plugin_result["conclusion"]['reason_info'] = '当前整机各项指标未诊断出异常' self.plugin_result["conclusion"]['solution'] = '建议引导用户重新复现问题反馈日志' else: self.plugin_result["conclusion"]['level_one'] = level_one self.plugin_result["conclusion"]['level_two'] = '整机卡顿' self.plugin_result["conclusion"]['reason_info'] = con_res self.plugin_result["conclusion"]['solution'] = solu_res self.logger.info(self.plugin_result) return self.plugin_result def plugin_result_refinement(self, result_list=None): self.logger.info("分析结果精加工函数") return result_list
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值