代码拉取完成,页面将自动刷新
#!/bin/bash
# $1: Complete execution command $2: store folder for generated file
# eg: ./performance_counter.sh "./hackbench -s 512 -l 200 -g 15 -f 25 -P" /home
if [ $# -ne 2 ]; then
echo "Usage: ./performance_counter.sh parameter1 parameter2"
exit 1
fi
echo "parameter1=$1"
result=$(echo "$1" | grep -oP '(?<=\s)\./\S*')
pkg2=$(echo "$result" | sed 's|^\./||' | sed 's/\//_/g')
result1=$(echo "$1" | sed 's:.*/::')
result2=$(echo "$1" | sed 's/.*^\(.*\)\$.*/\1/')
file_name="$result2-$pkg2"
echo "file name : $file_name"
echo "path: $result"
# 检查文件是否存在于目标文件夹中
if [ -f "$2/$file_name.txt" ]; then
echo "$file_name.txt already exists in $2. Skipping test."
exit 0
fi
if [ -f "performance.txt" ]; then
rm -f performance.txt
echo "performance.txt has been deleted"
fi
perf stat --sync -e duration_time,task-clock,cycles,instructions,cache-references,cache-misses,branches,branch-misses,L1-dcache-loads,L1-dcache-load-misses,LLC-load-misses,LLC-loads -r 1 -o performance.txt $1
awk '{print $1, $2, $3}' performance.txt > performance_tmp.txt
mv performance_tmp.txt performance.txt
duration_time=$(grep "duration_time" performance.txt | awk '{print $1}' | sed 's/,//g')
task_clock=$(grep "task-clock" performance.txt | awk '{print $1}' | sed 's/,//g')
cpu_cycle=$(grep "cycles" performance.txt | awk '{print $1}' | sed 's/,//g')
instruction=$(grep "instructions" performance.txt | awk '{print $1}' | sed 's/,//g')
cache_references=$(grep "cache-references" performance.txt | awk '{print $1}' | sed 's/,//g')
cache_misses=$(grep "cache-misses" performance.txt | awk '{print $1}' | sed 's/,//g')
branches=$(grep "branches" performance.txt | awk '{print $1}' | sed 's/,//g')
branch_misses=$(grep "branch-misses" performance.txt | awk '{print $1}' | sed 's/,//g')
L1_dcache_loads=$(grep "L1-dcache-loads" performance.txt | awk '{print $1}' | sed 's/,//g')
L1_dcache_load_misses=$(grep "L1-dcache-load-misses" performance.txt | awk '{print $1}' | sed 's/,//g')
LLC_load_misses=$(grep "LLC-load-misses" performance.txt | awk '{print $1}' | sed 's/,//g')
LLC_loads=$(grep "LLC-loads" performance.txt | awk '{print $1}' | sed 's/,//g')
printf "\n\n"
echo "Avg 10 times duration time: $duration_time"
printf "Avg 10 times task clock: %.3f\n" $task_clock
echo "Avg 10 times cpu-cycles: $cpu_cycle"
echo "Avg 10 times instructions: $instruction"
echo "Avg 10 times cache references: $cache_references"
echo "Avg 10 times cache misses: $cache_misses"
echo "Avg 10 times branches: $branches"
echo "Avg 10 times branch misses: $branch_misses"
echo "Avg 10 times L1 dcache loads: $L1_dcache_loads"
echo "Avg 10 times L1 dcache load misses: $L1_dcache_load_misses"
echo "Avg 10 times LLC load misses: $LLC_load_misses"
echo "Avg 10 times LLC load: $LLC_loads"
IPC=$(echo "scale=3; $instruction / $cpu_cycle" | bc)
printf "Avg 10 times IPC: %.3f\n" $IPC
if [ -f "$file_name.txt" ]; then
rm -f $file_name.txt
echo "$file_name.txt has been deleted"
fi
echo "$result2" >> $file_name.txt
echo "($result)" >> $file_name.txt
echo $duration_time >> $file_name.txt
echo $task_clock >> $file_name.txt
echo $cpu_cycle >> $file_name.txt
echo $instruction >> $file_name.txt
echo $cache_references >> $file_name.txt
echo $cache_misses >> $file_name.txt
echo $branches >> $file_name.txt
echo $branch_misses >> $file_name.txt
echo $L1_dcache_loads >> $file_name.txt
echo $L1_dcache_load_misses >> $file_name.txt
echo $LLC_load_misses >> $file_name.txt
echo $LLC_loads >> $file_name.txt
printf "%.3f\n" $IPC >> $file_name.txt
mv $file_name.txt $2
printf "perf测试结束\n\n"
rm -f performance.txt
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。