Using perfetto sdk with preload
Say we have a binary and preloaded library both statically link with perfetto.
Perfetto is already initialized in binary main function.
To capture trace event in preloaded library, do I need to initialize perfetto again in preloaded library?
If you managed to build your binary and library with two completely separate instances of perfetto (different static data and different static TLS), yes you would need to initialize perfetto again in your library.
@ddiproietto Thanks for your response. One more question, my application is divided into binary and tons of shared libraries. If I want to trace code in each shared library, do I have to compile perfetto sdk code into each shared library? Basically, I don't want to compile statically thousands lines of perfetto sdk code into each shared library, and thus inflate size of library. On the other hand, Perfetto doc says it is discouraged to attempt to build the C++ tracing library as shared library and use it from a different linker unit.
Is there a proper solution for this scenario?
Perfetto doc says it is discouraged to attempt to build the C++ tracing library as shared library and use it from a different linker unit.
That's right, we don't have a well define ABI surface (not even an unstable ABI surface) that we're comfortable maintaining.
Is there a proper solution for this scenario?
There's a new C API that has an ABI that we intend to maintain as a shared library boundary.
The headers for this API are in https://github.com/google/perfetto/tree/master/include/perfetto/public, examples of usage are in https://github.com/google/perfetto/blob/master/examples/shared_lib/example_shlib_data_source.c, https://github.com/google/perfetto/blob/master/examples/shared_lib/example_shlib_track_event.c and https://github.com/google/perfetto/blob/master/src/shared_lib/test/api_integrationtest.cc
Most of the functionality of the C++ API is there. Given that it's a newer API, it's possible that we're going to make backwards incompatible changes in the near future.