Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(258)

Side by Side Diff: components/tracing/core/scattered_stream_writer.cc

Issue 2196663002: tracing v2: Introduce TraceBufferWriter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proto_refactor
Patch Set: Fix linking errors moving kChunkSize outside of exported class Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scattered_stream_writer.h" 5 #include "components/tracing/core/scattered_stream_writer.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <algorithm> 9 #include <algorithm>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 12
13 namespace tracing { 13 namespace tracing {
14 namespace v2 { 14 namespace v2 {
15 15
16 ScatteredStreamWriter::Delegate::~Delegate() {}
17
16 ScatteredStreamWriter::ScatteredStreamWriter(Delegate* delegate) 18 ScatteredStreamWriter::ScatteredStreamWriter(Delegate* delegate)
17 : delegate_(delegate), 19 : delegate_(delegate),
18 cur_range_({nullptr, nullptr}), 20 cur_range_({nullptr, nullptr}),
19 write_ptr_(nullptr) {} 21 write_ptr_(nullptr) {}
20 22
21 ScatteredStreamWriter::~ScatteredStreamWriter() {} 23 ScatteredStreamWriter::~ScatteredStreamWriter() {}
22 24
23 void ScatteredStreamWriter::Reset(ContiguousMemoryRange range) { 25 void ScatteredStreamWriter::Reset(ContiguousMemoryRange range) {
24 cur_range_ = range; 26 cur_range_ = range;
25 write_ptr_ = range.begin; 27 write_ptr_ = range.begin;
(...skipping 29 matching lines...) Expand all
55 const size_t burst_size = std::min(bytes_available(), bytes_left); 57 const size_t burst_size = std::min(bytes_available(), bytes_left);
56 WriteBytes(src, burst_size); 58 WriteBytes(src, burst_size);
57 bytes_left -= burst_size; 59 bytes_left -= burst_size;
58 src += burst_size; 60 src += burst_size;
59 } 61 }
60 } 62 }
61 63
62 // TODO(primiano): perf optimization: I suspect that at the end this will always 64 // TODO(primiano): perf optimization: I suspect that at the end this will always
63 // be called with |size| == 4, in which case we might just hardcode it. 65 // be called with |size| == 4, in which case we might just hardcode it.
64 ContiguousMemoryRange ScatteredStreamWriter::ReserveBytes(size_t size) { 66 ContiguousMemoryRange ScatteredStreamWriter::ReserveBytes(size_t size) {
65 // Assume the reservations are always < TraceRingBuffer::Chunk::kSize. 67 // Assume the reservations are always < kChunkSize.
66 if (write_ptr_ + size > cur_range_.end) { 68 if (write_ptr_ + size > cur_range_.end) {
67 Extend(); 69 Extend();
68 DCHECK_LE(write_ptr_ + size, cur_range_.end); 70 DCHECK_LE(write_ptr_ + size, cur_range_.end);
69 } 71 }
70 uint8_t* begin = write_ptr_; 72 uint8_t* begin = write_ptr_;
71 write_ptr_ += size; 73 write_ptr_ += size;
72 #ifndef NDEBUG 74 #ifndef NDEBUG
73 memset(begin, '\xFF', size); 75 memset(begin, '\xFF', size);
74 #endif 76 #endif
75 return {begin, begin + size}; 77 return {begin, begin + size};
76 } 78 }
77 79
78 } // namespace v2 80 } // namespace v2
79 } // namespace tracing 81 } // namespace tracing
OLDNEW
« no previous file with comments | « components/tracing/core/scattered_stream_writer.h ('k') | components/tracing/core/trace_buffer_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698