-
Notifications
You must be signed in to change notification settings - Fork 0
/
run_flamegraph
executable file
·97 lines (93 loc) · 3.34 KB
/
run_flamegraph
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
#!/bin/bash -x
function run_server()
{
kubectl run pod1 --image=networkstatic/iperf3 --overrides="{\"spec\": { \"nodeSelector\": {\"kubernetes.io/hostname\": \"$1\"}}}" --command -- iperf3 -s
}
function run_client()
{
ipq=$(kubectl get pods pod1 -o json|jq ".status.podIP")
ipq1=${ipq#\"}
ip=${ipq1%\"}
# kubectl run pod2 --image=networkstatic/iperf3 --overrides="{\"spec\": { \"nodeSelector\": {\"kubernetes.io/hostname\": \"$1\"}}}" --command -- iperf3 -c $ip -t 70
cat >client-job.yaml <<EOF
apiVersion: batch/v1
kind: Job
metadata:
name: iperf3-client
spec:
template:
spec:
containers:
- name: iperf3-client
image: networkstatic/iperf3
command: ["iperf3", "-c", "$ip", "-t", "70"]
nodeName: $1
restartPolicy: Never
backoffLimit: 4
EOF
kubectl apply -f client-job.yaml
client_pod=$(kubectl get pods --selector=job-name=iperf3-client --output=jsonpath='{.items[*].metadata.name}')
}
function hostip_of()
{
hostipq=$(kubectl get pods $1 -o json|jq ".status.hostIP")
hostipq1=${hostipq#\"}
hostip=${hostipq1%\"}
echo $hostip
}
function uid_of()
{
uidq=$(kubectl get pods $1 -o json|jq ".metadata.uid")
uidq1=${uidq#\"}
uid=${uidq1%\"}
echo $uid
}
function data_of()
{
tail -n 1 $1 |
awk '{if ( $8 == "Mbits/sec") print $7*1e6*60; else if ( $8 == "Gbits/sec") print $7*1e9*60;}'
}
server_hostname=$1
client_hostname=$2
output_dir=$3
mkdir -p ${output_dir}
#sudo sh -c "echo 0 > /proc/sys/kernel/kptr_restrict"
#sudo sh -c "echo -1 > /proc/sys/kernel/perf_event_paranoid"
run_server ${server_hostname}
server_hostip=$(hostip_of pod1)
server_uid=$(uid_of pod1)
#sleep 10
kubectl wait --for=condition=Ready pod/pod1
run_client ${client_hostname}
client_hostip=$(hostip_of ${client_pod})
client_uid=$(uid_of ${client_pod})
#sleep 5
kubectl wait --for=condition=Ready pod/${client_pod}
server_start_cpu=$(ssh -n ${server_hostip} ~/workspace/ebpf-performance/cpuacct_of ${server_uid})
client_start_cpu=$(ssh -n ${client_hostip} ~/workspace/ebpf-performance/cpuacct_of ${client_uid})
ssh -n ${server_hostip} ~/workspace/ebpf-performance/perf_of ${server_uid} &
ssh -n ${client_hostip} ~/workspace/ebpf-performance/perf_of ${client_uid}
wait
server_end_cpu=$(ssh -n ${server_hostip} ~/workspace/ebpf-performance/cpuacct_of ${server_uid})
client_end_cpu=$(ssh -n ${client_hostip} ~/workspace/ebpf-performance/cpuacct_of ${client_uid})
sleep 20
kubectl logs pod1 >${output_dir}/server.log
kubectl logs ${client_pod} >${output_dir}/client.log
ssh -n ${server_hostip} ~/workspace/ebpf-performance/generate_flamegraph >${output_dir}/server-flamegraph.svg
ssh -n ${client_hostip} ~/workspace/ebpf-performance/generate_flamegraph >${output_dir}/client-flamegraph.svg
typeset -i server_cpu=${server_end_cpu}-${server_start_cpu}
typeset -i client_cpu=${client_end_cpu}-${client_start_cpu}
echo "server cpu=${server_cpu}" >${output_dir}/server.cpu
echo "client cpu=${client_cpu}" >${output_dir}/client.cpu
total_data=$(data_of ${output_dir}/server.log)
echo "${server_cpu} ${total_data}"|awk '{print $2/$1}' >${output_dir}/server_per_tick
echo "${client_cpu} ${total_data}"|awk '{print $2/$1}' >${output_dir}/client_per_tick
kubectl delete pod pod1
kubectl delete job iperf3-client
ssh -n ${server_hostip} rm -f perf.data
ssh -n ${client_hostip} rm -f perf.data
cd ${output_dir} && (
git add .
git commit -m Flamegraph
git push origin main
)