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