mirror of
https://github.com/jxxghp/MoviePilot.git
synced 2026-09-04 23:17:20 +08:00
fix
This commit is contained in:
@@ -324,66 +324,3 @@ class MemoryHelper(metaclass=Singleton):
|
||||
return f"{obj_type_name}(描述生成失败):{e}"
|
||||
except Exception as e:
|
||||
return f"未知对象(描述生成失败):{e}"
|
||||
|
||||
def get_current_memory_info(self) -> dict:
|
||||
"""
|
||||
获取当前内存使用信息
|
||||
:return: 内存使用信息字典
|
||||
"""
|
||||
try:
|
||||
# 获取当前进程内存使用
|
||||
current_memory = psutil.Process().memory_info().rss
|
||||
|
||||
# 获取对象统计
|
||||
all_objects = muppy.get_objects()
|
||||
sum1 = summary.summarize(all_objects)
|
||||
|
||||
memory_info = {
|
||||
"current_memory_mb": round(current_memory / 1024 / 1024, 2),
|
||||
"object_count": len(all_objects),
|
||||
"top_objects": [],
|
||||
"largest_objects": []
|
||||
}
|
||||
|
||||
# 解析对象统计信息
|
||||
formatted_lines = list(summary.format_(sum1))
|
||||
for line in formatted_lines:
|
||||
parts = line.split('|')
|
||||
if len(parts) >= 3 and not line.startswith('=') and not line.startswith(' types'):
|
||||
# 解析格式: "type_name | count | size"
|
||||
type_name = parts[0].strip()
|
||||
count_str = parts[1].strip()
|
||||
size_str = parts[2].strip()
|
||||
|
||||
# 跳过表头和分隔线
|
||||
if type_name and count_str.isdigit():
|
||||
# 解析大小(可能包含单位)
|
||||
size_mb = 0
|
||||
if 'MB' in size_str:
|
||||
size_mb = float(size_str.replace('MB', '').strip())
|
||||
elif 'KB' in size_str:
|
||||
size_mb = float(size_str.replace('KB', '').strip()) / 1024
|
||||
elif 'B' in size_str:
|
||||
size_mb = float(size_str.replace('B', '').strip()) / 1024 / 1024
|
||||
|
||||
memory_info["top_objects"].append({
|
||||
"type": type_name,
|
||||
"count": count_str,
|
||||
"size_mb": round(size_mb, 2)
|
||||
})
|
||||
|
||||
# 只取前10个有效对象
|
||||
if len(memory_info["top_objects"]) >= 10:
|
||||
break
|
||||
|
||||
# 获取最大对象信息
|
||||
try:
|
||||
memory_info["largest_objects"] = self._get_largest_objects(10)
|
||||
except Exception as e:
|
||||
logger.warning(f"获取大对象列表失败: {e}")
|
||||
memory_info["largest_objects"] = []
|
||||
|
||||
return memory_info
|
||||
except Exception as e:
|
||||
logger.error(f"获取内存信息失败: {e}")
|
||||
return {"error": str(e)}
|
||||
|
||||
Reference in New Issue
Block a user