-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprofiling.sh
More file actions
executable file
·52 lines (43 loc) · 1.77 KB
/
profiling.sh
File metadata and controls
executable file
·52 lines (43 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Function to test a single run benchmark and print perf metric results
run_program() {
local algo=$1
local dim=$2
local SEED=$3
local BLOCK_SIZE=$4
perf stat -o rep.txt -e $metrics ./program "$algo" "$dim" "$SEED" "$BLOCK_SIZE" 0 > /dev/null
cat rep.txt
# Extract the metrics from perf report
time=$(cat rep.txt | grep "elapsed" | awk -F ' ' '{print $1}' | tr -d ',' | tr -d ' ')
cycles=$(cat rep.txt | grep "cycles" | awk -F ' ' '{print $1}' | tr -d ',' | tr -d ' ')
instructions=$(cat rep.txt | grep "instructions" | awk -F ' ' '{print $1}' | tr -d ',' | tr -d ' ')
cache_misses=$(cat rep.txt | grep "cache-misses" | awk -F ' ' '{print $1}' | tr -d ',' | tr -d ' ')
cache_references=$(cat rep.txt | grep "cache-references" | awk -F ' ' '{print $1}' | tr -d ',' | tr -d ' ')
# Calculate the Cycles per Instruction (CPI) and cache-miss rate
cpi=0
cache_miss_rate=0
if [ "$instructions" -ne 0 ]; then
cpi=$(echo "scale=10; $cycles / $instructions" | bc)
fi
if [ "$cache_references" -ne 0 ]; then
cache_miss_rate=$(echo "scale=10; $cache_misses / $cache_references" | bc)
fi
# Print the results neatly
echo "Performance Metrics:"
echo "---------------------"
echo "Elapsed Time : $time seconds"
echo "Cycles : $cycles"
echo "Instructions : $instructions"
echo "Cache Misses : $cache_misses"
echo "Cache References : $cache_references"
echo "CPI (Cycles/Instr) : $cpi"
echo "Cache Miss Rate : $cache_miss_rate"
}
# Data for perf to collect
metrics="cycles,instructions,cache-misses,cache-references"
SEED=42
# Run the program and collect metrics
./manfile > /dev/null
run_program "$1" "$2" "$3" "$4"
# Clean up
rm rep.txt