Skip to content

Commit b1a05d1

Browse files
miguelinuxwenlingz
authored andcommitted
crashlog: re-write usercrash-wrapper
Using an O(n^2) function for look up the values from the arguments simplify the complexity code of the userchrash-wrapper. Tracked-On: #1386 Signed-off-by: Miguel Bernal Marin <miguel.bernal.marin@linux.intel.com> Reviewed-by: Zhi Jin <zhi.jin@intel.com> Acked-by: Chen Gang <gang.c.chen@intel.com>
1 parent 6981a4d commit b1a05d1

File tree

1 file changed

+18
-94
lines changed

1 file changed

+18
-94
lines changed

tools/acrn-crashlog/data/usercrash-wrapper

Lines changed: 18 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -17,38 +17,26 @@ if [ ! -f $default_core_pattern_file ]; then
1717
exit -1
1818
fi
1919

20-
# default coredump app and usercrash parameters index file under /tmp
21-
d_param_index_file=/tmp/default_param_index_file
22-
u_param_index_file=/tmp/usercrash_param_index_file
20+
# We know the parameter order
21+
my_order=(%E %P %u %g %s %t %c %h %e %p %i %I %d)
22+
my_params=($*)
2323

24-
# function to get the params from the input arguments
24+
# An O(n^2) function to look up the value
2525
function get_params()
2626
{
27-
raw_params=$1
28-
29-
count=$[(${#raw_params} + 1) / 3]
30-
for((i=0;i<$count;i++))
31-
do
32-
a_index=$[$i * 3 + 1]
33-
param_list[$i]=${raw_params:($a_index):1}
34-
done
35-
return 0;
36-
}
37-
38-
# function to generate the index for the parameters of default coredump app
39-
function gen_index()
40-
{
41-
full_list=$1
42-
dump_list=$2
43-
44-
i=0
45-
for arg in ${dump_list[@]}
27+
local ret=""
28+
for args in $*
4629
do
47-
q=(`expr \`expr $(expr index "$full_list" "$arg") + 1\` / 2`)
48-
index[$i]=$[$q - 1]
49-
let i+=1
30+
for index in ${!my_order[@]}
31+
do
32+
if [ ${my_order[${index}]} = ${args} ]
33+
then
34+
ret="${ret} ${my_params[${index}]}"
35+
break
36+
fi
37+
done
5038
done
51-
return 0;
39+
echo ${ret}
5240
}
5341

5442
# get default core_pattern parameters list
@@ -59,71 +47,7 @@ default_params=${default_content#* }
5947
t_app=${default_content%% *}
6048
default_app=${t_app#*|}
6149

62-
# function to save the index to /tmp. The index is the parameter
63-
# index of the default coredump app and usercrash referring to
64-
# the full parameters.
65-
function save_index()
66-
{
67-
# get full coredump parameters list
68-
pattern=`cat /proc/sys/kernel/core_pattern`
69-
full_params=${pattern#* }
70-
71-
get_params "$full_params"
72-
for((i=0;i<$count;i++))
73-
do
74-
full_param_list[$i]=${param_list[$i]}
75-
done
76-
77-
get_params "$default_params"
78-
for((i=0;i<$count;i++))
79-
do
80-
default_param_list[$i]=${param_list[$i]}
81-
done
82-
83-
# get the index of default parameter list accroding to
84-
# the full parameter list
85-
gen_index "${full_param_list[*]}" "${default_param_list[*]}"
86-
for((j=0;j<$i;j++))
87-
do
88-
default_param_index[$j]=${index[$j]}
89-
done
90-
echo "${default_param_index[@]}" > $d_param_index_file
91-
92-
# get the index of usercrash_c parameter accroding to
93-
# the full parameter list
94-
usercrash_param_list=("p" "e" "s")
95-
gen_index "${full_param_list[*]}" "${usercrash_param_list[*]}"
96-
for((j=0;j<$i;j++))
97-
do
98-
usercrash_param_index[$j]=${index[$j]}
99-
done
100-
echo "${usercrash_param_index[@]}" > $u_param_index_file
101-
}
102-
103-
if [[ ! -f $d_param_index_file ]] || [[ ! -f $u_param_index_file ]];then
104-
save_index
105-
fi
106-
107-
# get all the value of parameters in var[]
108-
i=0
109-
for p in "$@"
110-
do
111-
var[$i]=$p
112-
let i+=1
113-
done
114-
115-
str_usercrash_param_index=`cat $u_param_index_file`
116-
u_param_index_arr=(${str_usercrash_param_index// / })
117-
for((i=0;i<${#u_param_index_arr[@]};i++))
118-
do
119-
usercrash_var[$i]=${var[${u_param_index_arr[$i]}]}
120-
done
121-
122-
str_default_param_index=`cat $d_param_index_file`
123-
d_param_index_arr=(${str_default_param_index// / })
124-
for((i=0;i<${#d_param_index_arr[@]};i++))
125-
do
126-
default_var[$i]=${var[${d_param_index_arr[$i]}]}
127-
done
50+
usercrash_var=$(get_params "%p %e %s")
51+
default_var=$(get_params ${default_params})
12852

129-
tee >(/usr/bin/usercrash_c ${usercrash_var[*]}) | $default_app ${default_var[*]}
53+
tee >(/usr/bin/usercrash_c ${usercrash_var}) | ${default_app} ${default_var}

0 commit comments

Comments
 (0)