istio.io/istio@v0.0.0-20240520182934-d79c90f27776/tools/go-compile-verbose (about) 1 #!/usr/bin/env bash 2 3 # Copyright Istio Authors 4 # 5 # Licensed under the Apache License, Version 2.0 (the "License"); 6 # you may not use this file except in compliance with the License. 7 # You may obtain a copy of the License at 8 # 9 # http://www.apache.org/licenses/LICENSE-2.0 10 # 11 # Unless required by applicable law or agreed to in writing, software 12 # distributed under the License is distributed on an "AS IS" BASIS, 13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 # See the License for the specific language governing permissions and 15 # limitations under the License. 16 17 # This script runs can be used to emit (readable) compile tracing info when building go packages 18 19 # Before usage, `go clean -cache` is suggested, otherwise you will measure cached results. 20 # Cleanup: rm -f /tmp/golog; This will always append to the file so you should cleanup between each call. 21 # Usage (compile all tests only): `go test -exec=true -toolexec=$PWD/tools/go-compile-verbose ./...` 22 # Usage (compile binary): `go build -toolexec=$PWD/tools/go-compile-verbose ./...` 23 # Results will be in /tmp/golog, as stdout gets cached and pollutes all later runs. 24 START="$(date -u +%s.%N)" 25 26 # Output a message, with a timestamp matching istio log format 27 function log() { 28 delta=$(date +%s.%N --date="$START seconds ago") 29 echo -e "$(date -u '+%Y-%m-%dT%H:%M:%S.%NZ')\t${delta}\t$*" >&2 >> /tmp/golog 30 } 31 32 GROOT="$(go env GOROOT)" 33 GPATH="$(go env GOPATH)" 34 GMODCACHE="$(go env GOMODCACHE)" 35 ROOT="$PWD" 36 37 $@ 38 ls="$(basename $1)" 39 shift 40 case "$ls" in 41 link) 42 log "${ls}\t$(basename ${2})" ;; 43 compile) 44 f=${@: -1} 45 if [[ "$f" =~ "$GMODCACHE" ]]; then 46 base="${f/"$GMODCACHE"\//}" 47 mod="$(<<< "$base" cut -d@ -f1)" 48 rest="$(<<< "$base" cut -d@ -f2 | cut -d/ -f2-)" 49 log "${ls}\t${mod}\t${rest}" 50 elif [[ "$f" =~ "$GROOT" ]]; then 51 base="${f/"$GROOT"\//}" 52 log "${ls}\tstd\t${base}" 53 elif [[ "$f" =~ "$ROOT" ]]; then 54 base="${f/"$ROOT"\//}" 55 log "${ls}\tlocal\t${base}" 56 else 57 log "${ls}\tunknown\t${f}" 58 fi 59 ;; 60 vet) 61 # vet does not readily expose what is being vetted 62 log "${ls}" ;; 63 asm) 64 f="${@:$#}" 65 if [[ "$f" =~ "$GMODCACHE" ]]; then 66 base="${f/"$GMODCACHE"\//}" 67 mod="$(<<< "$base" cut -d@ -f1)" 68 rest="$(<<< "$base" cut -d@ -f2 | cut -d/ -f2-)" 69 log "${ls}\t${mod}\t${rest}" 70 elif [[ "$f" =~ "$GROOT" ]]; then 71 base="${f/"$GROOT"\//}" 72 log "${ls}\tstd\t${base}" 73 elif [[ "$f" =~ "$ROOT" ]]; then 74 base="${f/"$ROOT"\//}" 75 log "${ls}\tlocal\t${base}" 76 else 77 log "${ls}\tunknown\t${f}" 78 fi 79 ;; 80 cgo) 81 log "${ls}" ;; 82 *) 83 log "${ls}\t${@:-1}" ;; 84 esac