tracing: fix MSVC LNK2019 in DataSourceHelper::type() (#5591)
Move the primary-template definition of `DataSourceHelper::type()` out of
the class body so it is not implicitly inline.
`DataSourceHelper::type()` was added in 06486b8b6010 ("Fix component build
for client library on Windows", 2023-05-05) as a workaround for an MSVC
C2086 redefinition bug affecting an earlier static-data-member design.
That commit defined `type()` inline inside the class body
([dcl.fct.spec]/4 then makes it implicitly inline). MSVC propagates that
inline attribute to every explicit specialization of `type()` defined
out-of-line by `PERFETTO_DEFINE_DATA_SOURCE_STATIC_MEMBERS` in a `.cc`,
emits a C4506 ("no definition for inline function"), and silently drops
the specialization body. Any TU that does not see the body but calls
`Helper::type()` -- transitively via `DataSource<...>::Register<>()`,
`Trace()`, etc. -- is then left with an unresolved external symbol.
The bug stayed dormant until a5f062d78a60 ("[API] Single data source for
all track events", 2025-06-24, in v52.0+) made `TrackEventDataSource`
a concrete class with a `PERFETTO_DECLARE_DATA_SOURCE_STATIC_MEMBERS`
visible in the public header, so user TUs that invoke
`PERFETTO_TRACK_EVENT_STATIC_STORAGE()` started instantiating
`Register<>` and producing LNK2019:
example.cc.obj : error LNK2019: unresolved external symbol
"public: static class perfetto::internal::DataSourceType & __cdecl
perfetto::DataSourceHelper<class perfetto::internal::TrackEventDataSource,
struct perfetto::internal::TrackEventDataSourceTraits>::type(void)"
referenced in function "perfetto::DataSource<...>::Register<>(...)".
GCC and Clang are unaffected: they treat the out-of-line explicit
specialization as a regular non-inline function and emit it normally.
Fix: declare `type()` in the class body and define it out-of-line. The
primary template's member is then a non-inline function template, and
explicit specializations are unambiguously non-inline regular functions
on every compiler. No call sites change; the only file touched is
`include/perfetto/tracing/data_source.h`.
Verified on Windows / MSVC v143 (14.50.35717) for x64 Debug and Release
builds of `examples/sdk` and the v54.0 amalgamated SDK. GCC/Clang
unaffected because the change is a no-op semantic refactor for them.
Bug: #5591
Perfetto is an open-source suite of SDKs, daemons and tools which use tracing to help developers understand the behaviour of complex systems and root-cause functional and performance issues on client and embedded systems.
It is a production-grade tool that is the default tracing system for the Android operating system and the Chromium browser.
Perfetto is not a single tool, but a collection of components that work together:
Perfetto was designed to be a versatile and powerful tracing system for a wide range of use cases.
ftrace, allowing you to visualize scheduling, syscalls, interrupts, and custom kernel tracepoints on a timeline.chrome://tracing. Use it to debug and root-cause issues in the browser, V8, and Blink.We‘ve designed our documentation to guide you to the right information as quickly as possible, whether you’re a newcomer to performance analysis or an experienced developer.
New to tracing? If you're unfamiliar with concepts like tracing and profiling, start here:
Ready to dive in? Our “Getting Started” guide is the main entry point for all users. It will help you find the right tutorials and documentation for your specific needs:
Want the full overview? For a comprehensive look at what Perfetto is, why it's useful, and who uses it, see our main documentation page:
For users interested in the Debian distribution of Perfetto, the official source of truth and packaging efforts are maintained at Debian Perfetto Salsa Repository
Have questions? Need help?
We follow Google's Open Source Community Guidelines.