1 // Copyright (c) 2019 Cisco and/or its affiliates.
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at:
7 // http://www.apache.org/licenses/LICENSE-2.0
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
23 "git.fd.io/govpp.git/adapter/statsclient"
24 "git.fd.io/govpp.git/api"
25 "git.fd.io/govpp.git/core"
29 statsSocket = flag.String("socket", statsclient.DefaultSocketName, "Path to VPP stats socket")
32 func TestStatClientAll(t *testing.T) {
33 client := statsclient.NewStatsClient(*statsSocket)
35 c, err := core.ConnectStats(client)
37 t.Fatal("Connecting failed:", err)
41 sysStats := new(api.SystemStats)
42 nodeStats := new(api.NodeStats)
43 errorStats := new(api.ErrorStats)
44 ifaceStats := new(api.InterfaceStats)
46 if err = c.GetNodeStats(nodeStats); err != nil {
47 t.Fatal("updating node stats failed:", err)
49 if err = c.GetSystemStats(sysStats); err != nil {
50 t.Fatal("updating system stats failed:", err)
52 if err = c.GetErrorStats(errorStats); err != nil {
53 t.Fatal("updating error stats failed:", err)
55 if err = c.GetInterfaceStats(ifaceStats); err != nil {
56 t.Fatal("updating interface stats failed:", err)
60 func TestStatClientNodeStats(t *testing.T) {
61 client := statsclient.NewStatsClient(*statsSocket)
63 c, err := core.ConnectStats(client)
65 t.Fatal("Connecting failed:", err)
69 stats := new(api.NodeStats)
71 if err := c.GetNodeStats(stats); err != nil {
72 t.Fatal("getting node stats failed:", err)
76 func TestStatClientNodeStatsAgain(t *testing.T) {
77 client := statsclient.NewStatsClient(*statsSocket)
78 c, err := core.ConnectStats(client)
80 t.Fatal("Connecting failed:", err)
84 stats := new(api.NodeStats)
86 if err := c.GetNodeStats(stats); err != nil {
87 t.Fatal("getting node stats failed:", err)
89 if err := c.GetNodeStats(stats); err != nil {
90 t.Fatal("getting node stats failed:", err)
94 func BenchmarkStatClientNodeStatsGet1(b *testing.B) { benchStatClientNodeStatsGet(b, 1) }
95 func BenchmarkStatClientNodeStatsGet10(b *testing.B) { benchStatClientNodeStatsGet(b, 10) }
97 func benchStatClientNodeStatsGet(b *testing.B, repeatN int) {
98 client := statsclient.NewStatsClient(*statsSocket)
99 c, err := core.ConnectStats(client)
101 b.Fatal("Connecting failed:", err)
106 nodeStats := new(api.NodeStats)
107 for i := 0; i < b.N; i++ {
108 for r := 0; r < repeatN; r++ {
109 if err = c.GetNodeStats(nodeStats); err != nil {
110 b.Fatal("getting node stats failed:", err)
117 func BenchmarkStatClientNodeStatsUpdate1(b *testing.B) { benchStatClientNodeStatsLoad(b, 1) }
118 func BenchmarkStatClientNodeStatsUpdate10(b *testing.B) { benchStatClientNodeStatsLoad(b, 10) }
120 func benchStatClientNodeStatsLoad(b *testing.B, repeatN int) {
121 client := statsclient.NewStatsClient(*statsSocket)
122 c, err := core.ConnectStats(client)
124 b.Fatal("Connecting failed:", err)
127 nodeStats := new(api.NodeStats)
130 for i := 0; i < b.N; i++ {
131 for r := 0; r < repeatN; r++ {
132 if err = c.GetNodeStats(nodeStats); err != nil {
133 b.Fatal("getting node stats failed:", err)
140 func BenchmarkStatClientStatsUpdate1(b *testing.B) { benchStatClientStatsUpdate(b, 1) }
141 func BenchmarkStatClientStatsUpdate10(b *testing.B) { benchStatClientStatsUpdate(b, 10) }
142 func BenchmarkStatClientStatsUpdate100(b *testing.B) { benchStatClientStatsUpdate(b, 100) }
144 func benchStatClientStatsUpdate(b *testing.B, repeatN int) {
145 client := statsclient.NewStatsClient(*statsSocket)
146 c, err := core.ConnectStats(client)
148 b.Fatal("Connecting failed:", err)
152 sysStats := new(api.SystemStats)
153 nodeStats := new(api.NodeStats)
154 errorStats := new(api.ErrorStats)
155 ifaceStats := new(api.InterfaceStats)
158 for i := 0; i < b.N; i++ {
159 for r := 0; r < repeatN; r++ {
160 if err = c.GetNodeStats(nodeStats); err != nil {
161 b.Fatal("updating node stats failed:", err)
163 if err = c.GetSystemStats(sysStats); err != nil {
164 b.Fatal("updating system stats failed:", err)
166 if err = c.GetErrorStats(errorStats); err != nil {
167 b.Fatal("updating error stats failed:", err)
169 if err = c.GetInterfaceStats(ifaceStats); err != nil {
170 b.Fatal("updating error stats failed:", err)