Giter Site home page Giter Site logo

ondrajz / go-callvis Goto Github PK

View Code? Open in Web Editor NEW
5.8K 76.0 400.0 6.7 MB

Visualize call graph of a Go program using Graphviz

Home Page: https://ofabry.github.io/go-callvis

License: MIT License

Go 93.95% Makefile 6.05%
callgraph graphviz visualization golang golang-tools static-analysis awesome-go

go-callvis's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

go-callvis's Issues

Graph Relating Multiple Packages

I would like to be able to provide a comma-separated list of packages to graph their relationship to other packages (and possibly to each other). I.e.: go-callvis github.com/johnrichardrinehart/repo1/pkg1,github.com/johnrichardrinehart/repo1/pkg2. Note that pkg2 might depend on pkg1 and vice-versa.

internal error in pointer analysis: callEdge dynamic function call

Hi there! I got this error (and request to report the bug) while trying go-callvis on some proprietary code.

To Repro

sudo apt install -y graphviz
git clone <this repo>
make install
cd ~/GolandProjects/<proprietary repo>
go-callvis main.go

Stacktrace

Internal panic in pointer analysis:
goroutine 1 [running]:
runtime/debug.Stack(0x24, 0x0, 0x0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x22
golang.org/x/tools/go/pointer.Analyze.func1(0xc001a71d68)
        /home/saint/go/pkg/mod/golang.org/x/[email protected]/go/pointer/analysis.go:227 +0x10b
panic(0x8f2400, 0xc03241c430)
        /usr/local/go/src/runtime/panic.go:679 +0x1b2
golang.org/x/tools/go/pointer.(*analysis).callEdge(0xc013878e00, 0xc0183b1bf0, 0xc027ad1bc0, 0x25b0f)
        /home/saint/go/pkg/mod/golang.org/x/[email protected]/go/pointer/analysis.go:368 +0x78a
golang.org/x/tools/go/pointer.Analyze(0xc0239e7f90, 0x0, 0xa77bc0, 0xc03241c440)
        /home/saint/go/pkg/mod/golang.org/x/[email protected]/go/pointer/analysis.go:354 +0x68b
main.doAnalysis(0x0, 0x0, 0xc0000ae100, 0xc0000a2030, 0x1, 0x1, 0x3, 0x9cfb96)
        /home/saint/GolandProjects/go-callvis/analysis.go:50 +0x241
main.main()
        /home/saint/GolandProjects/go-callvis/main.go:104 +0x156
2020/04/05 11:11:37 internal error in pointer analysis: callEdge dynamic function call -> n154383: not a function object (please report this bug)

Internal panic in pointer analysis

go-callvis crashed when I try to make call graph of project "lnd":
Here is the log:

jason@lenovo:~/go/src/github.com/TrueFurby/go-callvis$ go-callvis -nostd -group pkg -limit github.com/lightningnetwork  github.com/lightningnetwork/lnd | dot -Tpng -o output.png
Internal panic in pointer analysis:
goroutine 1 [running]:
runtime/debug.Stack(0x24, 0x0, 0x0)
	/usr/local/go/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer.Analyze.func1(0xc420119a00)
	/home/jason/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer/analysis.go:227 +0x124
panic(0x6ad6a0, 0xc452e5e060)
	/usr/local/go/src/runtime/panic.go:491 +0x283
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer.(*analysis).taggedValue(0xc448689340, 0xc4000365ac, 0x1, 0x64, 0xc425d18700)
	/home/jason/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer/gen.go:272 +0x145
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer.(*untagConstraint).solve(0xc4495cc420, 0xc448689340, 0xc481759740)
	/home/jason/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer/solve.go:295 +0xd5
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer.(*analysis).solveConstraints(0xc448689340, 0xc4483e6ab0, 0xc481759740)
	/home/jason/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer/solve.go:165 +0x99
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer.(*analysis).solve(0xc448689340)
	/home/jason/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer/solve.go:59 +0x2e4
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer.Analyze(0xc42c506a50, 0x0, 0x894460, 0xc452e5e0c0)
	/home/jason/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer/analysis.go:331 +0x6b1
main.run(0x8b2f80, 0x71af6a, 0x4, 0xc420119ea8, 0xc4200de120, 0x1, 0x1, 0x8d1b98, 0x0, 0x0, ...)
	/home/jason/go/src/github.com/TrueFurby/go-callvis/main.go:159 +0x7ba
main.main()
	/home/jason/go/src/github.com/TrueFurby/go-callvis/main.go:77 +0x7ee
go-callvis: internal error in pointer analysis: not a tagged object: n222636 (please report this bug)

Option to omit defer functions

I have a suggestion that there is a need to omit defer functions when a package has so many. They would occupy plenty of unnecessary space. ๐Ÿš€

Thanks for your work. ๐Ÿ‘

Not looking for packages in 'mod' location

Error is

could not import github.com/aws/aws-lambda-go/events (cannot find package "github.com/aws/aws-lambda-go/events" in any of: /usr/local/Cellar/go/1.12.1/libexec/src/github.com/aws/aws-lambda-go/events (from $GOROOT) /Users/christopinka/go/src/github.com/aws/aws-lambda-go/events (from $GOPATH))

All dependencies are in /Users/christopinka/go/pkg/mod as module versions however.

go-callvis for quorum packages

git clone https://github.com/jpmorganchase/quorum.git
Iam trying this command
go-callvis -focus upgrade -group pkg,type -limit github.com/jpmorganchase/quorum github.com/jpmorganchase/quorum

output-
go-callvis: cannot find package "upgrade" in any of:
/usr/local/go/src/upgrade (from $GOROOT)
/home/ubuntu/go/src/upgrade (from $GOPATH)

[Question] can't generate the call graph for hashicorp/raft

I use the below command"

go-callvis -focus github.com/hashicorp/raft github.com/hashicorp/raft -limit github.com/hashicorp/raft -nostd

but there are many errors:

/Users/yuepan/go/src/github.com/hashicorp/raft/util.go:58:15: undeclared name: crand
/Users/yuepan/go/src/github.com/hashicorp/raft/util.go:59:9: undeclared name: fmt
/Users/yuepan/go/src/github.com/hashicorp/raft/util.go:62:9: undeclared name: fmt
/Users/yuepan/go/src/github.com/hashicorp/raft/util.go:129:9: undeclared name: fmt
/Users/yuepan/go/src/github.com/hashicorp/raft/util.go:132:9: invalid operation: buf (variable of type *invalid type) has no field or method Bytes
/Users/yuepan/go/src/github.com/hashicorp/raft/util.go:140:9: undeclared name: fmt
/Users/yuepan/go/src/github.com/hashicorp/raft/util.go:154:7: undeclared name: bytes
/Users/yuepan/go/src/github.com/hashicorp/raft/util.go:162:9: undeclared name: bytes
cannot find package "-limit" in any of:
	/usr/local/Cellar/go/1.7.4/libexec/src/-limit (from $GOROOT)
	/Users/yuepan/go/src/-limit (from $GOPATH)
cannot find package "-nostd" in any of:

Maybe I have made a mistake to use it.

My question is how to use it for github.com/hashicorp/raft github.com/hashicorp/raft

Cannot visualize github.com/alecthomas/gozmq

github.com/alecthomas/gozmq seems problematic for go-callvis to handle. I'm guessing because gozmq require cgo.

# % is my prompt
# Get the source, this works great, i have the libzmq3-dev deb-package installed on my machine
% go get -tags zmq_3_x github.com/alecthomas/gozmq
# The following command complain that various symbols are not declared. They are declared, but in the C part of package
% go-callvis github.com/alecthomas/gozmq
# go-callvis show the help pages when i do the following, missing feature?
% go-callvis -tags zmq_3_x github.com/alecthomas/gozmq

Is there any work ongoing to fix this?

callEdge dynamic function call -> n260892: not a function object

Hello,
I tried to get a call graph for the net/http package. But I got the following panic. Sadly I run this on some private code so I can not share the input code to reproduce the error.

go-callvis -focus upgrade -group pkg,type -limit net/http git.our.private.net/my/code              :(


Internal panic in pointer analysis:
goroutine 1 [running]:
runtime/debug.Stack(0x24, 0x0, 0x0)
	/usr/lib/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
	/usr/lib/go/src/runtime/debug/stack.go:16 +0x22
golang.org/x/tools/go/pointer.Analyze.func1(0xc08f7c1d68)
	/home/christoph/workspace/GO/src/golang.org/x/tools/go/pointer/analysis.go:227 +0x10b
panic(0x8f87e0, 0xc03cbd78f0)
	/usr/lib/go/src/runtime/panic.go:679 +0x1b2
golang.org/x/tools/go/pointer.(*analysis).callEdge(0xc048133a40, 0xc04b486a20, 0xc03c8bc360, 0x3fb1c)
	/home/christoph/workspace/GO/src/golang.org/x/tools/go/pointer/analysis.go:368 +0x78a
golang.org/x/tools/go/pointer.Analyze(0xc0487bb2c0, 0x0, 0xa7ed40, 0xc03cbd7910)
	/home/christoph/workspace/GO/src/golang.org/x/tools/go/pointer/analysis.go:354 +0x68b
main.doAnalysis(0x0, 0x0, 0xc000024600, 0xc0000200f0, 0x1, 0x1, 0x3, 0x9d67da)
	/home/christoph/workspace/GO/src/github.com/TrueFurby/go-callvis/analysis.go:49 +0x241
main.main()
	/home/christoph/workspace/GO/src/github.com/TrueFurby/go-callvis/main.go:104 +0x156
2019/10/14 14:52:29 internal error in pointer analysis: callEdge dynamic function call -> n260892: not a function object (please report this bug)

Way to focus on a type instead of a package?

Is there a way to focus on the methods of a type instead of all functions in a package? I'm wondering if maybe this functionality already exists but I just don't know how to use the flags properly.

(Brilliant tool, by the way!)

focus on multiple packages

We have a library that is separated into many sub-packages in deeply nested folders in the repo. We would like to visualize this entire library, i.e. we would like to focus on all these sub-packages. How can we do this?

Thanks

Andy

Cross-platform build tool support?

I'm trying to run this against a project that has platform-specific build files, and it's failing. Not sure if it's because I'm not ignoring stuff properly or if it's because of cross-platform builds.

Command:

go-callvis -focus github.com/rancher/os/cmd/control/install \
-limit github.com/rancher/os/cmd/control/install \
-ignore github.com/rancher/os/netconf,github.com/rancher/os/util,github.com/rancher/os/netconf/bridge \
github.com/rancher/os/cmd/control/install | dot -Tpng -o install.png

Result:

~/go/src/github.com/rancher/os/netconf/bridge.go:41:39: cannot use bridge (variable of type *github.com/rancher/os/vendor/github.com/vishvananda/netlink.Bridge) as *github.com/rancher/os/vendor/github.com/vishvananda/netlink.Link value in argument to netlink.LinkSetMaster
~/go/src/github.com/rancher/os/cmd/control/install/install.go:43:30: Mount not declared by package util
~/go/src/github.com/rancher/os/cmd/control/install/install.go:50:16: Blkid not declared by package util
~/go/src/github.com/rancher/os/cmd/control/install/install.go:58:14: ResolveDevice not declared by package util
~/go/src/github.com/rancher/os/cmd/control/install/install.go:62:18: Blkid not declared by package util
go-callvis: couldn't load packages due to errors: github.com/rancher/os/netconf, github.com/rancher/os/cmd/control/install

I suspect that this is at least partially due to the util package having platform-specific builds. For example, most of the errors above (Mount, Blkid, ResolveDevice) reside in util_linux.go instead of the main util.go:

github.com/rancher/os/util/util_linux.go

// +build linux

package util

Can anyone confirm that I am not ignoring or focussing this target properly?

callvis crashed with "out of memory" while running on Ubuntu 18.04

go version go1.11.4 linux/amd64

part of the printout:

fredzhou@fredzhou-Ubuntu:~/go/src/github.com/ethereum/go-ethereum$ go-callvis "github.com/syncthing/syncthing/cmd/stcli"
fatal error: runtime: out of memory

runtime stack:
runtime.throw(0x91d522, 0x16)
	/usr/local/go/src/runtime/panic.go:608 +0x72
runtime.sysMap(0xc014000000, 0x4000000, 0xcf2298)
	/usr/local/go/src/runtime/mem_linux.go:156 +0xc7
runtime.(*mheap).sysAlloc(0xcd8ea0, 0x4000000, 0x7f756002b260, 0x7f7561379d00)
	/usr/local/go/src/runtime/malloc.go:619 +0x1c7
runtime.(*mheap).grow(0xcd8ea0, 0xf7, 0x0)
	/usr/local/go/src/runtime/mheap.go:920 +0x42
runtime.(*mheap).allocSpanLocked(0xcd8ea0, 0xf7, 0xcf22a8, 0x20300100000000)
	/usr/local/go/src/runtime/mheap.go:848 +0x337
runtime.(*mheap).alloc_m(0xcd8ea0, 0xf7, 0x410100, 0x7f7560325400)
	/usr/local/go/src/runtime/mheap.go:692 +0x119
runtime.(*mheap).alloc.func1()
	/usr/local/go/src/runtime/mheap.go:759 +0x4c
runtime.(*mheap).alloc(0xcd8ea0, 0xf7, 0x7f7561010100, 0x417675)
	/usr/local/go/src/runtime/mheap.go:758 +0x8a
runtime.largeAlloc(0x1ede80, 0x450001, 0x7f75676d16c0)
	/usr/local/go/src/runtime/malloc.go:1019 +0x97
runtime.mallocgc.func1()
	/usr/local/go/src/runtime/malloc.go:914 +0x46
runtime.systemstack(0x0)
	/usr/local/go/src/runtime/asm_amd64.s:351 +0x66
runtime.mstart()
	/usr/local/go/src/runtime/proc.go:1229

goroutine 295 [running]:
runtime.systemstack_switch()
	/usr/local/go/src/runtime/asm_amd64.s:311 fp=0xc00b2b49f8 sp=0xc00b2b49f0 pc=0x4567f0
runtime.mallocgc(0x1ede80, 0x8c56e0, 0x1, 0x0)
	/usr/local/go/src/runtime/malloc.go:913 +0x896 fp=0xc00b2b4a98 sp=0xc00b2b49f8 pc=0x40d7e6
runtime.newarray(0x8c56e0, 0x1108, 0x0)
	/usr/local/go/src/runtime/malloc.go:1048 +0x6a fp=0xc00b2b4ac8 sp=0xc00b2b4a98 pc=0x40dbba
runtime.makeBucketArray(0x87ea80, 0x32f574628b75c50c, 0x0, 0x0, 0x0)
	/usr/local/go/src/runtime/map.go:355 +0x184 fp=0xc00b2b4b00 sp=0xc00b2b4ac8 pc=0x40ea84
runtime.hashGrow(0x87ea80, 0xc002d7e060)
	/usr/local/go/src/runtime/map.go:963 +0x89 fp=0xc00b2b4b50 sp=0xc00b2b4b00 pc=0x4102d9
runtime.mapassign(0x87ea80, 0xc002d7e060, 0xc00b2b4bf8, 0x0)
	/usr/local/go/src/runtime/map.go:623 +0x2af fp=0xc00b2b4bd8 sp=0xc00b2b4b50 pc=0x40f44f
go/types.(*Checker).recordTypeAndValue(0xc00016d2c0, 0x99f440, 0xc003189920, 0xc003189907, 0x99d160, 0xc00b5e5bb0, 0x0, 0x0)
	/usr/local/go/src/go/types/check.go:292 +0x13c fp=0xc00b2b4c40 sp=0xc00b2b4bd8 pc=0x5b6cfc
go/types.(*Checker).rawExpr(0xc00016d2c0, 0xc005af26c0, 0x99f440, 0xc003189920, 0x0, 0x0, 0x0)
	/usr/local/go/src/go/types/expr.go:993 +0x299 fp=0xc00b2b4ce0 sp=0xc00b2b4c40 pc=0x5c2a09
go/types.(*Checker).multiExpr(0xc00016d2c0, 0xc005af26c0, 0x99f440, 0xc003189920)
	/usr/local/go/src/go/types/expr.go:1575 +0x58 fp=0xc00b2b4d48 sp=0xc00b2b4ce0 pc=0x5c6c38
go/types.(*Checker).call.func1(0xc005af26c0, 0x0)
	/usr/local/go/src/go/types/call.go:65 +0x61 fp=0xc00b2b4d78 sp=0xc00b2b4d48 pc=0x5ed701
go/types.unpack(0xc00b2b4e70, 0x1, 0xc007f88000, 0xc0032adf40, 0xc00c702330, 0x1)
	/usr/local/go/src/go/types/call.go:181 +0x61 fp=0xc00b2b4de0 sp=0xc00b2b4d78 pc=0x5b4031
go/types.(*Checker).call(0xc00016d2c0, 0xc005af2680, 0xc0032b4480, 0x2)
	/usr/local/go/src/go/types/call.go:65 +0x36a fp=0xc00b2b4e98 sp=0xc00b2b4de0 pc=0x5b38ba
go/types.(*Checker).exprInternal(0xc00016d2c0, 0xc005af2680, 0x99ec80, 0xc0032b4480, 0x0, 0x0, 0x7f75676d16c0)
	/usr/local/go/src/go/types/expr.go:1445 +0x1d0c fp=0xc00b2b5448 sp=0xc00b2b4e98 pc=0x5c47bc
go/types.(*Checker).rawExpr(0xc00016d2c0, 0xc005af2680, 0x99ec80, 0xc0032b4480, 0x0, 0x0, 0x2)
	/usr/local/go/src/go/types/expr.go:969 +0x81 fp=0xc00b2b54e8 sp=0xc00b2b5448 pc=0x5c27f1
go/types.(*Checker).stmt(0xc00016d2c0, 0x0, 0x99eec0, 0xc0032a8a20)
	/usr/local/go/src/go/types/stmt.go:325 +0x40c5 fp=0xc00b2b5c48 sp=0xc00b2b54e8 pc=0x5e2ef5
go/types.(*Checker).stmtList(0xc00016d2c0, 0x0, 0xc003289800, 0xf, 0x10)
	/usr/local/go/src/go/types/stmt.go:120 +0xd6 fp=0xc00b2b5ca0 sp=0xc00b2b5c48 pc=0x5dd876
go/types.(*Checker).funcBody(0xc00016d2c0, 0xc0084d82a0, 0xc00328cde0, 0x3, 0xc0087460f0, 0xc0032b04b0, 0x0, 0x0)
	/usr/local/go/src/go/types/stmt.go:42 +0x1ea fp=0xc00b2b5d90 sp=0xc00b2b5ca0 pc=0x5dd1fa
go/types.(*Checker).funcDecl.func1()
	/usr/local/go/src/go/types/decl.go:611 +0x67 fp=0xc00b2b5de0 sp=0xc00b2b5d90 pc=0x5edb57
go/types.(*Checker).processDelayed(0xc00016d2c0, 0x0)
	/usr/local/go/src/go/types/resolver.go:583 +0x33 fp=0xc00b2b5df0 sp=0xc00b2b5de0 pc=0x5d9143
go/types.(*Checker).checkFiles(0xc00016d2c0, 0xc002d7c120, 0xc, 0xc, 0x0, 0x0)
	/usr/local/go/src/go/types/check.go:252 +0xbc fp=0xc00b2b5e20 sp=0xc00b2b5df0 pc=0x5b6a1c
go/types.(*Checker).Files(0xc00016d2c0, 0xc002d7c120, 0xc, 0xc, 0x1c, 0xc000b73d10)
	/usr/local/go/src/go/types/check.go:241 +0x49 fp=0xc00b2b5e60 sp=0xc00b2b5e20 pc=0x5b6939
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader.(*importer).addFiles(0xc000099680, 0xc00048b130, 0xc002d7c120, 0xc, 0xc, 0x1)
	/home/fredzhou/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader/loader.go:1022 +0x191 fp=0xc00b2b5f00 sp=0xc00b2b5e60 pc=0x603691
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader.(*importer).load(0xc000099680, 0xc001467180, 0x0)
	/home/fredzhou/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader/loader.go:981 +0x163 fp=0xc00b2b5fa0 sp=0xc00b2b5f00 pc=0x603433
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader.(*importer).startLoad.func1(0xc000099680, 0xc001467180, 0xc002d7a4c0)
	/home/fredzhou/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader/loader.go:962 +0x39 fp=0xc00b2b5fc8 sp=0xc00b2b5fa0 pc=0x604e59
runtime.goexit()
	/usr/local/go/src/runtime/asm_amd64.s:1333 +0x1 fp=0xc00b2b5fd0 sp=0xc00b2b5fc8 pc=0x4588d1
created by github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader.(*importer).startLoad
	/home/fredzhou/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader/loader.go:961 +0x191

goroutine 1 [chan receive]:
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader.(*importInfo).awaitCompletion(...)
	/home/fredzhou/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader/loader.go:447
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader.(*importer).importAll(0xc000099680, 0x0, 0x0, 0xc00002a004, 0x35, 0xc000113ec0, 0x0, 0x0, 0x0, 0x0, ...)
	/home/fredzhou/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader/loader.go:913 +0x406
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader.(*Config).Load(0xc0000e0420, 0xc00009c010, 0x1, 0x1)
	/home/fredzhou/go/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/loader/loader.go:521 +0x27f
main.doAnalysis(0xcd3060, 0x0, 0xc00009c010, 0x1, 0x1)
	/home/fredzhou/go/src/github.com/TrueFurby/go-callvis/analysis.go:34 +0x17e
main.main()
	/home/fredzhou/go/src/github.com/TrueFurby/go-callvis/main.go:80 +0x108

Startup problems?

Hello -- looks like a great tool. However, after following your install procedure, when I run go-callvis using your example I get this:
go-callvis -focus upgrade -limit github.com/syncthing/syncthing github.com/syncthing/syncthing/cmd/syncthing | dot -Tpng -o syncthing_focus.png
/opt/Projects/Golang/src/github.com/syncthing/syncthing/cmd/syncthing/gui_statics.go:37:13: Assets not declared by package auto
/opt/Projects/Golang/src/github.com/syncthing/syncthing/cmd/syncthing/gui_statics.go:44:20: Assets not declared by package auto
/opt/Projects/Golang/src/github.com/syncthing/syncthing/cmd/syncthing/gui_statics.go:44:20: cannot range over auto.Assets() (invalid operand)
go-callvis: couldn't load packages due to errors: github.com/syncthing/syncthing/cmd/syncthing

Am I doing something wrong?

packages contain errors

go-callvis.exe --debug -nostd ./resbroker/broker/                                                                                                           
D:\Go\src\runtime\cgo\cgo.go:31:8: could not import C (no metadata for C)
D:\GOPATH\pkg\mod\github.com\mattn\[email protected]+incompatible\backup.go:16:8: could not import C (no metadata for C)
17:15:55.715345 packages contain errors

need generic example

I tried a lot of the examples, and bend them to my needs, but none of them generates an image that represents the software.
I don't even know if it is needed that the software to be analyzed, should be in a GOPATH?

I haven't got that, so I'm not sure....
I do like this:
go-callvis -group pkg,type -nostd ./...
But I just got a main that has 2 childs (1 being error and 1 being the initialize)

How can I make a picture that covers my whole project?
(I did I misunderstood and isn't the tool capable of doing so?)

Focus on function instead of package

I have a web service that registers callback functions that never get explicitly called. Running this tool skips over those functions, which is exactly what I want to graph.

Visualize call graph of Go libs

Can go-callvis be used to visualize call graph for Go libs? I got go-callvis: no main packages by doing so, and no output generated.

Here are details:

gpkg=github.com/andrew-d/goscrape

$ go-callvis -limit $gpkg -focus $gpkg $gpkg | dot -Tpng -o /tmp/out.png
go-callvis: no main packages

$ ls /tmp/out.png
ls: cannot access '/tmp/out.png': No such file or directory

Call graph of server start with run

Hi, I want to use go-callvis to get the call graph of pd server which starts with function Run().
Command like this:
go-callvis -focus="" -limit github.com/pingcap/pd/server -ignore github.com/pingcap/pd/vendor | dot -Tpng -o pd_server.png

Nothing I got but the usage, so what is the problem?

can't run

2019/04/26 10:45:04 http serving at http://localhost:7878
2019/04/26 10:45:05 converting dot to svg..
2019/04/26 10:45:05 unable to find program 'dot', please install it or check your PATH

internal error in pointer analysis: callEdge dynamic function call -> n253458: not a function object

Internal panic in pointer analysis:
goroutine 1 [running]:
runtime/debug.Stack(0x24, 0x0, 0x0)
        /usr/local/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
        /usr/local/go/src/runtime/debug/stack.go:16 +0x22
golang.org/x/tools/go/pointer.Analyze.func1(0xc011f81d90)
        /Users/klook/go/src/golang.org/x/tools/go/pointer/analysis.go:227 +0x157
panic(0x14e0dc0, 0xc03c2d3360)
        /usr/local/go/src/runtime/panic.go:522 +0x1b5
golang.org/x/tools/go/pointer.(*analysis).callEdge(0xc04f1f88c0, 0xc0531dad80, 0xc00bb8fb00, 0x3de12)
        /Users/klook/go/src/golang.org/x/tools/go/pointer/analysis.go:368 +0x78c
golang.org/x/tools/go/pointer.Analyze(0xc04f2c55e0, 0x0, 0x1658140, 0xc03c2d3380)
        /Users/klook/go/src/golang.org/x/tools/go/pointer/analysis.go:354 +0x6e1
main.doAnalysis(0x0, 0x0, 0xc000022200, 0xc0000b8010, 0x1, 0x1, 0xc000030660, 0xc000024540)
        /Users/klook/go/src/github.com/TrueFurby/go-callvis/analysis.go:49 +0x2ec
main.main()
        /Users/klook/go/src/github.com/TrueFurby/go-callvis/main.go:104 +0x158
2020/01/19 11:28:46 internal error in pointer analysis: callEdge dynamic function call -> n253458: not a function object (please report this bug)

Large project

I have a large project (mainly a lot of generated codes) and facing this error:
dot: graph is too large for cairo-renderer bitmaps. Scaling by 0.235786 to fit
it is useless for that main package, can this render large image without scaling it?

ps: tried with svg but dot failed.

can't build

go version: go version go1.10 linux/amd64

command: make

output:

dep ensure
make: dep: Command not found
make: *** [Makefile:10: dep] Error 127

Crash using empty -focus

Trying to get the call-graph of an app with a lot of sub-packages and using the trick specified in #28

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x89e7d7]

goroutine 1 [running]:
main.(*analysis).render(0xc031240640, 0x7ffd60155567, 0x0, 0xc007f75a70, 0x1, 0x1, 0x0, 0x0, 0x0, 0x0, ...)
        /misc/go-callvis/analysis.go:123 +0x77
main.outputDot(0x7ffd6015554b, 0x9, 0x9bfcc3, 0x3)
        /misc/go-callvis/main.go:64 +0x316
main.main()
        /misc/go-callvis/main.go:120 +0x3f5```

graphviz segfault

I run:

~/go/bin/go-callvis -group pkg -nointer -file /tmp/rotator-modules -skipbrowser -ignore gotask.ws/scm/ts/rotator/vendor -nostd -focus '' -limit gotask.ws/scm/ts/rotator/modules gotask.ws/scm/ts/rotator/cmd/rotator

And receive:

2019/03/12 09:10:50 writing dot output..
2019/03/12 09:10:50 converting dot to svg..
2019/03/12 09:11:52 signal: segmentation fault

I've tried to run the dot manually, to see the error. The result:

libpath/shortest.c:324: triangulation failed
libpath/shortest.c:192: source point not in any triangle
Error: in routesplines, Pshortestpath failed
Segmentation fault

It seems it's impossible to visualize such graph.

Make returns "Makefile:12: *** target pattern contains no '%'. Stop."

Makefile

1 VERSION := $(shell git describe --tags --always --dirty)
2 GOARCH := $(shell go env GOARCH)
3 LDFLAGS := -X main.Version=$(VERSION)
4
5 BUILD_DIR ?= build
6 BINARY := go-callvis
7 RELEASE := $(BUILD_DIR)/$(BINARY)_$(VERSION)-$(GOARCH)
8
9 DEP ?= $(GOPATH)/bin/dep
10
11
12 all: $(DEP) install
13
14 $(DEP):
15 go get -u github.com/golang/dep/cmd/dep
16 dep version
17
18 install:
19 @echo "-> Installing go-callvis $(VERSION)"
20 go install -ldflags "$(LDFLAGS)"
21
22 build:
23 @echo "-> Building go-callvis $(VERSION)"
24 go build -v -ldflags "$(LDFLAGS)" -o $(BINARY)
25
26 release:
27 @echo "-> Releasing go-callvis $(VERSION)"
28 mkdir -p $(BUILD_DIR)
29 go build -ldflags "$(LDFLAGS)" -o $(RELEASE)
30
31 clean:
32 go clean -i
33
34 test:
35 go test -v
36
37
38 .PHONY: all install build release clean test

what dose these mean in the svg file? "$" "#"

i am a new comer to this nice project , and i begin to use go-callvis to analyze the source code of golevedbhttps://github.com/syndtr/goleveldb.after i generate the svg file , i find some symbols(eg. "$","#" in "main$6", "main$5$1$1" ,"init#1"
free-converter com-111-92282555

) in the svg.
what does these symbols mean? Do they mean a goroutine function call?
my commond is blow:
go-callvis -group pkg,type -nostd -nodesep 0.05 -limit github.com/syndtr github.com/syndtr/goleveldb/manualtest/dbstress

support for modules

when using go-callvis with a 1.11 module project, I am not able to get an output, I just get a lot of "could nit find x in any of ..."

init() of blanked imports are ignored

Hi, I have a project that contains multiple imported packages, some of them are blanked because I'm using only the init() function, the problem is that in go-callvis they are not displayed. I use

go-callvis -group type,pkg ../myproject |dot -Tpng -o out.png

I'm missing something?

Charting goreleaser

Hi,

I'm trying to chart goreleaser, from github.com/goreleaser/goreleaser, however, I only get this small chart out of the big package:

goreleaser

I've tried,

gpkg=github.com/goreleaser/goreleaser
go-callvis -group pkg,type -limit $gpkg $gpkg | dot -Tpng -o ~/out.png
# and
go-callvis -group pkg,type -limit github.com/goreleaser $gpkg | dot -Tpng -o ~/out.png

But the results are the same for both cases.

This is big package with many types and sub-folders, how come the chart is so limited, and how can I see the whole picture?

PS. Here is its folder structure:

./context
./checksum
./config
./config/testdata
./pipeline
./pipeline/env
./pipeline/fpm
./pipeline/fpm/testdata
./pipeline/git
./pipeline/brew
./pipeline/brew/testdata
./pipeline/snapcraft
./pipeline/cleandist
./pipeline/release
./pipeline/build
./pipeline/defaults
./pipeline/checksums
./pipeline/archive
./goreleaserlib
./internal
./internal/ext
./internal/name
./internal/testlib
./internal/client
./internal/buildtarget
./internal/archiveformat

Within each folder there at least one or two types define.

Please help. Thanks!

Include concrete usage example in README?

Hi,

I'm a bit confused as how to use go-callvis. What do I put where it says <main pkg> in the usage example?

I have tried the following, with the results you can see:

$ go-callvis github.com/scipipe/scipipe | dot -Tpng -o output.png
go-callvis: cannot find package "main" in any of:
        /home/samuel/go/src/main (from $GOROOT)
        /home/samuel/proj/go/src/main (from $GOPATH)

... and:

$ go-callvis github.com/scipipe/scipipe/main | dot -Tpng -o output.png
cannot find package "github.com/scipipe/scipipe/main" in any of:
        /home/samuel/go/src/github.com/scipipe/scipipe/main (from $GOROOT)
        /home/samuel/proj/go/src/github.com/scipipe/scipipe/main (from $GOPATH)
go-callvis: no initial packages were loaded

mac 10.3 make failed

cd github.com/TrueFurby/go-callvis/ && make

go get github.com/golang/dep/cmd/dep
dep ensure -update
make: dep: No such file or directory
make: *** [dep] Error 1

Can go-callvis run on the windows

after run go get cmd

This one
go-callvis [OPTIONS]

| dot -Tpng -o output.png
seems get problem

any other Path things should be set on windows ?

Enhancement: parse comment tag on goroutines to name them in diagram

In my diagrams, goroutines, being anonymous, get the name of their parent function with a $n appended. It would be nice if a specially-formatted comment associated with a goroutine would allow a more meaningful name to be generated for the goroutine in the resulting diagram, eg:

func A() {
..
  // #dot: ControlChannelReader
  go func() {
    ... // labelled 'ControlChannelReader' in resulting diagram rather than 'A$1'
  }()
}

Unsure what the best tag name would be: dot? gv?

Makefile assumes GOPATH has one directory

I get thios error when I run make:

Fatal: Unable to execute command: L:\Dev...;D:\Golang/bin/dep

I think this is becuase the makefile uses $(GOPATH) as if it contains a single directory

dep:
$(GOPATH)/bin/dep ensure

Calls between non-focused funcs are not shown

Currently only calls to or from focused package are shown. However in cases when the results two contain functions which are both outside focused package and shown because focused package has some calls from/to both. Calls between such functions should be shown since both functions are already in the result anyway.

Example code

package main

import (
    "fmt"

    "golang.org/x/sync/errgroup"
)

func main() {
    var g errgroup.Group
    g.Go(func() error {
        fmt.Println("Hello world")
        return nil
    })
    g.Wait()
}

Result

result

You can see that main calls (*Group).Go and (*Group).Go$1 calls main$1. However the call between those two funcs inside errgroup is not shown even though both are in the result already.

By showing such calls the results would make clearer results by showing complete call path from the main to the fmt.Println.

Thanks @DmitriyMV for reporting this issue!

Focus option should support using full import path

For situations where there might be two packages used with the same name in the program, an error should be shown and user can use full import path of the focused pkg to clearly define which one was meant to be used.

Also currently no error is shown even when defined focus pkg is not found in the program.

Thanks @peterhellberg for mentioning this!

[Graphviz] Optimize settings to provide cleaner layout

The current Graphviz settings used for the output via dot utility is not very useful when used on packages with large call graphs. I believe there must be some way to tweak the graphviz attributes to generate output with cleaner layout. Experienced Graphviz users are welcome to help! โ—

Here's some example from old discussion.

In the picture below I marked the areas with calls which are impossible to distinguish from each other. In situations like this there is little benefit from generating this without using deliberate limits and ignores...

Panic on callEdge dynamic function call

Internal panic in pointer analysis:
goroutine 1 [running]:
runtime/debug.Stack(0x24, 0x0, 0x0)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/debug/stack.go:24 +0xa7
runtime/debug.PrintStack()
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/debug/stack.go:16 +0x22
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer.Analyze.func1(0xc44341fa00)
	/Users/*********/code/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer/analysis.go:227 +0x124
panic(0x12aa0a0, 0xc44db24cc0)
	/usr/local/Cellar/go/1.9.2/libexec/src/runtime/panic.go:491 +0x283
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer.(*analysis).callEdge(0xc4296461c0, 0xc4258ad080, 0xc43bc346c0, 0x13eef)
	/Users/*********/code/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer/analysis.go:368 +0x937
github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer.Analyze(0xc43386d720, 0x0, 0x1490440, 0xc44db24e40)
	/Users/*********/code/src/github.com/TrueFurby/go-callvis/vendor/golang.org/x/tools/go/pointer/analysis.go:354 +0x8b8
main.run(0x14ae8e0, 0x1316ee6, 0x4, 0xc44341fea8, 0x14cd4e8, 0x0, 0x0, 0x14cd4e8, 0x0, 0x0, ...)
	/Users/*********/code/src/github.com/TrueFurby/go-callvis/main.go:159 +0x7ba
main.main()
	/Users/*********/code/src/github.com/TrueFurby/go-callvis/main.go:77 +0x7ee
go-callvis: internal error in pointer analysis: callEdge dynamic function call -> n81647: not a function object (please report this bug)

Funny pointer problem, can I exclude it? ignore does't help

go-callvis -focus=cmd  -ignore=github.com/btcsuite/btcd,github.com/btcsuite/btcutil -limit=github.com/lightningnetwork/lnd  -nostd  github.com/lightningnetwork/lnd/cmd/lnd  | dot -Tsvg -o dependency_graph.svg 
Internal panic in pointer analysis:
goroutine 1 [running]:
runtime/debug.Stack(0x24, 0x0, 0x0)
	/usr/local/go/src/runtime/debug/stack.go:24 +0x9d
runtime/debug.PrintStack()
	/usr/local/go/src/runtime/debug/stack.go:16 +0x22
golang.org/x/tools/go/pointer.Analyze.func1(0xc001131d68)
	/Users/hamiltonwang/go/pkg/mod/golang.org/x/[email protected]/go/pointer/analysis.go:227 +0x10b
panic(0x14f89c0, 0xc040b8d220)
	/usr/local/go/src/runtime/panic.go:679 +0x1b2
golang.org/x/tools/go/ssa.(*Program).LookupMethod(0xc01eb10500, 0x1683580, 0xc0290bab60, 0x0, 0x15c1c80, 0x5, 0xc020795900)
	/Users/hamiltonwang/go/pkg/mod/golang.org/x/[email protected]/go/ssa/methods.go:49 +0x1ac
golang.org/x/tools/go/pointer.(*invokeConstraint).solve(0xc0578e43d0, 0xc03918e380, 0xc041994700)
	/Users/hamiltonwang/go/pkg/mod/golang.org/x/[email protected]/go/pointer/solve.go:326 +0x2b1
golang.org/x/tools/go/pointer.(*analysis).solveConstraints(0xc03918e380, 0xc04c436240, 0xc041994700)
	/Users/hamiltonwang/go/pkg/mod/golang.org/x/[email protected]/go/pointer/solve.go:165 +0x176
golang.org/x/tools/go/pointer.(*analysis).solve(0xc03918e380)
	/Users/hamiltonwang/go/pkg/mod/golang.org/x/[email protected]/go/pointer/solve.go:59 +0x1a7
golang.org/x/tools/go/pointer.Analyze(0xc04a6350e0, 0x0, 0x1680200, 0xc040b8d250)
	/Users/hamiltonwang/go/pkg/mod/golang.org/x/[email protected]/go/pointer/analysis.go:331 +0x4ac
main.doAnalysis(0x0, 0x0, 0xc000022200, 0xc0000ca170, 0x1, 0x1, 0x3, 0x15d6d23)
	/Users/hamiltonwang/go/pkg/mod/github.com/!true!furby/[email protected]/analysis.go:49 +0x241
main.main()
	/Users/hamiltonwang/go/pkg/mod/github.com/!true!furby/[email protected]/main.go:104 +0x156
2019/12/05 16:01:11 internal error in pointer analysis: *github.com/btcsuite/btcutil.AddressPubKeyHash has no method Error (please report this bug)

As shown above

Thanks

Run as non-http utility (eg output SVG, PNG to a file w/o opening a web server)

USE CASE: calling go-callvis from a Makefile to non-interactively generate an output image of dot visualization

The examples page shows usage such as

go-callvis <opts> | dot -Tpng -o output.png

However this calling style still seems to launch the web browser with output rather than just outputting a dot PNG file, making it unsuitable for use in scripts or makefiles. Piping to 'dot' util as in the examples appears not to work as go-callvis doesn't output suitable data to stdout.

EDIT: I see that while the program is running, the output is written to /tmp/go-callvis_export.svg. Basically it would be good if this were specifiable via a new option like '-output' to give a custom path, and if -skipbrowser or the presence of -output would prevent launching the web browser and have go-callvis exit after generating the SVG.

I'll work on a patch to do this and submit a pull request.

`make` broken out of the box

$ make
go get -u github.com/golang/dep/cmd/dep
dep ensure -update
dep: WARNING: Unknown field in manifest: dependencies
Found 1 errors:

import path github.com/TrueFurby/go-callvis/examples/main had a local import: "./mypkg"
make: *** [dep] Error 1

The import path can be fixed by changing ./mypkg to github.com/TrueFurby/go-callvis/examples/main/mypkg, but after doing that, you'll still get:

$ make
go get -u github.com/golang/dep/cmd/dep
dep ensure -update
dep: WARNING: Unknown field in manifest: dependencies
Gopkg.toml and Gopkg.lock are out of sync. Run a plain dep ensure to resync them before attempting to -update
make: *** [dep] Error 1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.