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 #include "src/tracing/core/null_trace_writer.h" 18 19 #include "perfetto/base/logging.h" 20 #include "perfetto/ext/base/utils.h" 21 #include "perfetto/protozero/message.h" 22 23 #include "protos/perfetto/trace/trace_packet.pbzero.h" 24 25 namespace perfetto { 26 NullTraceWriter()27NullTraceWriter::NullTraceWriter() : delegate_(4096), stream_(&delegate_) { 28 cur_packet_.reset(new protozero::RootMessage<protos::pbzero::TracePacket>()); 29 cur_packet_->Finalize(); // To avoid the DCHECK in NewTracePacket(). 30 } 31 ~NullTraceWriter()32NullTraceWriter::~NullTraceWriter() {} 33 Flush(std::function<void ()> callback)34void NullTraceWriter::Flush(std::function<void()> callback) { 35 // Flush() cannot be called in the middle of a TracePacket. 36 PERFETTO_CHECK(cur_packet_->is_finalized()); 37 38 if (callback) 39 callback(); 40 } 41 NewTracePacket()42NullTraceWriter::TracePacketHandle NullTraceWriter::NewTracePacket() { 43 // If we hit this, the caller is calling NewTracePacket() without having 44 // finalized the previous packet. 45 PERFETTO_DCHECK(cur_packet_->is_finalized()); 46 cur_packet_->Reset(&stream_); 47 return TraceWriter::TracePacketHandle(cur_packet_.get()); 48 } 49 writer_id() const50WriterID NullTraceWriter::writer_id() const { 51 return 0; 52 } 53 written() const54uint64_t NullTraceWriter::written() const { 55 return 0; 56 } 57 58 } // namespace perfetto 59