Add a perfetto backend for tracing and enable it for chip-tool  & light-app on linux (#27354)

* Create varargs macros for tracing, including tests

* Add matter trace scope macros

* Add missing semicolon

* Add labels to trace end

* Restyled by whitespace

* Restyled by clang-format

* Restyled by gn

* Add perfetto v35.0 as a submodule for linux and android

* Start adding a perfetto backend

* Enable perfetto and switch chip-tool C++ standard to 17 as we never compile it for embedded using other compilers

* make library compile and link

* GN format

* Add a track event register, since this is what seems to be needed according to SDK guides

* Add open/close support

* Use a buildconfig header for tracing configuration

* Fix missing include

* Restyled by gn

* Add a file path to perfetto command line argument tracing

* Add a file path to perfetto command line argument tracing

* Fix start/stop to setup tracing

* Some minor reshuffling ... tracing not yet outputted

* Tracing to file works now

* Better tracing for dnssd stuff

* better tracing

* Better tracing logic - only enable perfetto tracing for chiptool

* Minor update

* more tracing ... shows active commissioning delegate calls are SLOOOW

* Remove old MATTER_TRACE_EVENT_SCOPE

* Remove trace.h include

* Remove src/trace dependency

* Minor change to kick re-builds

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

* Use a config variable to enable choice of perfetto enabling in tracing

* Restyle

* Fix logic for tracing enabling to use current_os  instead of target os

* Disable tracing by default, since building on linux or not is not sufficient ... many platforms build on linux

* remove chip_build_pw_trace_lib flag

* Switch linux default C++ standard to 17, to generally support perfetto everywhere

* Restyle

* Disable include check based since it is ifdef-guarded

* Make perfetto and tokenization words in our wordlist

* enable tracing on all linux apps by default and make perfetto the default linux backend

* Restyle

* Make only chip-tool use tracing for now - tracing backends require explicit configuration

* Restyle

* Use public header as a source set for macros_impl.h

* Remove multiplexed trace begin/end/instant from perfetto_tracing since review comment was that this is a footgun

* Multiplexed tracing is not thread safe. Assert lock held in all tracing locations

* Revert "Multiplexed tracing is not thread safe. Assert lock held in all tracing locations"

This reverts commit fd012030fffe354d4069f3092616845ede4a2548.

* Add thread safety documentation

* Allow shadow errors for perfetto compilation

* Remove old tracing calls from jni code

* Make esp32 compile with pw_rpc

* Set perfetto to only apply to linux and android for now

* Set perfetto to linux only after all ... once we have android build rules we can update

* Undo cmakelist reformat

* Undo pragmas warning disabled, use just void for now to make both gcc and clang happy

* Restyle

* make only chip-tool use C++17, since it is the only tracing/perfetto-enabled build

* More update of defaults to make perfetto compile only for chip-tool for now

* more changes to make the c++ version checks more generic

* Restyle

* more documentation

* Restyle

* Make file name be quoted

* Fix typo

* Enable trace support in generic linux examples, and explicitly enable it in the lighting app

* Perfetto has its own scope method. use that instead of the custom implemented class for multiplexing

* Use a buildconfig header for tracing command line arguments

* Restyle

* Restyle

* Add nogncheck for ifdef-guarded file

* Remove include path check for ifdef-guarded include

* Split out perfetto initialization and file output logic, to allow inclusion separation

* Ensure perfetto file output is closed at exit

* Ensure TrackEvent registration is done

* Another split, to ensure event storage is registered properly

* Restyled by clang-format

* Restyled by gn

* Restyled by prettier-markdown

* Fix conditional for perfetto tracing

* Make tracing for android default-enabled

* Restyled by clang-format

* Restyled by gn

* add perfetto repo for android

* Debug odd load path failure for java codegen

* Remove bootstrap cache for testing smoketest

* Revert "Debug odd load path failure for java codegen"

This reverts commit 13ec3ebba6690529f1f4007c77af28df7f79ab9c.

* Revert "Remove bootstrap cache for testing smoketest"

This reverts commit 3cfb7e48e655e734de6b3394d15fb8fc682f6660.

* Force bootstrap cache refresh, because buggy cache

* Switch to if instead of ifdef

* Restyled by gn

* Remove usage of vectors, turn more ifdefs into ifs

* Fix removal of registered backends

* Place the in list check in the register to avoid some code uglyness/duplication

* Move the inlist check back to the registry, to have even smaller code changes

* Fix logic errors regarding defined

* Fix conditional for ifndef

* Move trace setup to a class

* Correct another ifdef

* Fix a few more if/ifdef mismatches

* Undo unintentional repo change

* Restyled by clang-format

* update dependency logic to use explicit targets for each of the none/multiplexed/perfetto

* Add missing files

* Fix paths and comments

* Restyle

* Remove invalid deps on perfetto from none and multiplexed

* Bump up build time for python setup payload test because large build

---------

Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Andrei Litvin <andreilitvin@google.com>
diff --git a/.gitmodules b/.gitmodules
index 5478bed..2af5b7b 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -308,3 +308,8 @@
 	url = https://github.com/asriot/ASR595X_Freertos.git
 	branch = matter
 	platforms = asr
+[submodule "perfetto"]
+	path = third_party/perfetto/repo
+	url = https://github.com/google/perfetto.git
+	branch = master
+	platforms = linux,android