如何跟踪程序执行情况?

如何跟踪程序执行情况?

目前go程序1.3、1.4和1.5的编译性能差异很大,后者4x比前者慢一些。如何跟踪go编译器执行情况?

像这样的东西:

红宝石教授

注意:valgrind+calgrind不起作用(教程

 valgrind --tool=callgrind /usr/bin/go build
==26982== Callgrind, a call-graph generating cache profiler
==26982== Copyright (C) 2002-2015, and GNU GPL'd, by Josef Weidendorfer et al.
==26982== Using Valgrind-3.11.0 and LibVEX; rerun with -h for copyright info
==26982== Command: /usr/bin/go build
==26982== 
==26982== For interactive control, run 'callgrind_control -h'.
fatal error: rt_sigaction failure

runtime stack:
runtime.throw(0x9a2bf0, 0x14)
        /usr/lib/go/src/runtime/panic.go:527 +0x90
runtime.setsig(0xc800000040, 0x4e40d0, 0x1)
        /usr/lib/go/src/runtime/os1_linux.go:297 +0x197
runtime.initsig()
        /usr/lib/go/src/runtime/signal1_unix.go:67 +0x13d
runtime.mstart1()
        /usr/lib/go/src/runtime/proc1.go:717 +0xc9
runtime.mstart()
        /usr/lib/go/src/runtime/proc1.go:691 +0x72

goroutine 1 [runnable]:
runtime.main()
        /usr/lib/go/src/runtime/proc.go:28
runtime.goexit()
        /usr/lib/go/src/runtime/asm_amd64.s:1696 +0x1

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
        /usr/lib/go/src/runtime/asm_amd64.s:1696 +0x1
==26982== 
==26982== Events    : Ir
==26982== Collected : 851285
==26982== 
==26982== I   refs:      851,285

答案1

没关系,找到了回答,但不够有用:

去1.5

perf record /usr/bin/go build
[ perf record: Woken up 9 times to write data ]
[ perf record: Captured and wrote 2.890 MB perf.data (73779 samples) ]

perf report --sort comm,dso
Samples: 73K of event 'cycles', Event count (approx.): 54540942397
Overhead  Command  Shared Object
  82.19%  compile  compile
  10.62%  link     link
   5.07%  compile  [kernel.vmlinux]
   0.76%  link     [kernel.vmlinux]
   0.55%  go       go
   0.52%  go       [kernel.vmlinux]
   0.07%  compile  [ath9k]
   0.05%  compile  [mac80211]
   0.03%  go       [ext4]
   0.03%  compile  [i8042]
   0.03%  compile  [vdso]
   0.01%  go       [vdso]
   0.01%  compile  [libahci]
   0.01%  compile  [ath9k_hw]
   0.01%  link     [ext4]
   0.01%  go       [scsi_mod]
   0.01%  link     [mac80211]
   0.01%  go       [jbd2]
   0.01%  go       [libata]
   0.00%  compile  [ext4]
   0.00%  link     [libahci]
   0.00%  compile  [psmouse]
   0.00%  compile  [cfg80211]
   0.00%  compile  [libata]
   0.00%  go       [mac80211]
   0.00%  link     [i8042]
   0.00%  link     [scsi_mod]
   0.00%  compile  [scsi_mod]
   0.00%  link     [vdso]
   0.00%  go       [ath9k]
   0.00%  go       [cfg80211]

去1.4

perf record /usr/bin/go build
[ perf record: Woken up 2 times to write data ]
[ perf record: Captured and wrote 0.900 MB perf.data (22177 samples) ]

perf report --sort comm,dso
Samples: 22K of event 'cycles', Event count (approx.): 17031664028
Overhead  Command  Shared Object
  66.28%  6g       6g
  10.55%  6g       [kernel.vmlinux]
   9.88%  6l       6l
   7.55%  6g       libc-2.22.so
   2.39%  6l       libc-2.22.so
   1.35%  go       go
   1.09%  6l       [kernel.vmlinux]
   0.64%  go       [kernel.vmlinux]
   0.07%  6g       [ath9k]
   0.06%  6g       ld-2.22.so
   0.05%  6g       [mac80211]
   0.03%  6g       [ext4]
   0.02%  go       [ext4]
   0.01%  go       [jbd2]
   0.01%  6g       [ath9k_common]
   0.00%  go       [mac80211]
   0.00%  6g       [ath9k_hw]
   0.00%  6l       ld-2.22.so
   0.00%  6g       [scsi_mod]
   0.00%  go       [vdso]

去1.5

perf report
Samples: 72K of event 'cycles', Event count (approx.): 55631112443
Overhead  Command  Shared Object     Symbol
   6.59%  compile  compile           [.] 0x000000000001bd6b
   1.49%  compile  compile           [.] 0x000000000001c2a4
   1.00%  compile  compile           [.] 0x000000000001bcf1
   0.99%  compile  compile           [.] 0x0000000000056bac
   0.91%  compile  compile           [.] 0x000000000001bcdd
   0.80%  compile  compile           [.] 0x0000000000010471
   0.71%  link     link              [.] 0x000000000001c51b
   0.65%  compile  [kernel.vmlinux]  [k] ioread32
   0.54%  compile  compile           [.] 0x000000000001bcad
   0.49%  compile  [kernel.vmlinux]  [k] page_fault
   0.47%  compile  compile           [.] 0x000000000001bc65
   0.45%  compile  [kernel.vmlinux]  [k] clear_page_c_e
   0.43%  compile  compile           [.] 0x000000000000f157
   0.42%  compile  compile           [.] 0x000000000001bcce
   0.41%  compile  compile           [.] 0x000000000001bc80
   0.40%  compile  compile           [.] 0x0000000000010462
   0.39%  compile  compile           [.] 0x000000000001c34c
   0.38%  compile  compile           [.] 0x000000000001bcd9
   0.35%  compile  compile           [.] 0x000000000001bcc2
   0.33%  compile  compile           [.] 0x000000000001bd5d
   0.31%  compile  compile           [.] 0x000000000001bcc7
   0.31%  compile  compile           [.] 0x0000000000056a74
   0.30%  compile  compile           [.] 0x000000000001bcb7
   0.29%  compile  compile           [.] 0x000000000001bc89
   0.29%  link     link              [.] 0x000000000001ca54
   0.28%  compile  compile           [.] 0x000000000001047e
   0.28%  compile  compile           [.] 0x000000000001bcfe
   0.27%  compile  compile           [.] 0x000000000001b834
   0.27%  link     [kernel.vmlinux]  [k] ioread32
   0.26%  compile  compile           [.] 0x000000000001bcb2
   0.26%  compile  compile           [.] 0x000000000001bc94
   0.25%  compile  compile           [.] 0x0000000000056b3b
   0.25%  compile  compile           [.] 0x000000000001bd4f
   0.23%  compile  compile           [.] 0x000000000001bd58
   0.23%  compile  compile           [.] 0x000000000001bc9c
   0.21%  compile  compile           [.] 0x000000000001bd54
   0.21%  compile  compile           [.] 0x00000000000b120f
   0.20%  compile  compile           [.] 0x000000000000f0e3
   0.20%  compile  compile           [.] 0x000000000001bd4a
   0.19%  compile  compile           [.] 0x000000000000b488
   0.19%  compile  compile           [.] 0x00000000000103e3
   0.18%  compile  compile           [.] 0x000000000001bd65
   0.18%  compile  compile           [.] 0x000000000001bc32
   0.18%  compile  compile           [.] 0x000000000002c835
   0.18%  compile  compile           [.] 0x000000000001bd76
   0.18%  compile  compile           [.] 0x00000000001740f2
   0.18%  compile  compile           [.] 0x0000000000056b12
   0.17%  compile  compile           [.] 0x0000000000057778
   0.17%  compile  compile           [.] 0x00000000001d5051
   0.17%  compile  compile           [.] 0x000000000001bcef
   0.17%  compile  compile           [.] 0x0000000000057282
   0.16%  compile  [kernel.vmlinux]  [k] __rmqueue
   0.16%  compile  compile           [.] 0x000000000001bc79
   0.16%  compile  compile           [.] 0x0000000000114d5a
   0.16%  compile  compile           [.] 0x000000000001be27
   0.15%  compile  compile           [.] 0x000000000001be36
   0.15%  compile  compile           [.] 0x000000000001bcbb
   0.15%  compile  compile           [.] 0x0000000000013c19
   0.15%  compile  compile           [.] 0x000000000001bf53
   0.15%  compile  compile           [.] 0x00000000000026cd
   0.15%  compile  compile           [.] 0x000000000005516e
   0.15%  compile  compile           [.] 0x000000000001bca6
   0.14%  compile  compile           [.] 0x000000000001bcf4
   0.14%  compile  compile           [.] 0x000000000001baa4
   0.14%  compile  compile           [.] 0x000000000002cff7
   0.14%  link     link              [.] 0x0000000000008171
   0.14%  compile  compile           [.] 0x000000000000f0b2

相关内容