代码拉取完成,页面将自动刷新
import os
import pandas as pd
print("start processing perf results")
# 创建一个字典来统计每个 `a` 部分出现的次数
count={}
pn=['duration time','task clock','cpu-cycles','instructions','cache references','cache misses','branches','branch misses','L1 dcache loads',
'L1 dcache load misses','LLC load misses','LLC load','IPC']
def process_txt_file(file_path,test_name):
with open(file_path, 'r') as file:
lines = file.readlines()
if len(lines) != 15:
print(f"Warning: {file_path} does not contain exactly 14 lines.")
return None
if(count[test_name]>1):
name=lines[0].strip()+lines[1].strip()
else:
name = lines[0].strip()
data = []
for i in range(2,len(lines)):
# data[i-1][0]=name
# data[i-1][1]=lines[i].strip()
data.append([name,pn[i-2],lines[i].strip()])
return data
def count_a_occurrences(directory):
# 遍历目录中的所有文件
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith('.txt'):
parts = file.split('-', 1)
if len(parts) == 2:
test_name = parts[0]
if test_name in count:
count[test_name] += 1
else:
count[test_name] = 1
def main(input_directory, output_file):
count_a_occurrences(input_directory)
all_data = []
for file_name in os.listdir(input_directory):
if file_name.endswith('.txt'):
parts=file_name.split('-',1)
file_path = os.path.join(input_directory, file_name)
file_data = process_txt_file(file_path,parts[0])
if file_data:
for i in range(len(file_data)):
all_data.append(file_data[i])
# Create a DataFrame
columns = ['Test Name','Performance Name','Performance Value']
df = pd.DataFrame(all_data, columns=columns)
# Write DataFrame to an Excel file
df.to_excel(output_file, index=False)
print("success save perf results to perf_result.xlsx")
if __name__ == "__main__":
input_directory = 'perf' # Change to your directory
output_file = 'perf_result.xlsx'
main(input_directory, output_file)
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。