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 #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/logging.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 // Due to the tracing buffer being split into fixed-size chunks, on some | 31 // Due to the tracing buffer being split into fixed-size chunks, on some |
32 // occasions, these writes need to be spread over two (or more) non-contiguous | 32 // occasions, these writes need to be spread over two (or more) non-contiguous |
33 // chunks of memory. Similarly, when the buffer is backed by the heap, we want | 33 // chunks of memory. Similarly, when the buffer is backed by the heap, we want |
34 // to avoid realloc() calls, as they might cause a full copy of the contents | 34 // to avoid realloc() calls, as they might cause a full copy of the contents |
35 // of the buffer. | 35 // of the buffer. |
36 // The purpose of this class is to abtract away the non-contiguous write logic. | 36 // The purpose of this class is to abtract away the non-contiguous write logic. |
37 // This class knows how to deal with writes as long as they fall in the same | 37 // This class knows how to deal with writes as long as they fall in the same |
38 // ContiguousMemoryRange and defers the chunk-chaining logic to the Delegate. | 38 // ContiguousMemoryRange and defers the chunk-chaining logic to the Delegate. |
39 class TRACING_EXPORT ScatteredStreamWriter { | 39 class TRACING_EXPORT ScatteredStreamWriter { |
40 public: | 40 public: |
41 class TRACING_EXPORT Delegate { | 41 class Delegate { |
42 public: | 42 public: |
43 virtual ~Delegate(); | |
44 virtual ContiguousMemoryRange GetNewBuffer() = 0; | 43 virtual ContiguousMemoryRange GetNewBuffer() = 0; |
45 }; | 44 }; |
46 | 45 |
47 explicit ScatteredStreamWriter(Delegate* delegate); | 46 explicit ScatteredStreamWriter(Delegate* delegate); |
48 ~ScatteredStreamWriter(); | 47 ~ScatteredStreamWriter(); |
49 | 48 |
50 void WriteByte(uint8_t value); | 49 void WriteByte(uint8_t value); |
51 void WriteBytes(const uint8_t* src, size_t size); | 50 void WriteBytes(const uint8_t* src, size_t size); |
52 | 51 |
53 // 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 |
(...skipping 29 matching lines...) Expand all Loading... |
83 ContiguousMemoryRange cur_range_; | 82 ContiguousMemoryRange cur_range_; |
84 uint8_t* write_ptr_; | 83 uint8_t* write_ptr_; |
85 | 84 |
86 DISALLOW_COPY_AND_ASSIGN(ScatteredStreamWriter); | 85 DISALLOW_COPY_AND_ASSIGN(ScatteredStreamWriter); |
87 }; | 86 }; |
88 | 87 |
89 } // namespace v2 | 88 } // namespace v2 |
90 } // namespace tracing | 89 } // namespace tracing |
91 | 90 |
92 #endif // COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ | 91 #endif // COMPONENTS_TRACING_CORE_SCATTERED_STREAM_WRITER_H_ |
OLD | NEW |