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