[Work][Python]Spec power automation-4

Fatboy Slim
3 min readMay 15, 2020

--

Environment: Windows server 2019, python 2.7

This blog follows from the previous blog.

There are three steps which I want to develop for automation.

  1. Produce related setting file SPECpower_ssj_EXPERT, SPECpower_ssj_config_sut1, runssj.batch automatically.
  2. Run spec power, related stress, record related power consumption and ambient temperature.
  3. Plot chart and output report value automatically.

In this section of this blog, the target is output a summary excel and plot chart.

There are four types from spec power log.

  1. Temperature is record from thermal cable.

2. Power from Intel PTU.

3. Windows cpu usage log.

4.Spec power log.

We need get time interval from each loading 100%, 70%, 50%, 30% and idle to get 1, 2, 3 data log. For example, we need get 10:39:23 PM to 11:00:25 PMdata.

My solution is that all time covert to 24-hour clock and compute it as sec number. For example, 22:39:23 is 22 x60 x60 + 39x60+23=81563 and 23:00:25 is 23x60x60+0x60+25=82825. So we can get 81563 to 82825 data. The code is as below.

Convert time to 24-hour clock.

def twenfour(ins):
time_24=''
ins=ins.strip()
is_pm = ins[-2:].lower() == 'pm'
time_list = list(map(int, ins[:-2].split(':')))

if is_pm and time_list[0] < 12:
time_list[0] += 12
if not is_pm and time_list[0] == 12:
time_list[0] = 0
time_24=':'.join(map(lambda x: str(x).rjust(2, '0'),time_list))
return time_24

Convert time to sec number.

def time2int(n):
time_list = list(map(int, n.split(':')))
t_sum=(time_list[0]*60*60)+(time_list[1]*60)+time_list[2]
return t_sum

Output time point for getting record data.

def timepoint(day,time24, df,x,y,z,s):
timeindf=''
l=len(time24)
dl=len(df)
time_point=[]
for j in range(l):
for i in range(s,dl):
if day[j] in df[x][i]:
timeindf=df[x][i][y:z].strip()
diff=time24[j]-time2int(timeindf)
if diff<6 and diff>-6:
time_point.append(i)
break
return time_point

Save output excel is by using below code.

writer = pd.ExcelWriter('C:\Spec_power_auto\Summary.xlsx', engine='xlsxwriter')dx.to_excel(writer, sheet_name='Sheet1')writer.save()

If I can get log successfully, we can output plot chart as below code.

def plotcpu(a, alltime2,all_data1,all_data2,b,c):
plt.ylabel(a)
plt.xlabel('Time ')
plt.xticks(np.arange(0, len(all_time2), 700))
plt.plot(all_time2,all_data1,color='red')
plt.plot(all_data2,color='blue')
plt.legend(['CPU0','CPU1'])
plt.savefig(b+c+'.jpeg')
plt.show()

The summary example is as below.

The plot chart is as below.

Reference:

http://www.spec.org/power_ssj2008/

--

--

Fatboy Slim
Fatboy Slim

Written by Fatboy Slim

Interesting in any computer science.

No responses yet