da-tool check for duplicate configurations

(cherry picked from commit 06104476f1b3de8cc1530791b2190d69a8165af5)
This commit is contained in:
LHesperus 2023-11-23 21:57:25 +08:00 committed by openeuler-sync-bot
parent 0013f6ffbb
commit 425a3c1f34
2 changed files with 147 additions and 1 deletions

View File

@ -0,0 +1,141 @@
From e20bd8319c893134e8496ee41edd23fb17a13780 Mon Sep 17 00:00:00 2001
From: LHesperus <2639350497@qq.com>
Date: Thu, 23 Nov 2023 20:57:39 +0800
Subject: [PATCH] add usage and repet config check
---
extra-tools/da-tool/script/da-tool.sh | 67 ++++++++++++++++++++++++---
1 file changed, 60 insertions(+), 7 deletions(-)
mode change 100644 => 100755 extra-tools/da-tool/script/da-tool.sh
diff --git a/extra-tools/da-tool/script/da-tool.sh b/extra-tools/da-tool/script/da-tool.sh
old mode 100644
new mode 100755
index ccc3443..efc9592
--- a/extra-tools/da-tool/script/da-tool.sh
+++ b/extra-tools/da-tool/script/da-tool.sh
@@ -74,9 +74,18 @@ handle_error() {
trap 'handle_error' ERR
+function usage() {
+ echo ""
+ echo "usage: da-tool.sh [OPTIONS] [ARGS]"
+ echo ""
+ echo "The most commonly used da-tool.sh options are:"
+ echo " -t <duration> set tracing duration, unit: seconds, 1<=duration<=100, default is 10"
+ echo " -h show usage"
+}
+
# get opt
# while getopts "b:l:t:p:as" opt; do # debug
-while getopts "t:" opt; do
+while getopts "t:h" opt; do
case $opt in
a)
is_analysis_only_mode=true
@@ -87,7 +96,12 @@ while getopts "t:" opt; do
is_sample_with_analysis=false
;;
t)
- sleep_time=$OPTARG
+ if [[ $OPTARG =~ ^[0-9]+$ ]]; then
+ sleep_time=$OPTARG
+ else
+ usage
+ exit 1
+ fi
;;
p)
parameter="$OPTARG"
@@ -96,8 +110,13 @@ while getopts "t:" opt; do
pid_filter+=("$value")
done
;;
+ h)
+ usage
+ exit 1
+ ;;
\?)
echo "Invalid option: -$OPTARG" >&2
+ usage
exit 1
;;
esac
@@ -130,6 +149,37 @@ function config_display() {
done
}
+function arr_repet_ele_check() {
+ local arr=("$@")
+ for element in "${arr[@]}"; do
+ count=$(printf '%s\n' "${arr[@]}" | grep -c -w "$element")
+ if [ $count -ge 2 ]; then
+ echo " '$element' duplicate configuration, please check '$config_file'"
+ exit 1
+ fi
+ done
+}
+
+function config_file_check() {
+ arr_repet_ele_check ${kernel_symbols[@]} # check kernel
+ arr_repet_ele_check ${sched_symbols[@]} # check sched
+
+ spl_begin=0
+ declare -a target_path_tmp
+ declare -a user_symbols_arr_tmp
+ for ((i = 0; i < ${#user_symbols_arr_split[@]}; i++)); do
+ spl_end=${user_symbols_arr_split[$i]}
+ unset user_symbols_arr_tmp
+ target_path_tmp[${#target_path_tmp[*]}]=${user_symbols_arr[$((${spl_begin}))]}${user_symbols_arr[$((${spl_begin} + 1))]}
+ for ((j = ${spl_begin} + 2; j < ${spl_end}; j++)); do
+ user_symbols_arr_tmp[${#user_symbols_arr_tmp[*]}]=${user_symbols_arr[$j]}
+ done
+ spl_begin=${spl_end}
+ arr_repet_ele_check ${user_symbols_arr_tmp[@]} # check user symbol of same bin
+ done
+ arr_repet_ele_check "${target_path_tmp[@]}" # check bin
+}
+
function config_file_resolve() {
cum_tmp=0
while IFS= read -r line; do
@@ -166,6 +216,7 @@ function config_file_resolve() {
mkdir -p $sample_log_dir
touch $sample_log
config_display
+ config_file_check
}
function gen_config_for_analysis() {
@@ -191,13 +242,15 @@ function gen_config_for_analysis() {
function opt_check() {
if [ $is_uprobe_sample = false ] && [ $is_kprobe_sample = false ]; then
echo "use -m u|k|uk to set uprobe/kprobe/both"
+ usage
exit 1
fi
- if [ $sleep_time -ge $((sleep_time_max+1)) ] || [ $sleep_time -le 0 ];then
- echo "sampling time should > 0 and <= $sleep_time_max"
- exit 1
- fi
+ if [ $sleep_time -ge $((sleep_time_max + 1)) ] || [ $sleep_time -le 0 ]; then
+ echo "sampling time should > 0 and <= $sleep_time_max"
+ usage
+ exit 1
+ fi
}
function clear_env() {
@@ -462,6 +515,6 @@ echo >/sys/kernel/debug/tracing/uprobe_events
echo >/sys/kernel/debug/tracing/kprobe_events
echo "sample finish"
-if [ $is_sample_with_analysis = true ]; then # only sample
+if [ $is_sample_with_analysis = true ]; then
trace_analysis
fi
--
2.33.0

View File

@ -2,7 +2,7 @@
Name: aops-ceres
Version: v1.3.4
Release: 8
Release: 9
Summary: An agent which needs to be adopted in client, it managers some plugins, such as gala-gopher(kpi collection), fluentd(log collection) and so on.
License: MulanPSL2
URL: https://gitee.com/openeuler/%{name}
@ -13,6 +13,7 @@ Patch0003: 0003-fix-bug-in-test_hotpatch.py.patch
Patch0004: 0004-Modify-method-of-mark-invalid-data-and-add-summary.patch
Patch0005: 0005-add-specific-error-information.patch
Patch0006: 0006-update-return-log-field-of-the-cve-fix-func.patch
Patch0007: 0007-add-usage-and-repet-config-check.patch
BuildRequires: python3-setuptools
Requires: python3-requests python3-jsonschema python3-libconf
@ -92,6 +93,10 @@ install -b -m755 ./extra-tools/da-tool/script/da-tool.sh ${RPM_BUILD_ROOT}
%attr(755, root, root) %{_bindir}/da-tool-analysis
%changelog
* Thu Nov 23 2023 liuchanggeng<liuchanggeng@huawei.com> - v1.3.4-9
- da-tool add usage
- da-tool check for duplicate configurations
* Tue Nov 21 2023 wenxin<wenxin32@foxmail.com> - v1.3.4-8
- update return log field of the cve fix func
- add specific error information