When I'm diving into a new codebase, I always start from the project structure analysis. And my favorite tool is
tree. However, not every project is perfectly balanced. Some files and folders tend to be more popular and contain much more code than others. Seems like yet another incarnation of the Pareto principle.
So, when the
tree's capabilities aren't enough, I jump to
cloc. This tool is much more powerful and can show nice textual statistics for the number of code lines and programming languages used per the whole project or per each file individually.
However, some projects are really huge and some lovely visualization would be truly helpful! And here the FlameGraph goes! What if we feed the
cloc's output for the Kubernetes codebase to FlameGraph? Thanks to the author of this article for the original cloc-to-flamegraph one-liner:
git clone https://github.com/brendangregg/FlameGraph go get -d github.com/kubernetes/kubernetes cd $(go env GOPATH)/src/github.com/kubernetes/kubernetes cloc --csv-delimiter="$(printf '\t')" --by-file --quiet --csv . | \ sed '1,2d' | \ cut -f 2,5 | \ sed 's/\//;/g' | \ ~/FlameGraph/flamegraph.pl \ --width=3600 \ --height=32 \ --fontsize=8 \ --countname=lines \ --nametype=package \ > kubernetes.html open kubernetes.html