Add tracing service and make the shell+sky_viewer+services talk to it

This adds a tracing service that can aggregate tracing data from
multiple sources and write a json file out to disk that trace-viewer can
understand. This also teaches the shell, sky_viewer, and various other
services how to register themselves with the tracing service and provide
tracing data on demand. Finally, this teaches the skydb prompt to tell
the tracing service to start/stop tracing when the 'trace' command is
issued.

The tracing service exposes two APIs, a collector interface and a
coordinator interface. The collector interface allows different entities
to register themselves as being capable of producing tracing data. The
coordinator interface allows asking the service to collect data from
all registered sources and flushing the collected data to disk.

The service keeps track of all open connections to registered sources
and broadcasts a request for data whenever the coordinator's Start
method is called, then aggregates all data send back into a single
trace file. In this patch, the tracing service simply gives all sources
1 second to return data then flushes to disk. Ideally it would keep
track of how many requests it sent out and give each source a certain
amount of time to respond but this is simple and works for most cases.

The tracing service can talk to any source that is capable of producing
data that the trace-viewer can handle, which is a broad set, but in
practice many programs will want to use //base/debug's tracing to
produce trace data. This adds code at //mojo/common:tracing_impl that
registers a collector hooked up to //base/debug's tracing system. This
can be dropped in to the mojo::ApplicationDelegate::Initialize()
implementation for most services and applications to easily enable
base tracing. Programs that don't use //base, or that want to register
additional data sources that can talk to trace viewer (perhaps providing
data that's more easily available from another thread, say) may want
to create additional connections to the tracing service.

R=eseidel@chromium.org

Review URL: https://codereview.chromium.org/769963004
27 files changed
tree: f44dfb7319e70f710a6efd93966a070fb05ceba8
  1. base/
  2. benchmarks/
  3. build/
  4. cc/
  5. crypto/
  6. examples/
  7. gin/
  8. gpu/
  9. mojo/
  10. net/
  11. sandbox/
  12. sdch/
  13. services/
  14. skia/
  15. sky/
  16. testing/
  17. third_party/
  18. tools/
  19. ui/
  20. url/
  21. .clang-format
  22. .gitattributes
  23. .gitignore
  24. .gn
  25. AUTHORS
  26. BUILD.gn
  27. codereview.settings
  28. DEPS
  29. DEPS.dart
  30. LICENSE
  31. OWNERS
  32. PRESUBMIT.py
  33. PRESUBMIT_test.py
  34. README.md
  35. WATCHLISTS
README.md

Mojo

Mojo is an effort to extract a common platform out of Chrome's renderer and plugin processes that can support multiple types of sandboxed content, such as HTML, Pepper, or NaCl.

Set up your environment

The instructions below only need to be done once. Note that a simple “git clone” command is not sufficient to build the source code because this repo uses the gclient command from depot_tools to manage most third party dependencies.

  1. Download depot_tools and make sure it is in your path:
    http://www.chromium.org/developers/how-tos/install-depot-tools

  2. [Googlers only] Install Goma in ~/goma.

  3. Create a directory somewhere for your checkout (preferably on an SSD), cd into it, and run the following commands:

$ fetch mojo # append --target_os=android to include Android build support.
$ cd src
$ ./build/install-build-deps.sh
$ mojo/tools/mojob.py gn

The “fetch mojo” command does the following:

  • creates a directory called ‘src’ under your checkout directory
  • clones the repository using git clone
  • clones dependencies with gclient sync

install-build-deps.sh installs any packages needed to build, then mojo/tools/mojob.py gn runs gn args and configures the build directory, out/Debug.

If the fetch command fails, you will need to delete the src directory and start over.

Build Mojo

Build Mojo by running:

$ ninja -C out/Debug -j 10 root

The “root” parameter specifies the target to build, it's not a special keyword. You can find the “root” target in src/BUILD.gn.

(If you are a Googler, see the section at the end of this document for faster builds.)

You can also use the mojob.py script for building. This script automatically calls ninja and sets -j to an appropriate value based on whether Goma is present. You cannot specify a target name with this script.

mojo/tools/mojob.py build

Run a demo:

mojo/tools/mojo_demo.sh --browser

Run the tests:

mojo/tools/mojob.py test

Update your repo

You can update your repo like this:

$ gclient sync
$ git pull --rebase

You do not need to rerun “gn gen out/Debug”. Ninja will do so automatically as needed.

Contribute

With git you should make all your changes in a local branch. Once your change is committed, you can delete this branch.

Create a local branch named “mywork” and make changes to it.

  cd src
  git new-branch mywork
  vi ...

Commit your change locally (this doesn't commit your change to the SVN or Git server)

  git commit -a

If you added new files, you should tell git by running git add <files> before committing.

Upload your change for review

$ git cl upload

Respond to review comments See Contributing code for more detailed git instructions, including how to update your CL when you get review comments. There's a short tutorial that might be helpful to try before your first change: C++ in Chromium 101.

To land a change after receiving LGTM:

$ git cl land

Don't break the build! Waterfall is here: http://build.chromium.org/p/client.mojo/waterfall

Android Builds

To build for Android, first make sure you‘ve downloaded build support for Android, which you would have done by adding --target_os=android when you ran fetch mojo. If you didn’t do that, there's an easy fix. Edit the file .gclient in your root Mojo directory (the parent directory to src.) Add this line at the end of the file:

target_os = [u'android']

Pull down all of the packages with this command:

$ gclient sync

Prepare the build directory for Android:

$ src/mojo/tools/mojob.py gn --android

Finally, perform the build. The result will be in out/android_Debug:

$ src/mojo/tools/mojob.py build --android

Googlers

If you're a Googler, you can use Goma, a distributed compiler service for open-source projects such as Chrome and Android. The instructions below assume that Goma is installed in the default location (~/goma).

To enable Goma, update your “args.gn” file. Open the file in your editor with this command:

$ gn args out/Debug

Add this line to the end of the file:

use_goma = true

After you close the editor, the “gn args” command will automatically run “gn gen out/Debug” again.

Now you can dramatically increase the number of parallel tasks:

$ ninja -C out/Debug -j 1000 root