1 /* 2 * Copyright (C) 2021 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_INTERNAL_TRACING_MUXER_FAKE_H_ 18 #define SRC_TRACING_INTERNAL_TRACING_MUXER_FAKE_H_ 19 20 #include "perfetto/base/compiler.h" 21 #include "perfetto/tracing/internal/tracing_muxer.h" 22 23 namespace perfetto { 24 namespace internal { 25 26 // An always-fail implementation of TracingMuxer. Before tracing has been 27 // initialiazed, all muxer operations will route here and fail with a helpful 28 // error message. This is to avoid introducing null checks in 29 // performance-critical parts of the codebase. 30 class TracingMuxerFake : public TracingMuxer { 31 class FakePlatform : public Platform { 32 public: 33 ~FakePlatform() override; 34 ThreadLocalObject* GetOrCreateThreadLocalObject() override; 35 std::unique_ptr<base::TaskRunner> CreateTaskRunner( 36 const CreateTaskRunnerArgs&) override; 37 std::string GetCurrentProcessName() override; 38 39 static FakePlatform instance; 40 }; 41 42 public: TracingMuxerFake()43 TracingMuxerFake() : TracingMuxer(&FakePlatform::instance) {} 44 ~TracingMuxerFake() override; 45 Get()46 static constexpr TracingMuxerFake* Get() { 47 #if PERFETTO_HAS_NO_DESTROY() 48 return &instance; 49 #else 50 return nullptr; 51 #endif 52 } 53 54 // TracingMuxer implementation. 55 bool RegisterDataSource(const DataSourceDescriptor&, 56 DataSourceFactory, 57 DataSourceStaticState*) override; 58 void UpdateDataSourceDescriptor(const DataSourceDescriptor&, 59 const DataSourceStaticState*) override; 60 std::unique_ptr<TraceWriterBase> CreateTraceWriter( 61 DataSourceStaticState*, 62 uint32_t data_source_instance_index, 63 DataSourceState*, 64 BufferExhaustedPolicy buffer_exhausted_policy) override; 65 void DestroyStoppedTraceWritersForCurrentThread() override; 66 void RegisterInterceptor(const InterceptorDescriptor&, 67 InterceptorFactory, 68 InterceptorBase::TLSFactory, 69 InterceptorBase::TracePacketCallback) override; 70 71 private: 72 static TracingMuxerFake instance; 73 }; 74 75 } // namespace internal 76 } // namespace perfetto 77 78 #endif // SRC_TRACING_INTERNAL_TRACING_MUXER_FAKE_H_ 79