ondrajz / go-callvis

Visualize call graph of a Go program using Graphviz
https://ofabry.github.io/go-callvis
MIT License
5.91k stars 408 forks source link

Charting goreleaser #12

Closed suntong closed 7 years ago

suntong commented 7 years ago

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!

suntong commented 7 years ago

Oh, is it because all non-public functions & types are ignored?

I even tried this:

go-callvis -group pkg,type -nostd $gpkg | dot -Tpng -o ~/out.png

But the result is still rather limited:

nostd

If so, the non-public functions & types are equally important (besides the public ones) for people to understand the package, when they are trying to how how things related, which is what go-callvis for and why they are using it.

Please consider adding a switch to output those.
Thx.

ondrajz commented 7 years ago

I think I know why you might be confused. I will try to explain.

Both of your examples show expected output. Keep in mind that this tool only shows function calls. For example it won't show types, variables or constants. It can only show relation to a type if its method is called.

I assume that by non-public functions you meant unexported. The output always shows both unexported and exported functions. Currently there isn't any flag to omit them. In the Reference guide you can see the difference in visualization of those functions.

In your examples you can clearly see unexported function init calling anonymous function init#1. The reason why you don't see any calls from the main package to some unexported function inside other package is because that's impossible in Go, since unexported functions can only be called inside package.

The important flag which controls what is shown in the output is -focus flag. By default it is set to main, that means it will only show function calls from and to the main package. If you want to show calls inside other package you can use -focus flag to change the shown package.

You can find more thorough explanation in the wiki: https://github.com/TrueFurby/go-callvis/wiki/Focusing-packages

suntong commented 7 years ago

Oh, that's the trick. Thanks a lot for the comprehensive explanation, and the wiki example too!

So, FTA, this works,

go-callvis -group pkg,type -focus="" -limit github.com/goreleaser $gpkg | dot -Tpng -o ~/screenshot.png

and generated this chart:

chart