MCPcopy
hub / github.com/grpc/grpc-go / main

Function main

benchmark/client/main.go:86–134  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

84)
85
86func 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
136func buildConnections(ctx context.Context) []*grpc.ClientConn {
137 ccs := make([]*grpc.ClientConn, *numConn)

Callers

nothing calls this directly

Calls 15

MergeMethod · 0.95
GetCPUTimeFunction · 0.92
NewHistogramFunction · 0.92
buildConnectionsFunction · 0.85
runWithConnFunction · 0.85
parseHistFunction · 0.85
NowMethod · 0.80
WaitMethod · 0.80
PrintlnMethod · 0.80
ParseMethod · 0.65
FatalMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected