@@ -155,7 +155,7 @@ var (
155
155
verbose = flags .Bool ("v" , false , prettify (`
156
156
Enable verbose output.` ))
157
157
veryVerbose = flags .Bool ("vv" , false , prettify (`
158
- Enable very verbose output.` ))
158
+ Enable very verbose output (includes timing data) .` ))
159
159
serverName = flags .String ("servername" , "" , prettify (`
160
160
Override server name when validating TLS certificate. This flag is
161
161
ignored if -plaintext or -insecure is used.
@@ -276,6 +276,32 @@ func (cs compositeSource) AllExtensionsForType(typeName string) ([]*desc.FieldDe
276
276
return exts , nil
277
277
}
278
278
279
+ type timingData struct {
280
+ Title string
281
+ Start time.Time
282
+ Value time.Duration
283
+ Parent * timingData
284
+ Sub []* timingData
285
+ }
286
+
287
+ func (d * timingData ) Child (title string ) * timingData {
288
+ if d == nil {
289
+ return nil
290
+ }
291
+ child := & timingData {Title : title , Start : time .Now ()}
292
+ d .Sub = append (d .Sub , child )
293
+ return child
294
+ }
295
+
296
+ func (d * timingData ) Done () {
297
+ if d == nil {
298
+ return
299
+ }
300
+ if d .Value == 0 {
301
+ d .Value = time .Since (d .Start )
302
+ }
303
+ }
304
+
279
305
func main () {
280
306
flags .Usage = usage
281
307
flags .Parse (os .Args [1 :])
@@ -361,8 +387,16 @@ func main() {
361
387
if * verbose {
362
388
verbosityLevel = 1
363
389
}
390
+
391
+ var rootTiming * timingData
364
392
if * veryVerbose {
365
393
verbosityLevel = 2
394
+
395
+ rootTiming = & timingData {Title : "Timing Data" , Start : time .Now ()}
396
+ defer func () {
397
+ rootTiming .Done ()
398
+ dumpTiming (rootTiming , 0 )
399
+ }()
366
400
}
367
401
368
402
var symbol string
@@ -421,6 +455,8 @@ func main() {
421
455
}
422
456
423
457
dial := func () * grpc.ClientConn {
458
+ dialTiming := rootTiming .Child ("Dial" )
459
+ defer dialTiming .Done ()
424
460
dialTime := 10 * time .Second
425
461
if * connectTimeout > 0 {
426
462
dialTime = time .Duration (* connectTimeout * float64 (time .Second ))
@@ -453,6 +489,9 @@ func main() {
453
489
}
454
490
creds = alts .NewClientCreds (clientOptions )
455
491
} else if usetls {
492
+ tlsTiming := dialTiming .Child ("TLS Setup" )
493
+ defer tlsTiming .Done ()
494
+
456
495
tlsConf , err := grpcurl .ClientTLSConfig (* insecure , * cacert , * cert , * key )
457
496
if err != nil {
458
497
fail (err , "Failed to create TLS config" )
@@ -485,6 +524,7 @@ func main() {
485
524
if overrideName != "" {
486
525
opts = append (opts , grpc .WithAuthority (overrideName ))
487
526
}
527
+ tlsTiming .Done ()
488
528
} else {
489
529
panic ("Should have defaulted to use TLS." )
490
530
}
@@ -502,6 +542,8 @@ func main() {
502
542
if isUnixSocket != nil && isUnixSocket () {
503
543
network = "unix"
504
544
}
545
+ blockingDialTiming := dialTiming .Child ("BlockingDial" )
546
+ defer blockingDialTiming .Done ()
505
547
cc , err := grpcurl .BlockingDial (ctx , network , target , creds , opts ... )
506
548
if err != nil {
507
549
fail (err , "Failed to dial target host %q" , target )
@@ -749,7 +791,9 @@ func main() {
749
791
VerbosityLevel : verbosityLevel ,
750
792
}
751
793
794
+ invokeTiming := rootTiming .Child ("InvokeRPC" )
752
795
err = grpcurl .InvokeRPC (ctx , descSource , cc , symbol , append (addlHeaders , rpcHeaders ... ), h , rf .Next )
796
+ invokeTiming .Done ()
753
797
if err != nil {
754
798
if errStatus , ok := status .FromError (err ); ok && * formatError {
755
799
h .Status = errStatus
@@ -780,6 +824,17 @@ func main() {
780
824
}
781
825
}
782
826
827
+ func dumpTiming (td * timingData , lvl int ) {
828
+ ind := ""
829
+ for x := 0 ; x < lvl ; x ++ {
830
+ ind += " "
831
+ }
832
+ fmt .Printf ("%s%s: %s\n " , ind , td .Title , td .Value )
833
+ for _ , sd := range td .Sub {
834
+ dumpTiming (sd , lvl + 1 )
835
+ }
836
+ }
837
+
783
838
func usage () {
784
839
fmt .Fprintf (os .Stderr , `Usage:
785
840
%s [flags] [address] [list|describe] [symbol]
0 commit comments