github.com/distbuild/reclient@v0.0.0-20240401075343-3de72e395564/cmd/reproxytool/main.go (about) 1 // Copyright 2023 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 // 15 // Binary reproxytool parses reclient log files for common debugging purpose. 16 // 17 // To see help information: 18 // 19 // bazelisk run //cmd/reproxytool:reproxytool -- --help 20 // 21 // Example Invocation: 22 // 23 // Convert reproxy.INFO log to usage CSV: 24 // bazelisk run //cmd/reproxytool:reproxytool -- \ 25 // --operation=usage_to_csv --log_path=/tmp/reproxy.INFO \ 26 // --alsologtostderr 27 package main 28 29 import ( 30 "flag" 31 "fmt" 32 "os" 33 "path" 34 35 csv "github.com/bazelbuild/reclient/cmd/reproxytool/usage2csv" 36 log "github.com/golang/glog" 37 ) 38 39 // OpType denotes the type of operation to perform. 40 type OpType string 41 42 const ( 43 usage2CSV OpType = "usage_to_csv" 44 ) 45 46 var supportedOps = []OpType{ 47 usage2CSV, 48 } 49 50 var ( 51 operation = flag.String("operation", "", fmt.Sprintf("Specifies the operation to perform. Supported values: %v", supportedOps)) 52 logPath = flag.String("log_path", "", "Path to log file. E.g., /tmp/reproxy.INFO") 53 ) 54 55 func main() { 56 flag.Usage = func() { 57 fmt.Fprintf(flag.CommandLine.Output(), "Usage: %v [-flags] -- --operation <op> arguments ...\n", path.Base(os.Args[0])) 58 flag.PrintDefaults() 59 } 60 flag.Parse() 61 if *operation == "" { 62 log.Exitf("--operation must be specified.") 63 } 64 switch OpType(*operation) { 65 case usage2CSV: 66 if err := csv.Usage2CSV(getLogPathFlag()); err != nil { 67 log.Exitf("Error parsing usage data from reproxy.INFO, %v,to CSV file %v", logPath, err) 68 } 69 default: 70 log.Exitf("Unsupported operation %v. Supported operations:\n%v", *operation, supportedOps) 71 } 72 } 73 74 func getLogPathFlag() string { 75 if *logPath == "" { 76 log.Exitf("--log_path must be specified.") 77 } 78 return *logPath 79 }