/* * Copyright (C) 2019 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #ifndef SRC_TRACING_INTERNAL_TRACING_MUXER_IMPL_H_ #define SRC_TRACING_INTERNAL_TRACING_MUXER_IMPL_H_ #include <stddef.h> #include <stdint.h> #include <array> #include <atomic> #include <bitset> #include <functional> #include <list> #include <map> #include <memory> #include <set> #include <utility> #include <vector> #include "perfetto/base/time.h" #include "perfetto/ext/base/scoped_file.h" #include "perfetto/ext/base/thread_checker.h" #include "perfetto/ext/tracing/core/basic_types.h" #include "perfetto/ext/tracing/core/consumer.h" #include "perfetto/ext/tracing/core/producer.h" #include "perfetto/tracing/backend_type.h" #include "perfetto/tracing/core/data_source_descriptor.h" #include "perfetto/tracing/core/forward_decls.h" #include "perfetto/tracing/core/trace_config.h" #include "perfetto/tracing/internal/basic_types.h" #include "perfetto/tracing/internal/tracing_muxer.h" #include "perfetto/tracing/tracing.h" #include "protos/perfetto/common/interceptor_descriptor.gen.h" namespace perfetto { class ConsumerEndpoint; class DataSourceBase; class ProducerEndpoint; class TraceWriterBase; class TracingBackend; class TracingSession; struct TracingInitArgs; namespace base { class TaskRunner; } namespace shlib { void ResetForTesting(); } namespace test { class TracingMuxerImplInternalsForTest; } namespace internal { struct DataSourceStaticState; // This class acts as a bridge between the public API and the TracingBackend(s). // It exposes a simplified view of the world to the API methods handling all the // bookkeeping to map data source instances and trace writers to the various // backends. It deals with N data sources, M backends (1 backend == 1 tracing // service == 1 producer connection) and T concurrent tracing sessions. // // Handing data source registration and start/stop flows [producer side]: // ---------------------------------------------------------------------- // 1. The API client subclasses perfetto::DataSource and calls // DataSource::Register<MyDataSource>(). In turn this calls into the // TracingMuxer. // 2. The tracing muxer iterates through all the backends (1 backend == 1 // service == 1 producer connection) and registers the data source on each // backend. // 3. When any (services behind a) backend starts tracing and requests to start // that specific data source, the TracingMuxerImpl constructs a new instance // of MyDataSource and calls the OnStart() method. // // Controlling trace and retrieving trace data [consumer side]: // ------------------------------------------------------------ // 1. The API client calls Tracing::NewTrace(), returns a RAII TracingSession // object. // 2. NewTrace() calls into internal::TracingMuxer(Impl). TracingMuxer // subclasses the TracingSession object (TracingSessionImpl) and returns it. // 3. The tracing muxer identifies the backend (according to the args passed to // NewTrace), creates a new Consumer and connects to it. // 4. When the API client calls Start()/Stop()/ReadTrace() methods, the // TracingMuxer forwards them to the consumer associated to the // TracingSession. Likewise for callbacks coming from the consumer-side of // the service. class TracingMuxerImpl : public TracingMuxer { … }; } // namespace internal } // namespace perfetto #endif // SRC_TRACING_INTERNAL_TRACING_MUXER_IMPL_H_