jschwinger233 / gofuncgraph

bpf(2)-based ftrace(1)-like function graph tracer for golang processes.
MIT License
27 stars 5 forks source link

help: how to use gofuncgraph correctly #2

Closed hitzhangjie closed 1 year ago

hitzhangjie commented 1 year ago

I have a golang program:

package main

import "time"

func main() {
  time.Sleep(time.Second)
}

then build go build -o main main.go

then run:

$ gofuncgraph --uprobe-wildcards='main.main' ./main 
found 3 uprobes, large number of uprobes (>1000) need long time for attaching and detaching, continue? [Y/n]
Y
INFO[0003] start tracing                                
^C
INFO[0009] start detachin

After 1 second, there's nothing output, I have to ctrl+c to terminate. I want to see the timecost duration execution of main.main. Please help.

jschwinger233 commented 1 year ago
$ sudo gofuncgraph --uprobe-wildcards 'main.main' ./gofunc_issue_2 'main.main'
found 3 uprobes, large number of uprobes (>1000) need long time for attaching and detaching, continue? [Y/n]
y
INFO[0002] start tracing                                

17 19:33:08.6581           main.main() { runtime.main+519 ?:?
17 19:33:09.6582 001.0001  } main.main+39 /home/gray/src/github.com/jschwinger233/proving-ground/gofunc_issue_2/main.go:7
^CINFO[0030] start detaching 

Steps:

  1. sudo gofuncgraph --uprobe-wildcards 'main.main' ./main 'main.main'
  2. in another terminal: ./main

Probably you thought gofuncgraph would execute the command automatically, it actually merely traces the binary, and you'll have to run the command manually.

Sorry for the misunderstanding, I've always been too lazy to work out an up-to-date and user-friendly documentation.

jschwinger233 commented 1 year ago

BTW your tech blog helped me before, thanks a lot for those high-quality articles regarding ELF and debugger. :+1:

jschwinger233 commented 1 year ago

To be clear, the execution order is not required: in this case we have to run gofuncgraph ahead of ./main, otherwise we'll miss the invocation of main.main function.

For another scenario, for instance, if we'd like to trace grpc-related APIs inside a running daemon, just run gofuncgraph to attach the binary, then we can collect information from running process without disruption.

hitzhangjie commented 1 year ago

Thanks very much. It works.

hitzhangjie commented 1 year ago

I'm learning how to use ebpf and cilium. gofuncgraph is not only a very nice tool but also a good learning material. 👍