diff options
author | Kristina Chodorow <kchodorow@google.com> | 2015-06-16 15:43:31 +0000 |
---|---|---|
committer | John Field <jfield@google.com> | 2015-06-17 15:22:09 +0000 |
commit | 3bd26cd93a92814f94594272a9ad3e610798c8df (patch) | |
tree | 694e8860bfdd98936b973e5789936c5b72b35840 /site | |
parent | a214a7cdb7d51b146ba1d6a972a5140832bae3f6 (diff) |
Reblog of build visualization post
--
MOS_MIGRATED_REVID=96110942
Diffstat (limited to 'site')
-rw-r--r-- | site/assets/graph.png | bin | 0 -> 47679 bytes | |||
-rw-r--r-- | site/assets/simple-graph.png | bin | 0 -> 5923 bytes | |||
-rw-r--r-- | site/blog/_posts/2015-06-17-visualize-your-build.md | 67 |
3 files changed, 67 insertions, 0 deletions
diff --git a/site/assets/graph.png b/site/assets/graph.png Binary files differnew file mode 100644 index 0000000000..8c4eea6aaa --- /dev/null +++ b/site/assets/graph.png diff --git a/site/assets/simple-graph.png b/site/assets/simple-graph.png Binary files differnew file mode 100644 index 0000000000..1dd6c14621 --- /dev/null +++ b/site/assets/simple-graph.png diff --git a/site/blog/_posts/2015-06-17-visualize-your-build.md b/site/blog/_posts/2015-06-17-visualize-your-build.md new file mode 100644 index 0000000000..0bd20e1aa1 --- /dev/null +++ b/site/blog/_posts/2015-06-17-visualize-your-build.md @@ -0,0 +1,67 @@ +--- +layout: posts +title: Visualize your build +--- + +_Reposted from +[Kristina Chodorow's blog](http://www.kchodorow.com/blog/2015/04/24/have-you-ever-looked-at-your-build-i-mean-really-looked-at-your-build/)._ + +Bazel lets you see a graph of your build dependencies. It _could_ help you +debug things, but honestly it's just really cool to see what your build is doing. + +To try it out, you'll need a project that uses Bazel to build. If you don't +have one handy, +[here's a tiny workspace](https://github.com/kchodorow/tiny-workspace) you can +use: + +```bash +$ git clone https://github.com/kchodorow/tiny-workspace.git +$ cd tiny-workspace +``` + +Make sure you've +[downloaded and installed Bazel](http://bazel.io/docs/install.html) and have the +following line to your _~/.bazelrc_: + +``` +query --package_path %workspace%:[path to bazel]/base_workspace +``` + +Now run `bazel query` in your _tiny-workspace/_ directory, asking it to search +for all dependencies of `//:main` and format the output as a graph: + +```bash +$ bazel query 'deps(//:main)' --output graph > graph.in +``` + +This creates a file called _graph.in_, which is a text representation of the +build graph. You can use `dot` (install with `sudo apt-get install graphviz`) +to create a png from this: + +```bash +$ dot -Tpng < graph.in > graph.png +``` + +If you open up _graph.png_, you should see something like this: + +<img src="/assets/graph.png"> + +You can see `//:main` depends on one file (`//:main.cc`) and four targets +(`//:x`, `//tools/cpp:stl`, `//tools/default:crosstool`, and +`//tools/cpp:malloc`). All of the `//tools` targets are implicit dependencies +of any C++ target: every C++ build you do needs the right compiler, flags, and +libraries available, but it crowds your result graph. You can exclude these +implicit dependencies by removing them from your query results: + +```bash +$ bazel query --noimplicit_deps 'deps(//:main)' --output graph > simplified_graph.in +``` + +Now the resulting graph is just: + +<img src="/assets/simple-graph.png"> + +Much neater! + +If you're interested in further refining your query, check out the +[docs on querying](/docs/query.html). |