()
| 84 | ) |
| 85 | |
| 86 | func main() { |
| 87 | flag.Parse() |
| 88 | if *testName == "" { |
| 89 | logger.Fatal("-test_name not set") |
| 90 | } |
| 91 | req := &testpb.SimpleRequest{ |
| 92 | ResponseType: testpb.PayloadType_COMPRESSABLE, |
| 93 | ResponseSize: int32(*rspSize), |
| 94 | Payload: &testpb.Payload{ |
| 95 | Type: testpb.PayloadType_COMPRESSABLE, |
| 96 | Body: make([]byte, *rqSize), |
| 97 | }, |
| 98 | } |
| 99 | connectCtx, connectCancel := context.WithDeadline(context.Background(), time.Now().Add(5*time.Second)) |
| 100 | defer connectCancel() |
| 101 | ccs := buildConnections(connectCtx) |
| 102 | warmDeadline := time.Now().Add(time.Duration(*warmupDur) * time.Second) |
| 103 | endDeadline := warmDeadline.Add(time.Duration(*duration) * time.Second) |
| 104 | cf, err := os.Create("/tmp/" + *testName + ".cpu") |
| 105 | if err != nil { |
| 106 | logger.Fatalf("Error creating file: %v", err) |
| 107 | } |
| 108 | defer cf.Close() |
| 109 | pprof.StartCPUProfile(cf) |
| 110 | cpuBeg := syscall.GetCPUTime() |
| 111 | for _, cc := range ccs { |
| 112 | runWithConn(cc, req, warmDeadline, endDeadline) |
| 113 | } |
| 114 | wg.Wait() |
| 115 | cpu := time.Duration(syscall.GetCPUTime() - cpuBeg) |
| 116 | pprof.StopCPUProfile() |
| 117 | mf, err := os.Create("/tmp/" + *testName + ".mem") |
| 118 | if err != nil { |
| 119 | logger.Fatalf("Error creating file: %v", err) |
| 120 | } |
| 121 | defer mf.Close() |
| 122 | runtime.GC() // materialize all statistics |
| 123 | if err := pprof.WriteHeapProfile(mf); err != nil { |
| 124 | logger.Fatalf("Error writing memory profile: %v", err) |
| 125 | } |
| 126 | hist := stats.NewHistogram(hopts) |
| 127 | for _, h := range hists { |
| 128 | hist.Merge(h) |
| 129 | } |
| 130 | parseHist(hist) |
| 131 | fmt.Println("Client CPU utilization:", cpu) |
| 132 | fmt.Println("Client CPU profile:", cf.Name()) |
| 133 | fmt.Println("Client Mem Profile:", mf.Name()) |
| 134 | } |
| 135 | |
| 136 | func buildConnections(ctx context.Context) []*grpc.ClientConn { |
| 137 | ccs := make([]*grpc.ClientConn, *numConn) |
nothing calls this directly
no test coverage detected