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

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

Issue 2197563002: tracing v2: minor refactoring to TraceRingBuffer test helpers (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
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 #ifndef COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ 5 #ifndef COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_
6 #define COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ 6 #define COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include "base/logging.h"
10 #include "base/macros.h" 11 #include "base/macros.h"
11 #include "components/tracing/tracing_export.h" 12 #include "components/tracing/tracing_export.h"
12 13
13 namespace tracing { 14 namespace tracing {
14 namespace v2 { 15 namespace v2 {
15 16
16 struct ContiguousMemoryRange { 17 struct ContiguousMemoryRange {
17 uint8_t* begin; 18 uint8_t* begin;
18 uint8_t* end; // STL style: one byte past the end of the buffer. 19 uint8_t* end; // STL style: one byte past the end of the buffer.
19 20
(...skipping 25 matching lines...) Expand all
45 explicit ScatteredStreamWriter(Delegate* delegate); 46 explicit ScatteredStreamWriter(Delegate* delegate);
46 ~ScatteredStreamWriter(); 47 ~ScatteredStreamWriter();
47 48
48 void WriteByte(uint8_t value); 49 void WriteByte(uint8_t value);
49 void WriteBytes(const uint8_t* src, size_t size); 50 void WriteBytes(const uint8_t* src, size_t size);
50 51
51 // Reserves a fixed amount of bytes to be backfilled later. The reserved range 52 // Reserves a fixed amount of bytes to be backfilled later. The reserved range
52 // is guaranteed to be contiguous and not span across chunks. 53 // is guaranteed to be contiguous and not span across chunks.
53 ContiguousMemoryRange ReserveBytes(size_t size); 54 ContiguousMemoryRange ReserveBytes(size_t size);
54 55
56 // Fast (but unsafe) version of the above. The caller must have previously
57 // checked that there are at least |size| contiguos bytes available.
58 // Returns only the start pointer of the reservation.
59 template <size_t size> uint8_t* ReserveBytesUnsafe() {
alph 2016/07/30 07:41:14 Why it needs to be a template? Won't a simple func
Primiano Tucci (use gerrit) 2016/08/04 15:26:54 Fair point. I think I was just thinking to our pre
60 uint8_t* begin = write_ptr_;
61 write_ptr_ += size;
62 DCHECK_LE(write_ptr_, cur_range_.end);
63 return begin;
64 }
65
55 // Resets the buffer boundaries and the write pointer to the given |range|. 66 // Resets the buffer boundaries and the write pointer to the given |range|.
56 // Subsequent WriteByte(s) will write into |range|. 67 // Subsequent WriteByte(s) will write into |range|.
57 void Reset(ContiguousMemoryRange range); 68 void Reset(ContiguousMemoryRange range);
58 69
59 // Number of contiguous free bytes in |cur_range_| that can be written without 70 // Number of contiguous free bytes in |cur_range_| that can be written without
60 // requesting a new buffer. 71 // requesting a new buffer.
61 size_t bytes_available() const { 72 size_t bytes_available() const {
62 return static_cast<size_t>(cur_range_.end - write_ptr_); 73 return static_cast<size_t>(cur_range_.end - write_ptr_);
63 } 74 }
64 75
65 uint8_t* write_ptr() const { return write_ptr_; } 76 uint8_t* write_ptr() const { return write_ptr_; }
66 77
67 private: 78 private:
68 void Extend(); 79 void Extend();
69 80
70 Delegate* const delegate_; 81 Delegate* const delegate_;
71 ContiguousMemoryRange cur_range_; 82 ContiguousMemoryRange cur_range_;
72 uint8_t* write_ptr_; 83 uint8_t* write_ptr_;
73 84
74 DISALLOW_COPY_AND_ASSIGN(ScatteredStreamWriter); 85 DISALLOW_COPY_AND_ASSIGN(ScatteredStreamWriter);
75 }; 86 };
76 87
77 } // namespace v2 88 } // namespace v2
78 } // namespace tracing 89 } // namespace tracing
79 90
80 #endif // COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ 91 #endif // COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698