-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirst_perf_script
More file actions
executable file
·44 lines (33 loc) · 1.49 KB
/
first_perf_script
File metadata and controls
executable file
·44 lines (33 loc) · 1.49 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
#!/bin/bash
#This script measures CPU temps and clock every second
# exits the script when any command fails
set -e
# if the scripts catches a "USR1" signal, or an interruption signal, it will exit itself
trap "exit" USR1 SIGHUP SIGINT SIGTERM
# specifying all excutables' paths for newly installed packages and some file names
readonly RM=/bin/rm
readonly SUDO=/usr/bin/sudo
readonly VCGENCMD=/usr/bin/vcgencmd
readonly AWK=/usr/bin/awk
readonly EGREP=/bin/egrep
readonly CUT=/usr/bin/cut
readonly SLEEP=/bin/sleep
readonly FILENAME=kernel_performance_data
# deletes the previous data files in case it exists to avoid conflict
$SUDO $RM -rf $FILENAME
# prints the header to the data file, with a tab delimitor
$AWK -v OFS='\t' 'BEGIN { printf "%s\t%s\t%s\n", "Second elapsed", "Temperature(degrees C)", "CPU Clock(Mhz)" }' >>$FILENAME
# the second variable
second=0
while true #creates an infinite loop until the script exits itself
do
# gets cpu temp and clock using vcgencmd, and uses egrep and cut to get its numeric value
temp=$($SUDO $VCGENCMD measure_temp | $EGREP -o '[0-9]*\.[0-9]*')
cpu_clock=$($SUDO $VCGENCMD measure_clock arm | $CUT -d '=' -f 2-)
# prints the tab-delimited data to the file
$AWK -v OFS='\t' -v second="$second" -v temp="$temp" -v cpu_clock="$((cpu_clock/1000000))" 'BEGIN { printf "%s\t%s\t%s\n", second, temp, cpu_clock }' >>$FILENAME
# increments the second by 1
second=$((second + 1))
# puts the process to sleep for 1 second
$SLEEP 1
done