Created
November 21, 2019 17:24
-
-
Save LarryRuane/d3424159333f64bc63237088362b7edd to your computer and use it in GitHub Desktop.
patch to https://github.com/fullstorydev/grpcurl to enable repeating the given RPCs for performance measurements
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/cmd/grpcurl/grpcurl.go b/cmd/grpcurl/grpcurl.go | |
index aaa3bbf..92489ef 100644 | |
--- a/cmd/grpcurl/grpcurl.go | |
+++ b/cmd/grpcurl/grpcurl.go | |
@@ -115,6 +115,9 @@ var ( | |
Enable verbose output.`)) | |
serverName = flags.String("servername", "", prettify(` | |
Override server name when validating TLS certificate.`)) | |
+ repeatCount = flags.Int("repeat", 1, prettify(` | |
+ Submit the rpc the given number of times (default 1), for performance | |
+ measurements.`)) | |
) | |
func init() { | |
@@ -213,6 +216,9 @@ func main() { | |
if *emitDefaults && *format != "json" { | |
warn("The -emit-defaults is only used when using json format.") | |
} | |
+ if *repeatCount <= 0 { | |
+ fail(nil, "The -repeat argument must be greater than zero.") | |
+ } | |
args := flags.Args() | |
@@ -547,6 +553,19 @@ func main() { | |
if err != nil { | |
fail(err, "Error invoking method %q", symbol) | |
} | |
+ | |
+ for i := 1; i < *repeatCount; i++ { | |
+ in = strings.NewReader(*data) | |
+ rf, formatter, err = grpcurl.RequestParserAndFormatterFor(grpcurl.Format(*format), descSource, *emitDefaults, includeSeparators, in) | |
+ if err != nil { | |
+ fail(err, "Failed to construct request parser and formatter for %q", *format) | |
+ } | |
+ err = grpcurl.InvokeRPC(ctx, descSource, cc, symbol, append(addlHeaders, rpcHeaders...), h, rf.Next) | |
+ if err != nil { | |
+ fail(err, "Error invoking method %q", symbol) | |
+ } | |
+ } | |
+ | |
reqSuffix := "" | |
respSuffix := "" | |
reqCount := rf.NumRequests() | |
@@ -613,7 +632,7 @@ func prettify(docString string) string { | |
j++ | |
} | |
- return strings.Join(parts[:j], "\n"+indent()) | |
+ return strings.Join(parts[:j], "\n") | |
} | |
func warn(msg string, args ...interface{}) { |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment