加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python-确定CPU使用率的时间

发布时间:2020-12-17 17:39:00 所属栏目:Python 来源:网络整理
导读:我有兴趣了解我的系统的CPU使用率保持70%或更高的时间.我的样本数据如下所示.完整数据为here Time CPUDemandPercentage2019-03-06 03:55:00 40.172019-03-06 14:15:00 77.332019-03-06 14:20:00 79.66 为了实现我想要的目标,我进行了以下探索.我试图: 确定

我有兴趣了解我的系统的CPU使用率保持70%或更高的时间.我的样本数据如下所示.完整数据为here

Time                    CPUDemandPercentage
2019-03-06 03:55:00     40.17
2019-03-06 14:15:00     77.33
2019-03-06 14:20:00     79.66

为了实现我想要的目标,我进行了以下探索.我试图:

>确定峰位
>确定峰宽

import numpy as np
import matplotlib.pyplot as plt 
import scipy.signal
from pandas import read_csv
data=read_csv('data.csv',header=0,usecols=["CPUDemandPercentage"])
y = np.array(data['CPUDemandPercentage'])
indexes = scipy.signal.find_peaks_cwt(y,np.arange(1,4))
plt.plot(indexes,y[indexes],"xr"); plt.plot(y); plt.legend(['Peaks'])
plt.show()

这给了我一个像图

Peak

>不太准确,没有显示负峰.我如何在这里提高准确性.
>以及如何找到峰的宽度.

我在这里毫无头绪.有人能帮我吗.

最佳答案
大熊猫的另一个答案:这种解决方案是通用的,在两次测量之间无需有相同的时间增量

df['Time']=df['Time'].apply((lambda x: pd.to_datetime(x)))
df['TimeDelta'] = df['Time'].shift(-1) - df['Time']
filter = df['CPUDemandPercentage'] >= 70.0
df['changes'] = [(x,y) for x,y in zip(filter,filter.shift(-1))]
result  = df[df['changes']==(True,True)]['TimeDelta'].sum()

print(f'TimeCPU>=70%: {result} or {result.total_seconds()/60} minutes')

输出:

TimeCPU>70%: 0 days 03:10:00 or 190.0 minutes

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读