Optimize socketclient adapter and add various code improvements
[govpp.git] / examples / perf-bench / perf-bench.go
index b246e6c..81d183c 100644 (file)
@@ -20,14 +20,14 @@ import (
        "flag"
        "fmt"
        "log"
+       "os"
        "time"
 
        "github.com/pkg/profile"
        "github.com/sirupsen/logrus"
 
-       "git.fd.io/govpp.git/adapter"
        "git.fd.io/govpp.git/adapter/socketclient"
-       "git.fd.io/govpp.git/adapter/vppapiclient"
+       "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/binapi/vpe"
@@ -40,12 +40,14 @@ const (
 
 func main() {
        // parse optional flags
-       var sync, prof, sock bool
+       var sync bool
        var cnt int
+       var sock, prof string
        flag.BoolVar(&sync, "sync", false, "run synchronous perf test")
-       flag.BoolVar(&sock, "sock", false, "use socket client for VPP API")
+       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 {
@@ -57,16 +59,19 @@ func main() {
                }
        }
 
-       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)
        }
 
-       var a adapter.VppAPI
-       if sock {
-               a = socketclient.NewVppClient("/run/vpp-api.sock")
-       } else {
-               a = vppapiclient.NewVppClient("")
-       }
+       a := socketclient.NewVppClient(sock)
 
        // connect to VPP
        conn, err := core.Connect(a)