...
1
18
19 package main
20
21 import (
22 "flag"
23 "fmt"
24 )
25
26 var flagAddress = flag.String("address", "", "address of a remote gRPC server with profiling turned on to retrieve stats from")
27 var flagTimeout = flag.Int("timeout", 0, "network operations timeout in seconds to remote target (0 indicates unlimited)")
28
29 var flagRetrieveSnapshot = flag.Bool("retrieve-snapshot", false, "connect to remote target and retrieve a profiling snapshot locally for processing")
30 var flagSnapshot = flag.String("snapshot", "", "snapshot file to write to when retrieving profiling data or snapshot file to read from when processing profiling data")
31
32 var flagEnableProfiling = flag.Bool("enable-profiling", false, "enable profiling in remote target")
33 var flagDisableProfiling = flag.Bool("disable-profiling", false, "disable profiling in remote target")
34
35 var flagStreamStatsCatapultJSON = flag.String("stream-stats-catapult-json", "", "path to a file to write to after transforming a snapshot into catapult's JSON format")
36 var flagStreamStatsFilter = flag.String("stream-stats-filter", "server,client", "comma-separated list of stat tags to filter for")
37
38 func exactlyOneOf(opts ...bool) bool {
39 first := true
40 for _, o := range opts {
41 if !o {
42 continue
43 }
44
45 if first {
46 first = false
47 } else {
48 return false
49 }
50 }
51
52 return !first
53 }
54
55 func parseArgs() error {
56 flag.Parse()
57
58 if *flagAddress != "" {
59 if !exactlyOneOf(*flagEnableProfiling, *flagDisableProfiling, *flagRetrieveSnapshot) {
60 return fmt.Errorf("when -address is specified, you must include exactly only one of -enable-profiling, -disable-profiling, and -retrieve-snapshot")
61 }
62
63 if *flagStreamStatsCatapultJSON != "" {
64 return fmt.Errorf("when -address is specified, you must not include -stream-stats-catapult-json")
65 }
66 } else {
67 if *flagEnableProfiling || *flagDisableProfiling || *flagRetrieveSnapshot {
68 return fmt.Errorf("when -address isn't specified, you must not include any of -enable-profiling, -disable-profiling, and -retrieve-snapshot")
69 }
70
71 if *flagStreamStatsCatapultJSON == "" {
72 return fmt.Errorf("when -address isn't specified, you must include -stream-stats-catapult-json")
73 }
74 }
75
76 return nil
77 }
78
View as plain text