-
Notifications
You must be signed in to change notification settings - Fork 3
/
set_probes_func.sh
57 lines (48 loc) · 1.84 KB
/
set_probes_func.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
#!/bin/bash
# script to set probes in a lib using function list in text file.
# Generate list of functions from .c files
# ctags --c-kinds=f -x --fields=+n intel_display.c intel_dpll_mgr.c | awk '{print $1}' > func.txt
# Syntax:
# set_probes_func.sh <path to.ko/.so> func.txt
#
# TIPS:
# Capture probes
# $ sudo perf record -e probe:* -g -a
#
# Get unique names of triggered functions
# $ sudo perf script | sed 's/^[ \t]*//;s/[ \t]*$//' | tr -s ' ' | awk -F'[ ]' '{print $5}' | awk -F'[:]' '{print$2}' | sort | uniq > function.txt
# Get count of each function
# $ sudo perf script | sed 's/^[ \t]*//;s/[ \t]*$//' | tr -s ' ' | awk -F'[ ]' '{print $5}' | awk -F'[:]' '{print$2}' | sort | uniq -c | sort -nr
# Check if sufficient arguments were provided
if [ "$#" -ne 2 ]; then
echo "Usage: $0 <module_path> <function_list_file>"
exit 1
fi
# Assign command-line arguments to variables
MODULE_PATH="$1"
FUNCTION_LIST="$2"
# Check if the module path is valid
if [ ! -f "$MODULE_PATH" ]; then
echo "Error: Module path '$MODULE_PATH' does not exist."
exit 2
fi
# Check if the function list file exists
if [ ! -f "$FUNCTION_LIST" ]; then
echo "Error: Function list file '$FUNCTION_LIST' does not exist."
exit 3
fi
# Calculate the total number of functions to process
total_functions=$(wc -l < "$FUNCTION_LIST")
if [ "$total_functions" -eq 0 ]; then
echo "Error: No functions to process in '$FUNCTION_LIST'."
exit 4
fi
# Initialize a counter for the current function number
current_function=0
# Read each function name and set a probe
while IFS= read -r function_name; do
((current_function++))
echo "Setting probe on function $current_function/$total_functions: $function_name"
sudo perf probe -m "$MODULE_PATH" -a "$function_name"
done < "$FUNCTION_LIST"
echo "Finished setting probes on all $total_functions functions."