测试场景:客户端内存优化之后需要进行测试,对比优化前和优化后的各场景数据
- 安装,监控1min性能信息
- 打开一个页面,监控1min性能信息
- 打开多个页面,监控1min性能信息
- 使用客户端内部功能,监控1min性能信息
- 重启
测试系统:mac系统和window系统
监控数据:cpu时间,cpu百分比,物理内存,虚拟内存,磁盘读取字节,磁盘写入字节
测试思路:通过各测试场景,监控测试数据的变化
监控性能脚本
def get_process_information_for_mac(name, interval):
"""
根据进程名称获取获取进程相关信息
:param name: 进程名称
:param interval: 信息收集间隔时间
:return:
"""
fonts_pid = None
pids = psutil.process_iter()
for pid in pids:
try:
if (pid.name() == name):
fonts_pid = pid.pid
break
except:
pass
print(fonts_pid)
p = psutil.Process(fonts_pid)
with open("process_monitor_" + name + '_' + str(fonts_pid) + ".csv", "a+") as f:
f.write("当前时间,cpu时间,cpu百分比,物理内存,虚拟内存,磁盘读取字节,磁盘写入字节\n") # titles
while True:
current_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
# cpu时间、cpu百分比,物理内存、虚拟内存、磁盘写入字节,磁盘读取字节
cpu_times = p.cpu_times()
cpu_time = cpu_times.user + cpu_times.system
cpu_percent = p.cpu_percent() # better set interval second to calculate like: p.cpu_percent(interval=0.5)
physical_mem = p.memory_info().rss
virtual_mem = p.memory_info().vms
disk_read_bytes = psutil.disk_io_counters().read_bytes
disk_write_bytes = psutil.disk_io_counters().write_bytes
line = current_time + ',' + '{:.2f}'.format(cpu_time) + ',' + '{:.2%}'.format(cpu_percent) + ',' + '{:.2f}'.format(physical_mem / (10 ** 6)) + ',' + '{:.2f}'.format(virtual_mem / (10 ** 9)) + ',' + str(disk_read_bytes) + ',' + str(disk_write_bytes)
print(line)
f.write(line + "\n")
time.sleep(interval)
性能数据分析
整理csv,建立统计图进行对比
数据对比维度
每一项性能数据,针对优化前和优化后,使用折线图进行整体对比,得出各项的结论
整体性能数据,针对优化前和优化后,使用直方图进行对比,得出结论
最后结合prd,给出是否优化达标的结论