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

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

Issue 2228593004: Revert of tracing v2: Introduce TraceBufferWriter (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proto_refactor
Patch Set: 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
18 ScatteredStreamWriter::ScatteredStreamWriter(Delegate* delegate) 16 ScatteredStreamWriter::ScatteredStreamWriter(Delegate* delegate)
19 : delegate_(delegate), 17 : delegate_(delegate),
20 cur_range_({nullptr, nullptr}), 18 cur_range_({nullptr, nullptr}),
21 write_ptr_(nullptr) {} 19 write_ptr_(nullptr) {}
22 20
23 ScatteredStreamWriter::~ScatteredStreamWriter() {} 21 ScatteredStreamWriter::~ScatteredStreamWriter() {}
24 22
25 void ScatteredStreamWriter::Reset(ContiguousMemoryRange range) { 23 void ScatteredStreamWriter::Reset(ContiguousMemoryRange range) {
26 cur_range_ = range; 24 cur_range_ = range;
27 write_ptr_ = range.begin; 25 write_ptr_ = range.begin;
(...skipping 29 matching lines...) Expand all
57 const size_t burst_size = std::min(bytes_available(), bytes_left); 55 const size_t burst_size = std::min(bytes_available(), bytes_left);
58 WriteBytes(src, burst_size); 56 WriteBytes(src, burst_size);
59 bytes_left -= burst_size; 57 bytes_left -= burst_size;
60 src += burst_size; 58 src += burst_size;
61 } 59 }
62 } 60 }
63 61
64 // TODO(primiano): perf optimization: I suspect that at the end this will always 62 // TODO(primiano): perf optimization: I suspect that at the end this will always
65 // be called with |size| == 4, in which case we might just hardcode it. 63 // be called with |size| == 4, in which case we might just hardcode it.
66 ContiguousMemoryRange ScatteredStreamWriter::ReserveBytes(size_t size) { 64 ContiguousMemoryRange ScatteredStreamWriter::ReserveBytes(size_t size) {
67 // Assume the reservations are always < kChunkSize. 65 // Assume the reservations are always < TraceRingBuffer::Chunk::kSize.
68 if (write_ptr_ + size > cur_range_.end) { 66 if (write_ptr_ + size > cur_range_.end) {
69 Extend(); 67 Extend();
70 DCHECK_LE(write_ptr_ + size, cur_range_.end); 68 DCHECK_LE(write_ptr_ + size, cur_range_.end);
71 } 69 }
72 uint8_t* begin = write_ptr_; 70 uint8_t* begin = write_ptr_;
73 write_ptr_ += size; 71 write_ptr_ += size;
74 #ifndef NDEBUG 72 #ifndef NDEBUG
75 memset(begin, '\xFF', size); 73 memset(begin, '\xFF', size);
76 #endif 74 #endif
77 return {begin, begin + size}; 75 return {begin, begin + size};
78 } 76 }
79 77
80 } // namespace v2 78 } // namespace v2
81 } // namespace tracing 79 } // 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