"flag"
"fmt"
"log"
+ "os"
"time"
"github.com/pkg/profile"
"github.com/sirupsen/logrus"
- "git.fd.io/govpp.git"
+ "git.fd.io/govpp.git/adapter/socketclient"
+ "git.fd.io/govpp.git/adapter/statsclient"
"git.fd.io/govpp.git/api"
"git.fd.io/govpp.git/core"
- "git.fd.io/govpp.git/examples/bin_api/vpe"
+ "git.fd.io/govpp.git/examples/binapi/vpe"
)
const (
func main() {
// parse optional flags
- var sync, prof bool
+ var sync bool
var cnt int
+ var sock, prof string
flag.BoolVar(&sync, "sync", false, "run synchronous perf test")
+ flag.StringVar(&sock, "api-socket", socketclient.DefaultSocketName, "Path to VPP API socket")
+ flag.String("stats-socket", statsclient.DefaultSocketName, "Path to VPP stats socket")
flag.IntVar(&cnt, "count", 0, "count of requests to be sent to VPP")
- flag.BoolVar(&prof, "prof", false, "generate profile data")
+ flag.StringVar(&prof, "prof", "", "enable profiling mode [mem, cpu]")
flag.Parse()
if cnt == 0 {
}
}
- if prof {
- defer profile.Start().Stop()
+ switch prof {
+ case "mem":
+ defer profile.Start(profile.MemProfile, profile.MemProfileRate(1)).Stop()
+ case "cpu":
+ defer profile.Start(profile.CPUProfile).Stop()
+ case "":
+ default:
+ fmt.Printf("invalid profiling mode: %q\n", prof)
+ flag.Usage()
+ os.Exit(1)
}
+ a := socketclient.NewVppClient(sock)
+
// connect to VPP
- conn, err := govpp.Connect("")
+ conn, err := core.Connect(a)
if err != nil {
log.Fatalln("Error:", err)
}
}
defer ch.Close()
+ ch.SetReplyTimeout(time.Second * 2)
+
// log only errors
core.SetLogger(&logrus.Logger{Level: logrus.ErrorLevel})
elapsed := time.Since(start)
fmt.Println("Test took:", elapsed)
fmt.Printf("Requests per second: %.0f\n", float64(cnt)/elapsed.Seconds())
+
+ time.Sleep(time.Second)
}
func syncTest(ch api.Channel, cnt int) {