Skip to content

Commit cd85569

Browse files
authored
[VOQ][saidump] Modify generate_dump: replace save_saidump with save_saidump_by_route_size (sonic-net#2972)
* * [saidump] • Saidump for DNX-SAI sonic-net/sonic-buildimage#13561 Solution and modification: To use the redis-db SAVE option to save the snapshot of DB each time and recover later, instead of looping through each entry in the table and saving it. (1) Updated sonic-buildimage/build_debian.sh, to install Python library rdbtools into the host. (2) Updated sonic-buildimage/src/sonic-sairedis/saidump/saidump.cpp, add a new option -r, which updates the rdbtools's output-JSON files' format. (3) Add a new script file: files/scripts/saidump.sh, to do the below steps For each ASIC0, such as ASIC0, #1. Save the Redis data. sudo sonic-db-cli -n asic$1 SAVE > /dev/null sonic-net#2. Move dump files to /var/run/redisX/ docker exec database$1 sh -c "mv /var/lib/redis/dump.rdb /var/run/redis$1/" sonic-net#3. Run rdb command to convert the dump files into JSON files sudo python /usr/local/bin/rdb --command json /var/run/redis$1/dump.rdb | sudo tee /var/run/redis$1/dump.json > /dev/null sonic-net#4. Run saidump -r to update the JSON files' format as same as the saidump before. Then we can get the saidump result in standard output. docker exec syncd$1 sh -c "saidump -r /var/run/redis$1/dump.json" sonic-net#5. clear sudo rm -f /var/run/redis$1/dump.rdb sudo rm -f /var/run/redis$1/dump.json (4) Update sonic-buildimage/src/sonic-utilities/scripts/generate_dump, replace saidump with saidump.sh * * [saidump] • Saidump for DNX-SAI sonic-net/sonic-buildimage#13561
1 parent f1e24ae commit cd85569

File tree

1 file changed

+102
-13
lines changed

1 file changed

+102
-13
lines changed

scripts/generate_dump

+102-13
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ SKIP_BCMCMD=0
5050
SAVE_STDERR=true
5151
RETURN_CODE=$EXT_SUCCESS
5252
DEBUG_DUMP=false
53+
ROUTE_TAB_LIMIT_DIRECT_ITERATION=24000
5354

5455
# lock dirs/files
5556
LOCKDIR="/tmp/techsupport-lock"
@@ -863,24 +864,114 @@ save_redis() {
863864
}
864865

865866
###############################################################################
866-
# SAI DUMP from syncd
867+
# GET ROUTE table size by ASIC id and ip version
868+
# Globals:
869+
# TIMEOUT_MIN
870+
# TIMEOUT_EXIT_CODE
871+
# Arguments:
872+
# asic id
873+
# IP version
874+
# Returns:
875+
# Status: 0 success, otherwise failure
876+
###############################################################################
877+
get_route_table_size_by_asic_id_and_ipver() {
878+
local asic_id="$1"
879+
local ip_ver="$2"
880+
local filepath="/tmp/route_summary.txt"
881+
local ns=""
882+
RC=0
883+
884+
if [[ $NUM_ASICS -gt 1 ]] ; then
885+
ns="-n ${asic_id}"
886+
fi
887+
888+
if [ $ip_ver = "ipv4" ]; then
889+
cmd="vtysh ${ns} -c 'show ip route summary json'"
890+
elif [ $ip_ver = "ipv6" ]; then
891+
cmd="vtysh ${ns} -c 'show ipv6 route summary json'"
892+
else
893+
echo "Wrong argument $ip_ver."
894+
return 255
895+
fi
896+
897+
local timeout_cmd="timeout --foreground ${TIMEOUT_MIN}m"
898+
local cmds="$cmd > '$filepath'"
899+
900+
eval "${timeout_cmd} bash -c \"${cmds}\"" || RC=$?
901+
902+
if [ $RC -eq $TIMEOUT_EXIT_CODE ]; then
903+
echo "Command: $cmds timedout after ${TIMEOUT_MIN} minutes."
904+
return $RC
905+
elif [ $RC -ne 0 ]; then
906+
echo "Command: $cmds failed with RC $RC"
907+
return $RC
908+
fi
909+
910+
local route_tab_size=$(python3 -c "\
911+
import json
912+
with open('$filepath') as json_file:
913+
data = json.load(json_file)
914+
print(data['routesTotal'])")
915+
rm $filepath
916+
echo "$route_tab_size"
917+
}
918+
919+
###############################################################################
920+
# SAI DUMP based on the route table size
921+
# if the route table has more than ROUTE_TAB_LIMIT_DIRECT_ITERATION
922+
# then dump by Redis Save command,
923+
# otherwize, dump it by directly iteration the Redis
924+
#
867925
# Globals:
868926
# NUM_ASICS
927+
# ROUTE_TAB_LIMIT_DIRECT_ITERATION
869928
# Arguments:
870929
# None
871930
# Returns:
872931
# None
873932
###############################################################################
874-
save_saidump() {
933+
save_saidump_by_route_size() {
875934
trap 'handle_error $? $LINENO' ERR
876-
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
877-
save_cmd "docker exec syncd saidump" "saidump"
878-
else
879-
for (( i=0; i<$NUM_ASICS; i++ ))
880-
do
881-
save_cmd "docker exec syncd$i saidump" "saidump$i"
882-
done
883-
fi
935+
936+
for (( i=0; i<$NUM_ASICS; i++ ))
937+
do
938+
route_size_ipv4=`get_route_table_size_by_asic_id_and_ipver $i ipv4`
939+
ret=$?
940+
941+
if [ $ret -ne 0 ]; then
942+
echo "Get route table's size by asicid $i and ipv4 failed."
943+
return $ret
944+
fi
945+
946+
route_size_ipv6=`get_route_table_size_by_asic_id_and_ipver $i ipv6`
947+
ret=$?
948+
949+
if [ $ret -ne 0 ]; then
950+
echo "Get route table's size by asicid $i and ipv6 failed."
951+
return $ret
952+
fi
953+
954+
route_size=`expr $route_size_ipv4 + $route_size_ipv6`
955+
echo "The route table's size is $route_size(ipv4 $route_size_ipv4, ipv6 $route_size_ipv6)"
956+
957+
if [[ $route_size -gt $ROUTE_TAB_LIMIT_DIRECT_ITERATION ]]; then
958+
echo "Dump by using Redis SAVE."
959+
960+
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
961+
save_cmd "docker exec syncd saidump.sh" "saidump"
962+
else
963+
save_cmd "docker exec syncd$i saidump.sh" "saidump$i"
964+
fi
965+
else
966+
echo "Dump by using direct iteration of Redis DB."
967+
968+
if [[ ( "$NUM_ASICS" == 1 ) ]] ; then
969+
save_cmd "docker exec syncd saidump" "saidump"
970+
else
971+
save_cmd "docker exec syncd$i saidump" "saidump$i"
972+
fi
973+
fi
974+
done
884975
}
885976

886977
###############################################################################
@@ -1807,9 +1898,7 @@ main() {
18071898
save_cmd "ps -AwwL -o user,pid,lwp,ppid,nlwp,pcpu,pri,nice,vsize,rss,tty,stat,wchan:12,start,bsdtime,command" "ps.extended" &
18081899
wait
18091900

1810-
if [[ "$device_type" != "SpineRouter" ]]; then
1811-
save_saidump
1812-
fi
1901+
save_saidump_by_route_size
18131902

18141903
if [ "$asic" = "barefoot" ]; then
18151904
collect_barefoot

0 commit comments

Comments
 (0)