forked from camel-clarkson/K-LEB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinitialize.sh
executable file
·76 lines (68 loc) · 1.92 KB
/
initialize.sh
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/bin/bash
# Config: Event Counters, Timer Delay, Log path, Program Name
declare -a counter
num_event=0
config_cfg="./perf.cfg"
init_log_path=$(pwd)
# Read events from configuration file
while IFS= read -r line
do
if [[ $line =~ ^#.* ]]
then
fconfig=""
else
fconfig=$line
fi
if [ ! -z $fconfig ]
then
let "num_event+=1"
counter[$num_event]=$fconfig
fi
done < "$config_cfg"
printf -v joined '%s,' "${counter[@]}"
events="${joined%,}"
echo "Event: $events"
# Run script
while true ; do
echo "K-LEB program script"
PS3='Select your option: '
options=("Start monitoring" "Setup the kernel module" "Unload the kernel module" "Exit")
select opt in "${options[@]}"
do
case $opt in
"Start monitoring")
read -p "Enter hrtimer (in ms): " hrtimer
[ -z "$hrtimer" ] && hrtimer=1
read -p "Enter program to monitor with parameters: " target_path
log_path=$init_log_path"/Output.csv"
#config="${counter[@]} $hrtimer $log_path $target_path"
config="-e $events -t $hrtimer -o $log_path $target_path"
echo $config
> $log_path
sudo ./ioctl_start $config
echo "-------------------------------------------"
break
;;
"Unload the kernel module")
make clean
sudo rm /dev/kleb
sudo rmmod kleb
echo "-------------------------------------------"
break
;;
"Setup the kernel module")
make
sudo insmod kleb.ko
maj_num=$(dmesg | tail -n 5 | grep "The major number for your device is" | sed 's/^.*\([0-9][0-9][0-9]\)$/\1/g')
sudo mknod /dev/kleb c $maj_num 0
echo "-------------------------------------------"
break
;;
"Exit")
exit
break
;;
*) echo "invalid option $REPLY"
esac
done
done