()
| 53 | ) |
| 54 | |
| 55 | func main() { |
| 56 | flag.Parse() |
| 57 | if *testName == "" { |
| 58 | logger.Fatal("-test_name not set") |
| 59 | } |
| 60 | lis, err := net.Listen("tcp", ":"+*port) |
| 61 | if err != nil { |
| 62 | logger.Fatalf("Failed to listen: %v", err) |
| 63 | } |
| 64 | defer lis.Close() |
| 65 | |
| 66 | cf, err := os.Create("/tmp/" + *testName + ".cpu") |
| 67 | if err != nil { |
| 68 | logger.Fatalf("Failed to create file: %v", err) |
| 69 | } |
| 70 | defer cf.Close() |
| 71 | pprof.StartCPUProfile(cf) |
| 72 | cpuBeg := syscall.GetCPUTime() |
| 73 | // Launch server in a separate goroutine. |
| 74 | stop := benchmark.StartServer(benchmark.ServerInfo{Type: "protobuf", Listener: lis}, |
| 75 | grpc.WriteBufferSize(128*1024), |
| 76 | grpc.ReadBufferSize(128*1024), |
| 77 | ) |
| 78 | // Wait on OS terminate signal. |
| 79 | ch := make(chan os.Signal, 1) |
| 80 | signal.Notify(ch, os.Interrupt) |
| 81 | <-ch |
| 82 | cpu := time.Duration(syscall.GetCPUTime() - cpuBeg) |
| 83 | stop() |
| 84 | pprof.StopCPUProfile() |
| 85 | mf, err := os.Create("/tmp/" + *testName + ".mem") |
| 86 | if err != nil { |
| 87 | logger.Fatalf("Failed to create file: %v", err) |
| 88 | } |
| 89 | defer mf.Close() |
| 90 | runtime.GC() // materialize all statistics |
| 91 | if err := pprof.WriteHeapProfile(mf); err != nil { |
| 92 | logger.Fatalf("Failed to write memory profile: %v", err) |
| 93 | } |
| 94 | fmt.Println("Server CPU utilization:", cpu) |
| 95 | fmt.Println("Server CPU profile:", cf.Name()) |
| 96 | fmt.Println("Server Mem Profile:", mf.Name()) |
| 97 | } |
nothing calls this directly
no test coverage detected