1 /* 2 * Copyright (C) 2018 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_CORE_NULL_TRACE_WRITER_H_ 18 #define SRC_TRACING_CORE_NULL_TRACE_WRITER_H_ 19 20 #include "perfetto/protozero/message_handle.h" 21 #include "perfetto/protozero/scattered_stream_null_delegate.h" 22 #include "perfetto/tracing/core/trace_writer.h" 23 24 namespace perfetto { 25 26 // A specialization of TraceWriter which no-ops all the writes routing them 27 // into a fixed region of memory 28 // See //include/perfetto/tracing/core/trace_writer.h for docs. 29 class NullTraceWriter : public TraceWriter { 30 public: 31 NullTraceWriter(); 32 ~NullTraceWriter() override; 33 34 // TraceWriter implementation. See documentation in trace_writer.h. 35 // TracePacketHandle is defined in trace_writer.h 36 TracePacketHandle NewTracePacket() override; 37 void Flush(std::function<void()> callback = {}) override; 38 WriterID writer_id() const override; 39 uint64_t written() const override; 40 41 private: 42 NullTraceWriter(const NullTraceWriter&) = delete; 43 NullTraceWriter& operator=(const NullTraceWriter&) = delete; 44 45 protozero::ScatteredStreamWriterNullDelegate delegate_; 46 protozero::ScatteredStreamWriter stream_; 47 48 // The packet returned via NewTracePacket(). Its owned by this class, 49 // TracePacketHandle has just a pointer to it. 50 std::unique_ptr<protos::pbzero::TracePacket> cur_packet_; 51 }; 52 53 } // namespace perfetto 54 55 #endif // SRC_TRACING_CORE_NULL_TRACE_WRITER_H_ 56