# AFExecuteProcessRequestbegin AFExecuteProcessRequestend
# main function:主要实现把txt中的关键数据写入到excel中
# coding=utf-8
import os
import re
import csv
if __name__ == '__main__':
html_path = os.getcwd()
with open("评估结果.csv", "w", newline="") as csvfile:
writer = csv.writer(csvfile)
writer.writerow(['AFExecuteProcessRequestbegin_CPU', 'AFExecuteProcessRequestend_CPU',
'AFExecuteProcessRequestbegin_TIMESTAMP(ms)',
'AFExecuteProcessRequestend_TIMESTAMP(ms)', 'Cpu wall duration(ms)'])
file_html = html_path + "//" + "trace.html"
html_jiexi = open(file_html, 'r', encoding="GBK")
html_read = html_jiexi.readlines()
flag = 0
temp = []
for i in html_read:
if len(temp) == 4:
if temp[0] == temp[1]:
print(temp)
writer.writerow(temp)
temp.clear()
AFE = i.strip()
if AFE.find("AFExecuteProcessRequestbegin") != -1:
AFE_begin = float(i.split(":")[0].split(" ")[-1])
begin = i.split("[")[-1][0:3]
if flag == 0:
# print(i.split(":")[-1])
# print(begin)
# print(AFE_begin)
temp.append(begin)
temp.insert(2, AFE_begin)
flag = 1
if AFE.find("AFExecuteProcessRequestend") != -1:
# print(i.split(":")[0].split(" ")[-1])
AFE_end = float(i.split(":")[0].split(" ")[-1])
end = i.split("[")[-1][0:3]
if flag == 1:
# print(i.split(":")[-1])
# print(end)
# print(AFE_end)
temp.insert(1, end)
temp.append(AFE_end)
flag = 0
将文本中关键信息保存到Excel表格中
最新推荐文章于 2024-05-15 16:35:03 发布