优化后台截图功能
This commit is contained in:
1 parent
223c127e11
commit
ace3bbfa04
70 files changed
+4392
-871
No files matched your search
@@ -0,0 +1,297 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""检查系统配置是否适合多线程处理"""
|
||||
|
||||
import sys
|
||||
import os
|
||||
import platform
|
||||
|
||||
# 设置UTF-8输出
|
||||
if sys.platform == 'win32':
|
||||
try:
|
||||
sys.stdout.reconfigure(encoding='utf-8')
|
||||
except Exception:
|
||||
import io
|
||||
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
|
||||
|
||||
def check_cpu():
|
||||
"""检查CPU配置"""
|
||||
print("=" * 60)
|
||||
print("CPU 配置检查")
|
||||
print("=" * 60)
|
||||
|
||||
cpu_count = os.cpu_count()
|
||||
if cpu_count:
|
||||
print(f"CPU核心数: {cpu_count}")
|
||||
|
||||
# 评估
|
||||
if cpu_count >= 8:
|
||||
print("✅ CPU配置: 优秀 (8核+)")
|
||||
print(" 推荐线程数: 8-12")
|
||||
print(" 性能提升: 60-70%")
|
||||
elif cpu_count >= 4:
|
||||
print("✅ CPU配置: 良好 (4-7核)")
|
||||
print(" 推荐线程数: 4-6")
|
||||
print(" 性能提升: 50-60%")
|
||||
elif cpu_count >= 2:
|
||||
print("⚠️ CPU配置: 基础 (2-3核)")
|
||||
print(" 推荐线程数: 2-3")
|
||||
print(" 性能提升: 30-40%")
|
||||
else:
|
||||
print("❌ CPU配置: 不足 (单核)")
|
||||
print(" 不推荐使用多线程")
|
||||
else:
|
||||
print("❌ 无法检测CPU核心数")
|
||||
|
||||
# 获取CPU信息(Windows)
|
||||
try:
|
||||
import subprocess
|
||||
result = subprocess.run(
|
||||
['wmic', 'cpu', 'get', 'name'],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=5
|
||||
)
|
||||
if result.returncode == 0:
|
||||
lines = result.stdout.strip().split('\n')
|
||||
if len(lines) > 1:
|
||||
cpu_name = lines[1].strip()
|
||||
if cpu_name:
|
||||
print(f"CPU型号: {cpu_name}")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
print()
|
||||
|
||||
def check_memory():
|
||||
"""检查内存配置"""
|
||||
print("=" * 60)
|
||||
print("内存配置检查")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
import psutil
|
||||
mem = psutil.virtual_memory()
|
||||
total_gb = mem.total / (1024**3)
|
||||
available_gb = mem.available / (1024**3)
|
||||
used_percent = mem.percent
|
||||
|
||||
print(f"总内存: {total_gb:.2f} GB")
|
||||
print(f"可用内存: {available_gb:.2f} GB")
|
||||
print(f"已用内存: {used_percent:.1f}%")
|
||||
|
||||
# 评估
|
||||
if total_gb >= 16:
|
||||
print("✅ 内存配置: 优秀 (16GB+)")
|
||||
print(" 可以支持大量并发任务")
|
||||
elif total_gb >= 8:
|
||||
print("✅ 内存配置: 良好 (8-15GB)")
|
||||
print(" 可以流畅运行多线程处理")
|
||||
elif total_gb >= 4:
|
||||
print("⚠️ 内存配置: 基础 (4-7GB)")
|
||||
print(" 可以运行,但可能较慢")
|
||||
else:
|
||||
print("❌ 内存配置: 不足 (<4GB)")
|
||||
print(" 不推荐使用多线程")
|
||||
|
||||
# 检查当前可用内存
|
||||
if available_gb < 2:
|
||||
print("⚠️ 警告: 可用内存不足2GB,可能影响性能")
|
||||
|
||||
except ImportError:
|
||||
print("⚠️ psutil未安装,无法检测内存")
|
||||
print(" 安装命令: pip install psutil")
|
||||
print(" 或手动检查: 任务管理器 -> 性能 -> 内存")
|
||||
except Exception as e:
|
||||
print(f"❌ 内存检测失败: {e}")
|
||||
|
||||
print()
|
||||
|
||||
def check_python():
|
||||
"""检查Python版本"""
|
||||
print("=" * 60)
|
||||
print("Python 版本检查")
|
||||
print("=" * 60)
|
||||
|
||||
version = sys.version_info
|
||||
print(f"Python版本: {version.major}.{version.minor}.{version.micro}")
|
||||
|
||||
if version >= (3, 10):
|
||||
print("✅ Python版本: 优秀 (3.10+)")
|
||||
elif version >= (3, 8):
|
||||
print("✅ Python版本: 良好 (3.8-3.9)")
|
||||
else:
|
||||
print("❌ Python版本: 过低 (<3.8)")
|
||||
print(" 建议升级到 Python 3.8+")
|
||||
|
||||
print()
|
||||
|
||||
def check_system():
|
||||
"""检查操作系统"""
|
||||
print("=" * 60)
|
||||
print("操作系统检查")
|
||||
print("=" * 60)
|
||||
|
||||
system = platform.system()
|
||||
version = platform.version()
|
||||
arch = platform.machine()
|
||||
|
||||
print(f"操作系统: {system}")
|
||||
print(f"系统版本: {version}")
|
||||
print(f"架构: {arch}")
|
||||
|
||||
if system == 'Windows':
|
||||
if '64' in arch or 'AMD64' in arch:
|
||||
print("✅ 系统架构: 64位 (支持)")
|
||||
else:
|
||||
print("❌ 系统架构: 32位 (不支持)")
|
||||
else:
|
||||
print("⚠️ 非Windows系统,可能不兼容")
|
||||
|
||||
print()
|
||||
|
||||
def check_disk():
|
||||
"""检查磁盘空间"""
|
||||
print("=" * 60)
|
||||
print("磁盘空间检查")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
import shutil
|
||||
total, used, free = shutil.disk_usage('.')
|
||||
total_gb = total / (1024**3)
|
||||
free_gb = free / (1024**3)
|
||||
used_percent = (used / total) * 100
|
||||
|
||||
print(f"总空间: {total_gb:.2f} GB")
|
||||
print(f"可用空间: {free_gb:.2f} GB")
|
||||
print(f"已用空间: {used_percent:.1f}%")
|
||||
|
||||
if free_gb >= 10:
|
||||
print("✅ 磁盘空间: 充足 (10GB+)")
|
||||
elif free_gb >= 5:
|
||||
print("✅ 磁盘空间: 足够 (5-9GB)")
|
||||
elif free_gb >= 2:
|
||||
print("⚠️ 磁盘空间: 基础 (2-4GB)")
|
||||
else:
|
||||
print("❌ 磁盘空间: 不足 (<2GB)")
|
||||
print(" 建议清理磁盘空间")
|
||||
|
||||
except Exception as e:
|
||||
print(f"❌ 磁盘检测失败: {e}")
|
||||
|
||||
print()
|
||||
|
||||
def get_recommendation():
|
||||
"""给出综合建议"""
|
||||
print("=" * 60)
|
||||
print("综合评估与建议")
|
||||
print("=" * 60)
|
||||
|
||||
try:
|
||||
cpu_count = os.cpu_count() or 4
|
||||
try:
|
||||
import psutil
|
||||
mem = psutil.virtual_memory()
|
||||
total_gb = mem.total / (1024**3)
|
||||
except ImportError:
|
||||
total_gb = 8 # 假设8GB
|
||||
|
||||
# 综合评分
|
||||
score = 0
|
||||
recommendations = []
|
||||
|
||||
# CPU评分
|
||||
if cpu_count >= 8:
|
||||
score += 30
|
||||
cpu_status = "优秀"
|
||||
elif cpu_count >= 4:
|
||||
score += 20
|
||||
cpu_status = "良好"
|
||||
elif cpu_count >= 2:
|
||||
score += 10
|
||||
cpu_status = "基础"
|
||||
else:
|
||||
cpu_status = "不足"
|
||||
|
||||
# 内存评分
|
||||
if total_gb >= 16:
|
||||
score += 30
|
||||
mem_status = "优秀"
|
||||
elif total_gb >= 8:
|
||||
score += 20
|
||||
mem_status = "良好"
|
||||
elif total_gb >= 4:
|
||||
score += 10
|
||||
mem_status = "基础"
|
||||
else:
|
||||
mem_status = "不足"
|
||||
|
||||
# Python版本评分
|
||||
if sys.version_info >= (3, 10):
|
||||
score += 20
|
||||
elif sys.version_info >= (3, 8):
|
||||
score += 15
|
||||
|
||||
# 系统评分
|
||||
if platform.system() == 'Windows' and ('64' in platform.machine() or 'AMD64' in platform.machine()):
|
||||
score += 20
|
||||
|
||||
# 给出建议
|
||||
print(f"综合评分: {score}/100")
|
||||
print()
|
||||
|
||||
if score >= 80:
|
||||
print("✅ 你的电脑非常适合多线程处理!")
|
||||
print(" 建议:")
|
||||
print(" - 使用 6-8 个线程")
|
||||
print(" - 可以充分利用多核CPU")
|
||||
print(" - 性能提升: 60-70%")
|
||||
elif score >= 60:
|
||||
print("✅ 你的电脑适合多线程处理")
|
||||
print(" 建议:")
|
||||
print(" - 使用 4-6 个线程")
|
||||
print(" - 可以正常使用多线程")
|
||||
print(" - 性能提升: 40-50%")
|
||||
elif score >= 40:
|
||||
print("⚠️ 你的电脑可以运行多线程,但效果有限")
|
||||
print(" 建议:")
|
||||
print(" - 使用 2-3 个线程")
|
||||
print(" - 性能提升: 20-30%")
|
||||
else:
|
||||
print("❌ 你的电脑不太适合多线程处理")
|
||||
print(" 建议:")
|
||||
print(" - 使用单线程或2线程")
|
||||
print(" - 考虑升级硬件")
|
||||
|
||||
print()
|
||||
print(f"CPU状态: {cpu_status} ({cpu_count}核)")
|
||||
print(f"内存状态: {mem_status} ({total_gb:.1f}GB)")
|
||||
|
||||
except Exception as e:
|
||||
print(f"评估失败: {e}")
|
||||
|
||||
def main():
|
||||
"""主函数"""
|
||||
print("\n" + "=" * 60)
|
||||
print("系统配置检查 - 多线程处理适配性分析")
|
||||
print("=" * 60)
|
||||
print()
|
||||
|
||||
check_system()
|
||||
check_python()
|
||||
check_cpu()
|
||||
check_memory()
|
||||
check_disk()
|
||||
get_recommendation()
|
||||
|
||||
print()
|
||||
print("=" * 60)
|
||||
print("检查完成")
|
||||
print("=" * 60)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user