cpu

#!/usr/bin/env python

-- coding: utf-8 --

import matplotlib.pyplot as plt
import numpy as np
import sys
import datetime

修改文件路径

filePath = “/home/st/Desktop/draw-performance-pgen5/”
file_tag = “Performance”
x_time = 0
x_cpu = 1
x_mem = 2
nowTime=datetime.datetime.now().strftime(’%Y-%m-%d’)

filename = sys.argv[1]

x轴显示时间标签

x_lable = []
i = 0
with open(filePath + filename, ‘r’) as perf_file:
line = perf_file.readline()
while line:
i += 1
x_lable.append(str(line.strip().split(’,’)[x_time].split(’ ')[1]).strip())
line = perf_file.readline()

cpu图

x = np.arange(i)
z = np.loadtxt(filePath + filename, delimiter=",", usecols=(x_cpu), unpack=True)
#plt.bar(x, z, facecolor=’#79b3f2’, edgecolor=‘none’)
plt.plot(x, z, color=‘b’, label=‘mem’)

x轴显示时间标签的个数 (30个)

x_show_num = 30
N = i
if N > x_show_num:
x_freq = N / x_show_num
x_show = list(x)[::x_freq]
x_lable_show = x_lable[::x_freq]
else:
x_show = x
x_lable_show = x_lable

x轴显示时间的倾斜角

plt.xlim(x_lable_show[0], x_lable_show[len(x_lable_show) - 1])
plt.ylim(0,400)
plt.xticks(x_show, x_lable_show, rotation=90)
plt.subplots_adjust(bottom=0.35)
plt.grid(True)

plt.legend([‘MIN=%d%%, MAX=%d%%, AVG=%d%%’%(min(z),max(z),round(np.mean(z),2))])

x轴标题

plt.xlabel(‘Time/s’)

y轴标题

plt.ylabel(‘CPU/%’)

title

if filename == ‘performance-guide.txt’:
plt.title(’%s Navigation CPU Without ADAS %s’ %(nowTime, file_tag))
cpu_fig_name = ‘%s-guide-cpu-without-adas.png’ % nowTime
elif filename == ‘performance-guide-adas.txt’:
plt.title(’%s Navigation CPU With ADAS %s’ %(nowTime, file_tag))
cpu_fig_name = ‘%s-guide-cpu-with-adas.png’ % nowTime
elif filename == ‘performance-cruise.txt’:
plt.title(’%s Cruise CPU Without ADAS %s’ %(nowTime, file_tag))
cpu_fig_name = ‘%s-cruise-cpu-without-adas.png’ % nowTime
else:
plt.title(’%s Cruise CPU With ADAS %s’ %(nowTime, file_tag))
cpu_fig_name = ‘%s-cruise-cpu-with-adas.png’ % nowTime
plt.savefig(cpu_fig_name)
plt.close()

mem图

y = np.loadtxt(filePath + filename, delimiter=",", usecols=(x_mem), unpack=True)

将获取的mem KB转成MB,保留两位小数

for item in range(0, i):
y[item] = round(y[item]/1024.0, 2)
#plt.bar(x, y, facecolor=’#79b3f2’, label=‘mem’, edgecolor=‘none’)
plt.plot(x, y, color=‘b’, label=‘mem’)

x轴显示时间的倾斜角

plt.xlim(x_lable_show[0], x_lable_show[len(x_lable_show) - 1])
plt.ylim(0,2000)
plt.xticks(x_show, x_lable_show, rotation=90)
plt.subplots_adjust(bottom=0.35)
plt.grid(True)
plt.legend([‘MIN=%dMB, MAX=%dMB, AVG=%dMB’%(float(min(y)),float(max(y)),round(np.mean(y),2))])

x轴标题

plt.xlabel(‘Time/s’)

y轴标题

plt.ylabel(‘Mem/MB’)

title

if filename == ‘performance-guide.txt’:
plt.title(’%s Navigation Memory Without ADAS %s’ %(nowTime, file_tag))
mem_fig_name = ‘%s-guide-mem-without-adas.png’ % nowTime
elif filename == ‘performance-guide-adas.txt’:
plt.title(’%s Navigation Memory With ADAS %s’ %(nowTime, file_tag))
mem_fig_name = ‘%s-guide-mem-with-adas.png’ % nowTime
elif filename == ‘performance-cruise.txt’:
plt.title(’%s cruise Memory Without ADAS %s’ %(nowTime, file_tag))
mem_fig_name = ‘%s-cruise-mem-without-adas.png’ % nowTime
else:
plt.title(’%s Cruise Memory With ADAS %s’ %(nowTime, file_tag))
mem_fig_name = ‘%s-cruise-mem-with-adas.png’ % nowTime
plt.savefig(mem_fig_name)
plt.close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值