-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget_roce_throughput.sh
executable file
·126 lines (103 loc) · 3.15 KB
/
get_roce_throughput.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
#!/bin/bash
#
# Show live throughput for RoCE interfaces based on RDMA unicast rx/tx byte counters from ethtool.
#
# Author: Sven Breuner, Yaniv Romem
# Maintainer: Sven Breuner <sven[at]excelero.com>
# Print usage info and exit
usage()
{
echo "Show live throughput for RoCE interfaces based on RDMA unicast rx/tx byte"
echo "counters from ethtool."
echo
echo "Usage:"
echo " $0 [Options] [Interface [Interface [...] ]"
echo
echo "Options:"
echo " -m Use multiple lines per interface, one for rx and one for tx."
echo " -s Single run. Default is an infinite loop."
echo " -t NUM Time interval in seconds. Defaults to 1 sec."
echo " interface Interface to query counters for. Defaults to automatic query"
echo " of available interfaces based on ibdev2netdev."
echo
echo "Example:"
echo " $ $0 ens3f0 ens3f1"
exit 1
}
# Parse command line arguments and set defaults
parse_args()
{
local OPTIND # local to prevent effects from other subscripts
# default settings
multiline=0 # 1 for multiple lines for rx and tx per interface
quit=0 # 1 for single run instead of infinite loop
t=1 # time interval in seconds
while getopts ":hmst:" opt; do
case "${opt}" in
m)
# Single run instead of infinite loop
multiline=1
;;
s)
# Single run instead of infinite loop
quit=1
;;
t)
# Time interval in seconds
t=${OPTARG}
;;
*)
# Other option arguments are invalid
usage
;;
esac
done
shift $((OPTIND-1))
# Non-option arguments are assumed to be interface names
NICs=($*)
# If no interfaces were given by user then auto detect from ibdev2netdev
if [ ${#NICs[@]} -eq 0 ]; then
NICs=(`ibdev2netdev | grep "(Up)" | cut "-d " -f 5`)
fi
}
# Print statistics for given time interval. (Includes sleep.)
print_stats()
{
# read absolute rx/tx counters of given interfaces (reuse from last round if possible)
if [ ${#STATS_B[@]} -eq 0 ]; then
for (( i=0; i < ${#NICs[@]}; i++ )) do
STATS_A[$i]=`ethtool -S ${NICs[$i]} | grep rdma | grep uni | grep bytes | cut -d: -f2`
# STAT_A[$i] contains 2 newline-separated values now: the absolute rx bytes and tx bytes
done
else
# reuse counters from last round
STATS_A=("${STATS_B[@]}")
fi
# wait for given time interval (seconds)
sleep $t;
# read absolute rx/tx counters again and print difference
for (( i=0; i < ${#NICs[@]}; i++ )) do
STATS_B[$i]=`ethtool -S ${NICs[$i]} | grep rdma | grep uni | grep bytes | cut -d: -f2`
A=(${STATS_A[$i]})
B=(${STATS_B[$i]})
RX=$(( (${B[0]}-${A[0]}) / (1024 * 1024 * $t) ))
TX=$(( (${B[1]}-${A[1]}) / (1024 * 1024 * $t) ))
if [ $multiline -gt 0 ]; then
echo "${NICs[$i]} RX MiB/s: $RX"
echo "${NICs[$i]} TX MiB/s: $TX"
else
printf '%-8s | MiB/s | RX %6s | TX %6s\n' ${NICs[$i]} $RX $TX
fi
done
}
parse_args "$@"
SECONDS=0 # automatically incremented by bash
while true; do
stats_out=$(print_stats)
if [ $quit -gt 0 ]; then
echo "$stats_out"
exit 0
fi
echo "--- ${SECONDS}s ---"
echo "$stats_out"
done