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 DataSourceParams, 58 bool, 59 DataSourceStaticState*) override; 60 void UpdateDataSourceDescriptor(const DataSourceDescriptor&, 61 const DataSourceStaticState*) override; 62 std::unique_ptr<TraceWriterBase> CreateTraceWriter( 63 DataSourceStaticState*, 64 uint32_t data_source_instance_index, 65 DataSourceState*, 66 BufferExhaustedPolicy buffer_exhausted_policy) override; 67 void DestroyStoppedTraceWritersForCurrentThread() override; 68 void RegisterInterceptor(const InterceptorDescriptor&, 69 InterceptorFactory, 70 InterceptorBase::TLSFactory, 71 InterceptorBase::TracePacketCallback) override; 72 void ActivateTriggers(const std::vector<std::string>&, uint32_t) override; 73 74 private: 75 static TracingMuxerFake instance; 76 }; 77 78 } // namespace internal 79 } // namespace perfetto 80 81 #endif // SRC_TRACING_INTERNAL_TRACING_MUXER_FAKE_H_ 82