TracedValue: template-based resolution

Add more complex rules for determining whether a class can be written
into a trace.

The following rules are checked in the given order:
- If T::WriteIntoTracedValue(perfetto::TracedValue) exists, use it.
  (allows for simpler code in most of the cases, but does not work when you can't modify the class).
- If perfetto::TraceFormatTraits<T>::WriteIntoTracedValue(
  perfetto::TracedValue, T) exists, use it.
- If T has operator (), taking perfetto::TracedValue, invoke it
  (useful for lambdas)
- If T is iterable and its nested type supports being written into a
  trace, iterate over the elements of T and write them into an array.
  (classes having std::begin(T) defined are considered to be iterables)

This patch also adds the following helpers:
- check_write_support<T>::{value,type} - defined when type T can be
  written in a trace. Useful for enabling support for a complex type
  only when a nested type also can be written into a trace.
- has_write_support<T>::value - boolean, whether T can be written into a
  trace or not (useful when this value has to be or'ed or negated, in
  other cases check_write_support produces more helpful error messages
  with the entire chain of template deduction attempts).

Some real-world examples (removing blink::TracedValue) can be found here: crrev.com/c/2484654
(Note: it is based on the earlier naming iteration, using OutputContext and ConvertToTraceFormat
instead of TracedValue and WriteIntoTracedValue).

R=primiano@google.com,eseckler@google.com,skyostil@google.com

Change-Id: Ic5067fc904c2f78be8c285bdd4b5d6d897485751
6 files changed
tree: 4f7c69c53936d650bb01239f66dfe1692188c9b8
  1. .github/
  2. bazel/
  3. build_overrides/
  4. buildtools/
  5. debian/
  6. docs/
  7. examples/
  8. gn/
  9. include/
  10. infra/
  11. protos/
  12. src/
  13. test/
  14. tools/
  15. ui/
  16. .clang-format
  17. .clang-tidy
  18. .gitattributes
  19. .gitignore
  20. .gn
  21. .style.yapf
  22. Android.bp
  23. Android.bp.extras
  24. BUILD
  25. BUILD.extras
  26. BUILD.gn
  27. CHANGELOG
  28. codereview.settings
  29. DIR_METADATA
  30. heapprofd.rc
  31. LICENSE
  32. METADATA
  33. MODULE_LICENSE_APACHE2
  34. OWNERS
  35. perfetto.rc
  36. PRESUBMIT.py
  37. README.chromium
  38. README.md
  39. TEST_MAPPING
  40. traced_perf.rc
  41. WORKSPACE
README.md

Perfetto - System profiling, app tracing and trace analysis

Perfetto is a production-grade open-source stack for performance instrumentation and trace analysis. It offers services and libraries and for recording system-level and app-level traces, native + java heap profiling, a library for analyzing traces using SQL and a web-based UI to visualize and explore multi-GB traces.

See https://perfetto.dev/docs or the /docs/ directory for documentation.