xref: /aosp_15_r20/external/perfetto/src/tracing/test/proxy_producer_endpoint.h (revision 6dbdd20afdafa5e3ca9b8809fa73465d530080dc)
1 /*
2  * Copyright (C) 2024 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef SRC_TRACING_TEST_PROXY_PRODUCER_ENDPOINT_H_
18 #define SRC_TRACING_TEST_PROXY_PRODUCER_ENDPOINT_H_
19 
20 #include "perfetto/ext/tracing/core/tracing_service.h"
21 
22 namespace perfetto {
23 
24 // A "proxy" ProducerEndpoint that forwards all the requests to a real
25 // (`backend_`) ProducerEndpoint endpoint or drops them if (`backend_`) is
26 // nullptr.
27 class ProxyProducerEndpoint : public ProducerEndpoint {
28  public:
29   ~ProxyProducerEndpoint() override;
30 
31   // `backend` is not owned.
set_backend(ProducerEndpoint * backend)32   void set_backend(ProducerEndpoint* backend) { backend_ = backend; }
33 
backend()34   ProducerEndpoint* backend() const { return backend_; }
35 
36   // Begin ProducerEndpoint implementation
37   void Disconnect() override;
38   void RegisterDataSource(const DataSourceDescriptor&) override;
39   void UpdateDataSource(const DataSourceDescriptor&) override;
40   void UnregisterDataSource(const std::string& name) override;
41   void RegisterTraceWriter(uint32_t writer_id, uint32_t target_buffer) override;
42   void UnregisterTraceWriter(uint32_t writer_id) override;
43   void CommitData(const CommitDataRequest&,
44                   CommitDataCallback callback = {}) override;
45   SharedMemory* shared_memory() const override;
46   size_t shared_buffer_page_size_kb() const override;
47   std::unique_ptr<TraceWriter> CreateTraceWriter(
48       BufferID target_buffer,
49       BufferExhaustedPolicy buffer_exhausted_policy =
50           BufferExhaustedPolicy::kDefault) override;
51   SharedMemoryArbiter* MaybeSharedMemoryArbiter() override;
52   bool IsShmemProvidedByProducer() const override;
53   void NotifyFlushComplete(FlushRequestID) override;
54   void NotifyDataSourceStarted(DataSourceInstanceID) override;
55   void NotifyDataSourceStopped(DataSourceInstanceID) override;
56   void ActivateTriggers(const std::vector<std::string>&) override;
57   void Sync(std::function<void()> callback) override;
58   // End ProducerEndpoint implementation
59 
60  private:
61   ProducerEndpoint* backend_ = nullptr;
62 };
63 
64 }  // namespace perfetto
65 
66 #endif  // SRC_TRACING_TEST_PROXY_PRODUCER_ENDPOINT_H_
67