OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/tracing/core/trace_buffer_writer.h" | 5 #include "components/tracing/core/trace_buffer_writer.h" |
6 | 6 |
7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "components/tracing/core/proto_utils.h" | 9 #include "components/tracing/core/proto_utils.h" |
| 10 #include "components/tracing/proto/events_chunk.pbzero.h" |
10 | 11 |
11 namespace tracing { | 12 namespace tracing { |
12 namespace v2 { | 13 namespace v2 { |
13 | 14 |
14 namespace { | 15 namespace { |
15 | 16 |
16 // TODO(primiano) remove this in next CLs. This should just be taken from the | 17 using ChunkProto = pbzero::tracing::proto::EventsChunk; |
17 // C++ class autogenerated from events_chunk.proto (crbug.com/608721). | |
18 struct ChunkProto { | |
19 enum : uint32_t { | |
20 kWriterIdFieldNumber = 1, | |
21 kSeqIdInStreamFieldNumber = 2, | |
22 kEventsFieldNumber = 3, | |
23 kFirstEventContinuesFromPrevChunkFieldNumber = 4, | |
24 kLastEventContinuesOnNextChunkFieldNumber = 5 | |
25 }; | |
26 }; | |
27 | 18 |
28 const size_t kEventPreambleSize = 1 + proto::kMessageLengthFieldSize; | 19 const size_t kEventPreambleSize = 1 + proto::kMessageLengthFieldSize; |
29 | 20 |
30 // TODO(primiano): replace 16 with a more reasonable size, that is, the size | 21 // TODO(primiano): replace 16 with a more reasonable size, that is, the size |
31 // of a simple trace event with no args. | 22 // of a simple trace event with no args. |
32 const size_t kMinEventSize = 16; | 23 const size_t kMinEventSize = 16; |
33 | 24 |
34 } // namespace | 25 } // namespace |
35 | 26 |
36 TraceBufferWriter::TraceBufferWriter(TraceRingBuffer* trace_ring_buffer, | 27 TraceBufferWriter::TraceBufferWriter(TraceRingBuffer* trace_ring_buffer, |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 // events_chunk.proto cannot be used here because that would re-enter this | 144 // events_chunk.proto cannot be used here because that would re-enter this |
154 // class and make this code extremely hard to reason about. | 145 // class and make this code extremely hard to reason about. |
155 uint8_t* chunk_proto = new_chunk->payload(); | 146 uint8_t* chunk_proto = new_chunk->payload(); |
156 | 147 |
157 proto::StaticAssertSingleBytePreamble<ChunkProto::kWriterIdFieldNumber>(); | 148 proto::StaticAssertSingleBytePreamble<ChunkProto::kWriterIdFieldNumber>(); |
158 *chunk_proto++ = static_cast<uint8_t>( | 149 *chunk_proto++ = static_cast<uint8_t>( |
159 proto::MakeTagVarInt(ChunkProto::kWriterIdFieldNumber)); | 150 proto::MakeTagVarInt(ChunkProto::kWriterIdFieldNumber)); |
160 chunk_proto = proto::WriteVarInt(writer_id_, chunk_proto); | 151 chunk_proto = proto::WriteVarInt(writer_id_, chunk_proto); |
161 | 152 |
162 proto::StaticAssertSingleBytePreamble< | 153 proto::StaticAssertSingleBytePreamble< |
163 ChunkProto::kSeqIdInStreamFieldNumber>(); | 154 ChunkProto::kSeqIdFieldNumber>(); |
164 *chunk_proto++ = static_cast<uint8_t>( | 155 *chunk_proto++ = static_cast<uint8_t>( |
165 proto::MakeTagVarInt(ChunkProto::kSeqIdInStreamFieldNumber)); | 156 proto::MakeTagVarInt(ChunkProto::kSeqIdFieldNumber)); |
166 chunk_proto = proto::WriteVarInt(chunk_seq_id_, chunk_proto); | 157 chunk_proto = proto::WriteVarInt(chunk_seq_id_, chunk_proto); |
167 | 158 |
168 if (is_fragmenting_event) { | 159 if (is_fragmenting_event) { |
169 proto::StaticAssertSingleBytePreamble< | 160 proto::StaticAssertSingleBytePreamble< |
170 ChunkProto::kFirstEventContinuesFromPrevChunkFieldNumber>(); | 161 ChunkProto::kFirstEventContinuesFromPrevChunkFieldNumber>(); |
171 *chunk_proto++ = static_cast<uint8_t>(proto::MakeTagVarInt( | 162 *chunk_proto++ = static_cast<uint8_t>(proto::MakeTagVarInt( |
172 ChunkProto::kFirstEventContinuesFromPrevChunkFieldNumber)); | 163 ChunkProto::kFirstEventContinuesFromPrevChunkFieldNumber)); |
173 *chunk_proto++ = 1; // = true. | 164 *chunk_proto++ = 1; // = true. |
174 } | 165 } |
175 | 166 |
(...skipping 28 matching lines...) Expand all Loading... |
204 | 195 |
205 void TraceBufferWriter::Flush() { | 196 void TraceBufferWriter::Flush() { |
206 FinalizeCurrentEvent(); | 197 FinalizeCurrentEvent(); |
207 FinalizeCurrentChunk(false /* is_fragmenting_event */); | 198 FinalizeCurrentChunk(false /* is_fragmenting_event */); |
208 trace_ring_buffer_->ReturnChunk(chunk_); | 199 trace_ring_buffer_->ReturnChunk(chunk_); |
209 chunk_ = nullptr; | 200 chunk_ = nullptr; |
210 } | 201 } |
211 | 202 |
212 } // namespace v2 | 203 } // namespace v2 |
213 } // namespace tracing | 204 } // namespace tracing |
OLD | NEW |