rights reserved. 20 演習3: プロファイルを取得してみよう exercise/cut.go は GNU Coreutils の cut(1) のGoポート(不完全)です。 これをビルド、実⾏し、プロファイルが⽣成されたか確認しよう cd exercise go build ./exercise sample10k.csv ls # cpu.prof(⾃分で名前をつけた場合はそのファイル)があれば成功
rights reserved. 44 CIでベンチマークとプロファイルの両⽅を取得 $ go test -bench=. -cpuprofile=cpu.prof goos: linux goarch: amd64 pkg: github.com/ymotongpoo/20250927-gocon-workshop/exercise cpu: Intel(R) Core(TM) i5-7260U CPU @ 2.20GHz BenchmarkCut-4 650418 1805 ns/op ok github.com/ymotongpoo/20250927-gocon-workshop/exercise 1.711s ヒープを取得したい場合には -memprofile オプションを付けます go test -bench=. -memprofile=mem.prof
rights reserved. 45 演習8: プロファイルをベンチマークで取得しよう プロファイルの計装を削除し、ベンチマークを取得したい部分を関数として切 り出して、 go test -bench を利⽤してプロファイルを取得してください 取得したプロファイルが先ほどと同様に go tool pprof で可視化できること を確認してください