Upgrade to Pro — share decks privately, control downloads, hide ads and more …

$ go tool traceを使ってみよう/ Let's use go tool trace

nametake
December 11, 2017

$ go tool traceを使ってみよう/ Let's use go tool trace

golang.tokyo #11( https://techplay.jp/event/641403 )での発表資料です。

nametake

December 11, 2017
Tweet

More Decks by nametake

Other Decks in Technology

Transcript

  1. package main import ( "log" "net/http" _ "net/http/pprof" "runtime" )

    func main() { runtime.SetBlockProfileRate(1) log.Println( http.ListenAndServe("0.0.0.0:6060", nil), ) }
  2. package main import ( "os" "runtime/trace" ) func main() {

    f, err := os.Create("trace.out") if err != nil { panic(err) } defer f.Close() err = trace.Start(f) if err != nil { panic(err) } defer trace.Stop() }
  3. f, err := os.Create("test.txt") if err != nil { panic(err)

    } defer f.Close() for i := 0; i < 100; i++ { fmt.Fprintf(f, "line number: %d\n", i) }
  4. f, err := os.Create("test.txt") if err != nil { panic(err)

    } defer f.Close() for i := 0; i < 100; i++ { fmt.Fprintf(f, "line number: %d\n", i) }
  5. f, err := os.Create("test.txt") if err != nil { panic(err)

    } defer f.Close() for i := 0; i < 100; i++ { fmt.Fprintf(f, "line number: %d\n", i) }
  6. f, err := os.Create("test.txt") if err != nil { panic(err)

    } defer f.Close() w := bufio.NewWriter(f) defer w.Flush() for i := 0; i < 100; i++ { fmt.Fprintf(w, "line number: %d\n", i) }
  7. GC

  8. GC

  9. n := 400000 list := []int{} for i := 0;

    i < n; i++ { list = append(list, i) }
  10. n := 400000 list := []int{} for i := 0;

    i < n; i++ { list = append(list, i) }
  11. n := 400000 list := make([]int, n) for i :=

    0; i < n; i++ { list[i] = i }