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